comparison src/event/quic/ngx_event_quic_ssl.c @ 9011:f9c788f3f5cc quic

QUIC: ngx_quic_buffer_t object. The object is used instead of ngx_chain_t pointer for buffer operations like ngx_quic_write_chain() and ngx_quic_read_chain(). These functions are renamed to ngx_quic_write_buffer() and ngx_quic_read_buffer().
author Roman Arutyunyan <arut@nginx.com>
date Mon, 14 Feb 2022 15:27:59 +0300
parents 92729be0377b
children b5656025ddb5
comparison
equal deleted inserted replaced
9010:a5aebd51e4c7 9011:f9c788f3f5cc
329 329
330 ngx_int_t 330 ngx_int_t
331 ngx_quic_handle_crypto_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, 331 ngx_quic_handle_crypto_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
332 ngx_quic_frame_t *frame) 332 ngx_quic_frame_t *frame)
333 { 333 {
334 size_t len;
335 uint64_t last; 334 uint64_t last;
336 ngx_buf_t *b; 335 ngx_chain_t *cl;
337 ngx_chain_t *cl, **ll;
338 ngx_quic_send_ctx_t *ctx; 336 ngx_quic_send_ctx_t *ctx;
339 ngx_quic_connection_t *qc; 337 ngx_quic_connection_t *qc;
340 ngx_quic_crypto_frame_t *f; 338 ngx_quic_crypto_frame_t *f;
341 339
342 qc = ngx_quic_get_connection(c); 340 qc = ngx_quic_get_connection(c);
344 f = &frame->u.crypto; 342 f = &frame->u.crypto;
345 343
346 /* no overflow since both values are 62-bit */ 344 /* no overflow since both values are 62-bit */
347 last = f->offset + f->length; 345 last = f->offset + f->length;
348 346
349 if (last > ctx->crypto_received + NGX_QUIC_MAX_BUFFERED) { 347 if (last > ctx->crypto.offset + NGX_QUIC_MAX_BUFFERED) {
350 qc->error = NGX_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED; 348 qc->error = NGX_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED;
351 return NGX_ERROR; 349 return NGX_ERROR;
352 } 350 }
353 351
354 if (last <= ctx->crypto_received) { 352 if (last <= ctx->crypto.offset) {
355 if (pkt->level == ssl_encryption_initial) { 353 if (pkt->level == ssl_encryption_initial) {
356 /* speeding up handshake completion */ 354 /* speeding up handshake completion */
357 355
358 if (!ngx_queue_empty(&ctx->sent)) { 356 if (!ngx_queue_empty(&ctx->sent)) {
359 ngx_quic_resend_frames(c, ctx); 357 ngx_quic_resend_frames(c, ctx);
366 } 364 }
367 365
368 return NGX_OK; 366 return NGX_OK;
369 } 367 }
370 368
371 if (f->offset > ctx->crypto_received) { 369 if (f->offset == ctx->crypto.offset) {
372 if (ngx_quic_write_chain(c, &ctx->crypto, frame->data, f->length, 370 if (ngx_quic_crypto_input(c, frame->data) != NGX_OK) {
373 f->offset - ctx->crypto_received, NULL) 371 return NGX_ERROR;
372 }
373
374 ngx_quic_skip_buffer(c, &ctx->crypto, last);
375
376 } else {
377 if (ngx_quic_write_buffer(c, &ctx->crypto, frame->data, f->length,
378 f->offset)
374 == NGX_CHAIN_ERROR) 379 == NGX_CHAIN_ERROR)
375 { 380 {
376 return NGX_ERROR; 381 return NGX_ERROR;
377 } 382 }
378 383 }
379 return NGX_OK; 384
380 } 385 cl = ngx_quic_read_buffer(c, &ctx->crypto, (uint64_t) -1);
381
382 ngx_quic_trim_chain(frame->data, ctx->crypto_received - f->offset);
383
384 if (ngx_quic_crypto_input(c, frame->data) != NGX_OK) {
385 return NGX_ERROR;
386 }
387
388 ngx_quic_trim_chain(ctx->crypto, last - ctx->crypto_received);
389 ctx->crypto_received = last;
390
391 cl = ctx->crypto;
392 ll = &cl;
393 len = 0;
394
395 while (*ll) {
396 b = (*ll)->buf;
397
398 if (b->sync && b->pos != b->last) {
399 /* hole */
400 break;
401 }
402
403 len += b->last - b->pos;
404 ll = &(*ll)->next;
405 }
406
407 ctx->crypto_received += len;
408 ctx->crypto = *ll;
409 *ll = NULL;
410 386
411 if (cl) { 387 if (cl) {
412 if (ngx_quic_crypto_input(c, cl) != NGX_OK) { 388 if (ngx_quic_crypto_input(c, cl) != NGX_OK) {
413 return NGX_ERROR; 389 return NGX_ERROR;
414 } 390 }