mirror of
https://github.com/nginx/nginx.git
synced 2025-06-24 23:43:06 +08:00
QUIC: simplified quic connection dispatching.
Currently listener contains rbtree with multiple nodes for single QUIC connection: each corresponding to specific server id. Each udp node points to same ngx_connection_t, which points to QUIC connection via c->udp field. Thus when an event handler is called, it only gets ngx_connection_t with c->udp pointing to QUIC connection. This makes it hard to obtain actual node which was used to dispatch packet (it requires to repeat DCID lookup). Additionally, ngx_quic_connection_t->udp field is only needed to keep a pointer in c->udp. The node is not added into the tree and does not carry useful information.
This commit is contained in:
parent
f3489441b2
commit
20f3d107df
@ -684,6 +684,13 @@ ngx_lookup_udp_connection(ngx_listening_t *ls, ngx_str_t *key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
|
|
||||||
|
#if (NGX_QUIC)
|
||||||
|
if (ls->quic && c->udp != udp) {
|
||||||
|
c->udp = udp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +112,6 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_udp_connection_t udp;
|
|
||||||
|
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
ngx_str_t scid; /* initial client ID */
|
ngx_str_t scid; /* initial client ID */
|
||||||
ngx_str_t dcid; /* server (our own) ID */
|
ngx_str_t dcid; /* server (our own) ID */
|
||||||
@ -198,6 +196,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_udp_connection_t udp;
|
ngx_udp_connection_t udp;
|
||||||
|
ngx_quic_connection_t *quic;
|
||||||
ngx_queue_t queue;
|
ngx_queue_t queue;
|
||||||
uint64_t seqnum;
|
uint64_t seqnum;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -342,7 +341,7 @@ static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c,
|
|||||||
static ngx_int_t ngx_quic_issue_server_ids(ngx_connection_t *c);
|
static ngx_int_t ngx_quic_issue_server_ids(ngx_connection_t *c);
|
||||||
static void ngx_quic_clear_temp_server_ids(ngx_connection_t *c);
|
static void ngx_quic_clear_temp_server_ids(ngx_connection_t *c);
|
||||||
static ngx_quic_server_id_t *ngx_quic_insert_server_id(ngx_connection_t *c,
|
static ngx_quic_server_id_t *ngx_quic_insert_server_id(ngx_connection_t *c,
|
||||||
ngx_str_t *id);
|
ngx_quic_connection_t *qc, ngx_str_t *id);
|
||||||
static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c,
|
static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c,
|
||||||
ngx_quic_connection_t *qc);
|
ngx_quic_connection_t *qc);
|
||||||
static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c,
|
static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c,
|
||||||
@ -1096,6 +1095,7 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
|
|||||||
{
|
{
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_quic_tp_t *ctp;
|
ngx_quic_tp_t *ctp;
|
||||||
|
ngx_quic_server_id_t *sid;
|
||||||
ngx_quic_client_id_t *cid;
|
ngx_quic_client_id_t *cid;
|
||||||
ngx_quic_connection_t *qc;
|
ngx_quic_connection_t *qc;
|
||||||
|
|
||||||
@ -1247,18 +1247,19 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->udp = &qc->udp;
|
if (ngx_quic_insert_server_id(c, qc, &qc->odcid) == NULL) {
|
||||||
|
|
||||||
if (ngx_quic_insert_server_id(c, &qc->odcid) == NULL) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
qc->server_seqnum = 0;
|
qc->server_seqnum = 0;
|
||||||
|
|
||||||
if (ngx_quic_insert_server_id(c, &qc->dcid) == NULL) {
|
sid = ngx_quic_insert_server_id(c, qc, &qc->dcid);
|
||||||
|
if (sid == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->udp = &sid->udp;
|
||||||
|
|
||||||
qc->validated = pkt->validated;
|
qc->validated = pkt->validated;
|
||||||
|
|
||||||
return qc;
|
return qc;
|
||||||
@ -4777,7 +4778,7 @@ ngx_quic_issue_server_ids(ngx_connection_t *c)
|
|||||||
dcid.len = NGX_QUIC_SERVER_CID_LEN;
|
dcid.len = NGX_QUIC_SERVER_CID_LEN;
|
||||||
dcid.data = id;
|
dcid.data = id;
|
||||||
|
|
||||||
sid = ngx_quic_insert_server_id(c, &dcid);
|
sid = ngx_quic_insert_server_id(c, qc, &dcid);
|
||||||
if (sid == NULL) {
|
if (sid == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
@ -4840,19 +4841,19 @@ ngx_quic_clear_temp_server_ids(ngx_connection_t *c)
|
|||||||
|
|
||||||
|
|
||||||
static ngx_quic_server_id_t *
|
static ngx_quic_server_id_t *
|
||||||
ngx_quic_insert_server_id(ngx_connection_t *c, ngx_str_t *id)
|
ngx_quic_insert_server_id(ngx_connection_t *c, ngx_quic_connection_t *qc,
|
||||||
|
ngx_str_t *id)
|
||||||
{
|
{
|
||||||
ngx_str_t dcid;
|
ngx_str_t dcid;
|
||||||
ngx_quic_server_id_t *sid;
|
ngx_quic_server_id_t *sid;
|
||||||
ngx_quic_connection_t *qc;
|
|
||||||
|
|
||||||
qc = ngx_quic_get_connection(c);
|
|
||||||
|
|
||||||
sid = ngx_quic_alloc_server_id(c, qc);
|
sid = ngx_quic_alloc_server_id(c, qc);
|
||||||
if (sid == NULL) {
|
if (sid == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sid->quic = qc;
|
||||||
|
|
||||||
sid->seqnum = qc->server_seqnum;
|
sid->seqnum = qc->server_seqnum;
|
||||||
|
|
||||||
if (qc->server_seqnum != NGX_QUIC_UNSET_PN) {
|
if (qc->server_seqnum != NGX_QUIC_UNSET_PN) {
|
||||||
|
@ -64,7 +64,8 @@
|
|||||||
|
|
||||||
#define NGX_QUIC_BUFFER_SIZE 4096
|
#define NGX_QUIC_BUFFER_SIZE 4096
|
||||||
|
|
||||||
#define ngx_quic_get_connection(c) ((ngx_quic_connection_t *)(c)->udp)
|
#define ngx_quic_get_connection(c) \
|
||||||
|
(((c)->udp) ? (((ngx_quic_server_id_t *)((c)->udp))->quic) : NULL)
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user