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

View file

@ -0,0 +1,55 @@
#ifndef SLIPSTREAM_DNS_REQUEST_BUFFER
#define SLIPSTREAM_DNS_REQUEST_BUFFER
#include <stdbool.h>
#include "SPCDNS/src/dns.h"
#define GLOBAL_BUFFER_SIZE 4096
typedef struct st_slipstream_cnxid_dns_request_buffer_t slipstream_cnxid_dns_request_buffer_t;
typedef struct st_element_t {
dns_decoded_t dns_decoded[DNS_DECODEBUF_4K];
struct sockaddr_storage peer_addr;
struct st_element_t* buffer_prev;
struct st_element_t* buffer_next;
struct st_element_t* cnxid_buffer_prev;
struct st_element_t* cnxid_buffer_next;
slipstream_cnxid_dns_request_buffer_t* cnxid_buffer;
} slot_t;
typedef struct st_slipstream_cnxid_dns_request_buffer_t {
slot_t* head;
slot_t* tail;
} slipstream_cnxid_dns_request_buffer_t;
typedef struct {
slot_t elements[GLOBAL_BUFFER_SIZE];
slot_t* head;
slot_t* tail;
slot_t* free;
picohash_table* cnxid_to_cnxid_buffer;
} slipstream_dns_request_buffer_t;
typedef struct st_cnxid_to_cnxid_buffer_t {
picoquic_connection_id_t cnx_id;
slipstream_cnxid_dns_request_buffer_t* cnxid_buffer;
} cnxid_to_cnxid_buffer_t;
void slipstream_dns_request_buffer_init(slipstream_dns_request_buffer_t* buffer);
slipstream_cnxid_dns_request_buffer_t* slipstream_dns_request_buffer_get_cnxid_buffer(
slipstream_dns_request_buffer_t* buffer, picoquic_connection_id_t* initial_cnxid, bool create);
slot_t* slipstream_dns_request_buffer_get_write_slot(slipstream_dns_request_buffer_t* buffer);
void slipstream_dns_request_buffer_commit_slot_to_cnxid_buffer(slipstream_dns_request_buffer_t* buffer,
slipstream_cnxid_dns_request_buffer_t* cnxid_buffer,
slot_t* slot);
slot_t* slipstream_dns_request_buffer_get_read_slot(slipstream_dns_request_buffer_t* buffer,
slipstream_cnxid_dns_request_buffer_t* cnxid_buffer);
#endif //SLIPSTREAM_DNS_REQUEST_BUFFER

View file

@ -1,20 +0,0 @@
#ifndef SLIPSTREAM_SERVER_CIRCULAR_QUEUE_BUFFER_H
#define SLIPSTREAM_SERVER_CIRCULAR_QUEUE_BUFFER_H
#define SIZE 4096
#include "SPCDNS/src/dns.h"
typedef struct {
dns_decoded_t queries[SIZE][DNS_DECODEBUF_4K];
size_t tail;
size_t head;
} circular_query_buffer_t;
dns_decoded_t* circular_query_buffer_get_write_slot(circular_query_buffer_t* buf);
dns_decoded_t* circular_query_buffer_get_read_slot(circular_query_buffer_t* buf);
size_t circular_query_buffer_get_size(circular_query_buffer_t* buf);
#endif // SLIPSTREAM_SERVER_CIRCULAR_QUEUE_BUFFER_H

View file

@ -0,0 +1,10 @@
#ifndef SLIPSTREAM_UTILS_H
#define SLIPSTREAM_UTILS_H
#include "picoquic.h"
char* picoquic_connection_id_to_string(const picoquic_connection_id_t* cid);
void sockaddr_dummy(struct sockaddr_storage *addr_storage);
#endif //SLIPSTREAM_UTILS_H