Support multiple simultaneous clients

* replace cqb with a dns request buffer with separate queues for each cnx id
* ensure we respond to the addr from the DNS request we popped from queue
This commit is contained in:
Jop Zitman 2024-12-17 17:15:32 +08:00
parent 0006c48e4b
commit 2038af95e8
10 changed files with 380 additions and 73 deletions

44
src/slipstream_utils.c Normal file
View file

@ -0,0 +1,44 @@
#include "slipstream_utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* picoquic_connection_id_to_string(const picoquic_connection_id_t* cid) {
// Each byte needs 2 hex characters + null terminator
char* str = malloc((cid->id_len * 2 + 1) * sizeof(char));
if (str == NULL) {
return NULL;
}
// Convert each byte to hex
for (int i = 0; i < cid->id_len; i++) {
sprintf(&str[i * 2], "%02x", cid->id[i]);
}
str[cid->id_len * 2] = '\0';
return str;
}
// Function to create a dummy sockaddr_storage with hardcoded IPv4 and port
void sockaddr_dummy(struct sockaddr_storage *addr_storage) {
// Clear the entire sockaddr_storage to avoid residual data
memset(addr_storage, 0, sizeof(struct sockaddr_storage));
// Cast sockaddr_storage to sockaddr_in for IPv4
struct sockaddr_in *addr4 = (struct sockaddr_in *)addr_storage;
// Set address family to AF_INET (IPv4)
addr4->sin_family = AF_INET;
// Use a hardcoded IPv4 address: 192.0.2.1 (TEST-NET-1 for testing)
inet_pton(AF_INET, "192.0.2.1", &addr4->sin_addr);
// Set a hardcoded port: 12345
addr4->sin_port = htons(12345);
#ifdef __APPLE__ // For BSD systems, set sin_len
addr4->sin_len = sizeof(struct sockaddr_in);
#endif
}