diff src/event/ngx_event_quic_transport.c @ 8285:f85749b60e58 quic

Removed memory allocations from encryption code. + ngx_quic_encrypt(): - no longer accepts pool as argument - pkt is 1st arg - payload is passed as pkt->payload - performs encryption to the specified static buffer + ngx_quic_create_long/short_packet() functions: - single buffer for everything, allocated by caller - buffer layout is: [ ad | payload | TAG ] the result is in the beginning of buffer with proper length - nonce is calculated on stack - log is passed explicitly, pkt is 1st arg - no more allocations inside + ngx_quic_create_long_header(): - args changed: no need to pass str_t + added ngx_quic_create_short_header()
author Vladimir Homutov <vl@nginx.com>
date Thu, 26 Mar 2020 12:11:50 +0300
parents 50db7ce374b7
children dc7ac778aafe
line wrap: on
line diff
--- a/src/event/ngx_event_quic_transport.c
+++ b/src/event/ngx_event_quic_transport.c
@@ -341,12 +341,12 @@ ngx_quic_parse_long_header(ngx_quic_head
 
 
 size_t
-ngx_quic_create_long_header(ngx_quic_header_t *pkt, ngx_str_t *out,
+ngx_quic_create_long_header(ngx_quic_header_t *pkt, u_char *out,
     size_t pkt_len, u_char **pnp)
 {
-    u_char    *p, *start;
+    u_char  *p, *start;
 
-    p = start = out->data;
+    p = start = out;
 
     *p++ = pkt->flags;
 
@@ -372,6 +372,26 @@ ngx_quic_create_long_header(ngx_quic_hea
 }
 
 
+size_t
+ngx_quic_create_short_header(ngx_quic_header_t *pkt, u_char *out,
+    size_t pkt_len, u_char **pnp)
+{
+    u_char  *p, *start;
+
+    p = start = out;
+
+    *p++ = 0x40;
+
+    p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
+
+    *pnp = p;
+
+    *p++ = (*pkt->number);
+
+    return p - start;
+}
+
+
 ngx_int_t
 ngx_quic_parse_short_header(ngx_quic_header_t *pkt, ngx_str_t *dcid)
 {