comparison src/event/quic/ngx_event_quic_udp.c @ 9107:adcc6d8acfd4 quic

Common tree insert function for QUIC and UDP connections. Previously, ngx_udp_rbtree_insert_value() was used for plain UDP and ngx_quic_rbtree_insert_value() was used for QUIC. Because of this it was impossible to initialize connection tree in ngx_create_listening() since this function is not aware what kind of listening it creates. Now ngx_udp_rbtree_insert_value() is used for both QUIC and UDP. To make is possible, a generic key field is added to ngx_udp_connection_t. It keeps client address for UDP and connection ID for QUIC.
author Roman Arutyunyan <arut@nginx.com>
date Sun, 14 May 2023 12:30:11 +0400
parents 3028db26a0f5
children 68fa4b86ed46
comparison
equal deleted inserted replaced
9106:113e2438dbd4 9107:adcc6d8acfd4
363 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); 363 (void) ngx_atomic_fetch_add(ngx_stat_active, -1);
364 #endif 364 #endif
365 } 365 }
366 366
367 367
368 void
369 ngx_quic_rbtree_insert_value(ngx_rbtree_node_t *temp,
370 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
371 {
372 ngx_int_t rc;
373 ngx_connection_t *c, *ct;
374 ngx_rbtree_node_t **p;
375 ngx_quic_socket_t *qsock, *qsockt;
376
377 for ( ;; ) {
378
379 if (node->key < temp->key) {
380
381 p = &temp->left;
382
383 } else if (node->key > temp->key) {
384
385 p = &temp->right;
386
387 } else { /* node->key == temp->key */
388
389 qsock = (ngx_quic_socket_t *) node;
390 c = qsock->udp.connection;
391
392 qsockt = (ngx_quic_socket_t *) temp;
393 ct = qsockt->udp.connection;
394
395 rc = ngx_memn2cmp(qsock->sid.id, qsockt->sid.id,
396 qsock->sid.len, qsockt->sid.len);
397
398 if (rc == 0 && c->listening->wildcard) {
399 rc = ngx_cmp_sockaddr(c->local_sockaddr, c->local_socklen,
400 ct->local_sockaddr, ct->local_socklen, 1);
401 }
402
403 p = (rc < 0) ? &temp->left : &temp->right;
404 }
405
406 if (*p == sentinel) {
407 break;
408 }
409
410 temp = *p;
411 }
412
413 *p = node;
414 node->parent = temp;
415 node->left = sentinel;
416 node->right = sentinel;
417 ngx_rbt_red(node);
418 }
419
420
421 static ngx_connection_t * 368 static ngx_connection_t *
422 ngx_quic_lookup_connection(ngx_listening_t *ls, ngx_str_t *key, 369 ngx_quic_lookup_connection(ngx_listening_t *ls, ngx_str_t *key,
423 struct sockaddr *local_sockaddr, socklen_t local_socklen) 370 struct sockaddr *local_sockaddr, socklen_t local_socklen)
424 { 371 {
425 uint32_t hash; 372 uint32_t hash;