| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | * | |
| 37 | 37 | * Version number of the ngtcp2 library release. | |
| 38 | 38 | */ | |
| 39 | - #define NGTCP2_VERSION "1.2.0" | ||
| 39 | + #define NGTCP2_VERSION "1.3.0" | ||
| 40 | 40 | ||
| 41 | 41 | /** | |
| 42 | 42 | * @macro | |
@@ -46,6 +46,6 @@ | |||
| 46 | 46 | * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 | |
| 47 | 47 | * becomes 0x010203. | |
| 48 | 48 | */ | |
| 49 | - #define NGTCP2_VERSION_NUM 0x010200 | ||
| 49 | + #define NGTCP2_VERSION_NUM 0x010300 | ||
| 50 | 50 | ||
| 51 | 51 | #endif /* VERSION_H */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ typedef struct ngtcp2_buf { | |||
| 36 | 36 | uint8_t *begin; | |
| 37 | 37 | /* end points to the one beyond of the last byte of the buffer */ | |
| 38 | 38 | uint8_t *end; | |
| 39 | - /* pos pointers to the start of data. Typically, this points to the | ||
| 39 | + /* pos points to the start of data. Typically, this points to the | ||
| 40 | 40 | point that next data should be read. Initially, it points to | |
| 41 | 41 | |begin|. */ | |
| 42 | 42 | uint8_t *pos; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,10 +27,6 @@ | |||
| 27 | 27 | #include <assert.h> | |
| 28 | 28 | #include <string.h> | |
| 29 | 29 | ||
| 30 | - #if defined(_MSC_VER) | ||
| 31 | - # include <intrin.h> | ||
| 32 | - #endif | ||
| 33 | - | ||
| 34 | 30 | #include "ngtcp2_log.h" | |
| 35 | 31 | #include "ngtcp2_macro.h" | |
| 36 | 32 | #include "ngtcp2_mem.h" | |
@@ -235,39 +231,27 @@ void ngtcp2_cc_cubic_init(ngtcp2_cc_cubic *cubic, ngtcp2_log *log) { | |||
| 235 | 231 | } | |
| 236 | 232 | ||
| 237 | 233 | uint64_t ngtcp2_cbrt(uint64_t n) { | |
| 238 | - int d; | ||
| 239 | - uint64_t a; | ||
| 240 | - | ||
| 241 | - if (n == 0) { | ||
| 242 | - return 0; | ||
| 243 | - } | ||
| 244 | - | ||
| 245 | - #if defined(_MSC_VER) | ||
| 246 | - { | ||
| 247 | - unsigned long index; | ||
| 248 | - # if defined(_WIN64) | ||
| 249 | - if (_BitScanReverse64(&index, n)) { | ||
| 250 | - d = 61 - index; | ||
| 251 | - } else { | ||
| 252 | - ngtcp2_unreachable(); | ||
| 253 | - } | ||
| 254 | - # else /* !defined(_WIN64) */ | ||
| 255 | - if (_BitScanReverse(&index, (unsigned int)(n >> 32))) { | ||
| 256 | - d = 31 - index; | ||
| 257 | - } else { | ||
| 258 | - d = 32 + 31 - _BitScanReverse(&index, (unsigned int)n); | ||
| 234 | + size_t s; | ||
| 235 | + uint64_t y = 0; | ||
| 236 | + uint64_t b; | ||
| 237 | + | ||
| 238 | + for (s = 63; s > 0; s -= 3) { | ||
| 239 | + y <<= 1; | ||
| 240 | + b = 3 * y * (y + 1) + 1; | ||
| 241 | + if ((n >> s) >= b) { | ||
| 242 | + n -= b << s; | ||
| 243 | + y++; | ||
| 259 | 244 | } | |
| 260 | - # endif /* !defined(_WIN64) */ | ||
| 261 | 245 | } | |
| 262 | - #else /* !defined(_MSC_VER) */ | ||
| 263 | - d = __builtin_clzll(n); | ||
| 264 | - #endif /* !defined(_MSC_VER) */ | ||
| 265 | - a = 1ULL << ((64 - d) / 3 + 1); | ||
| 266 | 246 | ||
| 267 | - for (; a * a * a > n;) { | ||
| 268 | - a = (2 * a + n / a / a) / 3; | ||
| 247 | + y <<= 1; | ||
| 248 | + b = 3 * y * (y + 1) + 1; | ||
| 249 | + if (n >= b) { | ||
| 250 | + n -= b; | ||
| 251 | + y++; | ||
| 269 | 252 | } | |
| 270 | - return a; | ||
| 253 | + | ||
| 254 | + return y; | ||
| 271 | 255 | } | |
| 272 | 256 | ||
| 273 | 257 | /* HyStart++ constants */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3441,12 +3441,22 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi, | |||
| 3441 | 3441 | } | |
| 3442 | 3442 | ||
| 3443 | 3443 | switch ((*pfrc)->fr.type) { | |
| 3444 | + case NGTCP2_FRAME_RESET_STREAM: | ||
| 3445 | + strm = | ||
| 3446 | + ngtcp2_conn_find_stream(conn, (*pfrc)->fr.reset_stream.stream_id); | ||
| 3447 | + if (strm == NULL || | ||
| 3448 | + !ngtcp2_strm_require_retransmit_reset_stream(strm)) { | ||
| 3449 | + frc = *pfrc; | ||
| 3450 | + *pfrc = (*pfrc)->next; | ||
| 3451 | + ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem); | ||
| 3452 | + continue; | ||
| 3453 | + } | ||
| 3454 | + break; | ||
| 3444 | 3455 | case NGTCP2_FRAME_STOP_SENDING: | |
| 3445 | 3456 | strm = | |
| 3446 | 3457 | ngtcp2_conn_find_stream(conn, (*pfrc)->fr.stop_sending.stream_id); | |
| 3447 | 3458 | if (strm == NULL || | |
| 3448 | - ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD) && | ||
| 3449 | - ngtcp2_strm_rx_offset(strm) == strm->rx.last_offset)) { | ||
| 3459 | + !ngtcp2_strm_require_retransmit_stop_sending(strm)) { | ||
| 3450 | 3460 | frc = *pfrc; | |
| 3451 | 3461 | *pfrc = (*pfrc)->next; | |
| 3452 | 3462 | ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem); | |
@@ -3476,10 +3486,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi, | |||
| 3476 | 3486 | case NGTCP2_FRAME_MAX_STREAM_DATA: | |
| 3477 | 3487 | strm = ngtcp2_conn_find_stream(conn, | |
| 3478 | 3488 | (*pfrc)->fr.max_stream_data.stream_id); | |
| 3479 | - if (strm == NULL || | ||
| 3480 | - (strm->flags & | ||
| 3481 | - (NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_STOP_SENDING)) || | ||
| 3482 | - (*pfrc)->fr.max_stream_data.max_stream_data < strm->rx.max_offset) { | ||
| 3489 | + if (strm == NULL || !ngtcp2_strm_require_retransmit_max_stream_data( | ||
| 3490 | + strm, &(*pfrc)->fr.max_stream_data)) { | ||
| 3483 | 3491 | frc = *pfrc; | |
| 3484 | 3492 | *pfrc = (*pfrc)->next; | |
| 3485 | 3493 | ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem); | |
@@ -3497,8 +3505,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi, | |||
| 3497 | 3505 | case NGTCP2_FRAME_STREAM_DATA_BLOCKED: | |
| 3498 | 3506 | strm = ngtcp2_conn_find_stream( | |
| 3499 | 3507 | conn, (*pfrc)->fr.stream_data_blocked.stream_id); | |
| 3500 | - if (strm == NULL || (strm->flags & NGTCP2_STRM_FLAG_SHUT_WR) || | ||
| 3501 | - (*pfrc)->fr.stream_data_blocked.offset != strm->tx.max_offset) { | ||
| 3508 | + if (strm == NULL || !ngtcp2_strm_require_retransmit_stream_data_blocked( | ||
| 3509 | + strm, &(*pfrc)->fr.stream_data_blocked)) { | ||
| 3502 | 3510 | frc = *pfrc; | |
| 3503 | 3511 | *pfrc = (*pfrc)->next; | |
| 3504 | 3512 | ngtcp2_frame_chain_objalloc_del(frc, &conn->frc_objalloc, conn->mem); | |
@@ -7145,7 +7153,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) { | |||
| 7145 | 7153 | return rv; | |
| 7146 | 7154 | } | |
| 7147 | 7155 | } | |
| 7148 | - } else if (fr->datacnt) { | ||
| 7156 | + } else if (fr->datacnt && !(strm->flags & NGTCP2_STRM_FLAG_STOP_SENDING)) { | ||
| 7149 | 7157 | rv = ngtcp2_strm_recv_reordering(strm, fr->data[0].base, fr->data[0].len, | |
| 7150 | 7158 | fr->offset); | |
| 7151 | 7159 | if (rv != 0) { | |
@@ -7304,27 +7312,20 @@ static int conn_recv_reset_stream(ngtcp2_conn *conn, | |||
| 7304 | 7312 | } | |
| 7305 | 7313 | ||
| 7306 | 7314 | /* Stream is reset before we create ngtcp2_strm object. */ | |
| 7307 | - conn->rx.offset += fr->final_size; | ||
| 7308 | - ngtcp2_conn_extend_max_offset(conn, fr->final_size); | ||
| 7309 | - | ||
| 7310 | - rv = conn_call_stream_reset(conn, fr->stream_id, fr->final_size, | ||
| 7311 | - fr->app_error_code, NULL); | ||
| 7315 | + strm = ngtcp2_objalloc_strm_get(&conn->strm_objalloc); | ||
| 7316 | + if (strm == NULL) { | ||
| 7317 | + return NGTCP2_ERR_NOMEM; | ||
| 7318 | + } | ||
| 7319 | + rv = ngtcp2_conn_init_stream(conn, strm, fr->stream_id, NULL); | ||
| 7312 | 7320 | if (rv != 0) { | |
| 7321 | + ngtcp2_objalloc_strm_release(&conn->strm_objalloc, strm); | ||
| 7313 | 7322 | return rv; | |
| 7314 | 7323 | } | |
| 7315 | 7324 | ||
| 7316 | - /* There will be no activity in this stream because we got | ||
| 7317 | - RESET_STREAM and don't write stream data any further. This | ||
| 7318 | - effectively allows another new stream for peer. */ | ||
| 7319 | - if (bidi) { | ||
| 7320 | - handle_max_remote_streams_extension(&conn->remote.bidi.unsent_max_streams, | ||
| 7321 | - 1); | ||
| 7322 | - } else { | ||
| 7323 | - handle_max_remote_streams_extension(&conn->remote.uni.unsent_max_streams, | ||
| 7324 | - 1); | ||
| 7325 | + rv = conn_call_stream_open(conn, strm); | ||
| 7326 | + if (rv != 0) { | ||
| 7327 | + return rv; | ||
| 7325 | 7328 | } | |
| 7326 | - | ||
| 7327 | - return 0; | ||
| 7328 | 7329 | } | |
| 7329 | 7330 | ||
| 7330 | 7331 | if ((strm->flags & NGTCP2_STRM_FLAG_SHUT_RD)) { | |
@@ -7461,15 +7462,16 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn, | |||
| 7461 | 7462 | been acknowledged. */ | |
| 7462 | 7463 | if (!ngtcp2_strm_is_all_tx_data_fin_acked(strm) && | |
| 7463 | 7464 | !(strm->flags & NGTCP2_STRM_FLAG_RESET_STREAM)) { | |
| 7465 | + strm->flags |= NGTCP2_STRM_FLAG_RESET_STREAM; | ||
| 7466 | + | ||
| 7464 | 7467 | rv = conn_reset_stream(conn, strm, fr->app_error_code); | |
| 7465 | 7468 | if (rv != 0) { | |
| 7466 | 7469 | return rv; | |
| 7467 | 7470 | } | |
| 7468 | 7471 | } | |
| 7469 | 7472 | ||
| 7470 | - strm->flags |= NGTCP2_STRM_FLAG_SHUT_WR | | ||
| 7471 | - NGTCP2_STRM_FLAG_STOP_SENDING_RECVED | | ||
| 7472 | - NGTCP2_STRM_FLAG_RESET_STREAM; | ||
| 7473 | + strm->flags |= | ||
| 7474 | + NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_STOP_SENDING_RECVED; | ||
| 7473 | 7475 | ||
| 7474 | 7476 | ngtcp2_strm_streamfrq_clear(strm); | |
| 7475 | 7477 | ||
@@ -12533,14 +12535,15 @@ static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm, | |||
| 12533 | 12535 | ||
| 12534 | 12536 | /* Extend connection flow control window for the amount of data | |
| 12535 | 12537 | which are not passed to application. */ | |
| 12536 | - if (!(strm->flags & (NGTCP2_STRM_FLAG_STOP_SENDING | | ||
| 12537 | - NGTCP2_STRM_FLAG_RESET_STREAM_RECVED))) { | ||
| 12538 | + if (!(strm->flags & NGTCP2_STRM_FLAG_RESET_STREAM_RECVED)) { | ||
| 12538 | 12539 | ngtcp2_conn_extend_max_offset(conn, strm->rx.last_offset - | |
| 12539 | 12540 | ngtcp2_strm_rx_offset(strm)); | |
| 12540 | 12541 | } | |
| 12541 | 12542 | ||
| 12542 | 12543 | strm->flags |= NGTCP2_STRM_FLAG_STOP_SENDING; | |
| 12543 | 12544 | ||
| 12545 | + ngtcp2_strm_discard_reordered_data(strm); | ||
| 12546 | + | ||
| 12544 | 12547 | return conn_stop_sending(conn, strm, app_error_code); | |
| 12545 | 12548 | } | |
| 12546 | 12549 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,25 @@ static uint8_t *write_varint_param(uint8_t *p, ngtcp2_transport_param_id id, | |||
| 123 | 123 | return ngtcp2_put_uvarint(p, value); | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | + /* | ||
| 127 | + * zero_paramlen returns the length of a single transport parameter | ||
| 128 | + * which has zero length value in its parameter. | ||
| 129 | + */ | ||
| 130 | + static size_t zero_paramlen(ngtcp2_transport_param_id id) { | ||
| 131 | + return ngtcp2_put_uvarintlen(id) + 1; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + /* | ||
| 135 | + * write_zero_param writes parameter |id| that has zero length value. | ||
| 136 | + * It returns p + the number of bytes written. | ||
| 137 | + */ | ||
| 138 | + static uint8_t *write_zero_param(uint8_t *p, ngtcp2_transport_param_id id) { | ||
| 139 | + p = ngtcp2_put_uvarint(p, id); | ||
| 140 | + *p++ = 0; | ||
| 141 | + | ||
| 142 | + return p; | ||
| 143 | + } | ||
| 144 | + | ||
| 126 | 145 | /* | |
| 127 | 146 | * cid_paramlen returns the length of a single transport parameter | |
| 128 | 147 | * which has |cid| as value. | |
@@ -235,9 +254,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned( | |||
| 235 | 254 | params->ack_delay_exponent); | |
| 236 | 255 | } | |
| 237 | 256 | if (params->disable_active_migration) { | |
| 238 | - len += | ||
| 239 | - ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION) + | ||
| 240 | - ngtcp2_put_uvarintlen(0); | ||
| 257 | + len += zero_paramlen(NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION); | ||
| 241 | 258 | } | |
| 242 | 259 | if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) { | |
| 243 | 260 | len += varint_paramlen(NGTCP2_TRANSPORT_PARAM_MAX_ACK_DELAY, | |
@@ -258,8 +275,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned( | |||
| 258 | 275 | params->max_datagram_frame_size); | |
| 259 | 276 | } | |
| 260 | 277 | if (params->grease_quic_bit) { | |
| 261 | - len += ngtcp2_put_uvarintlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT) + | ||
| 262 | - ngtcp2_put_uvarintlen(0); | ||
| 278 | + len += zero_paramlen(NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT); | ||
| 263 | 279 | } | |
| 264 | 280 | if (params->version_info_present) { | |
| 265 | 281 | version_infolen = | |
@@ -377,8 +393,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned( | |||
| 377 | 393 | } | |
| 378 | 394 | ||
| 379 | 395 | if (params->disable_active_migration) { | |
| 380 | - p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION); | ||
| 381 | - p = ngtcp2_put_uvarint(p, 0); | ||
| 396 | + p = write_zero_param(p, NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION); | ||
| 382 | 397 | } | |
| 383 | 398 | ||
| 384 | 399 | if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) { | |
@@ -404,8 +419,7 @@ ngtcp2_ssize ngtcp2_transport_params_encode_versioned( | |||
| 404 | 419 | } | |
| 405 | 420 | ||
| 406 | 421 | if (params->grease_quic_bit) { | |
| 407 | - p = ngtcp2_put_uvarint(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT); | ||
| 408 | - p = ngtcp2_put_uvarint(p, 0); | ||
| 422 | + p = write_zero_param(p, NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT); | ||
| 409 | 423 | } | |
| 410 | 424 | ||
| 411 | 425 | if (params->version_info_present) { | |
@@ -482,6 +496,22 @@ static int decode_varint_param(uint64_t *pdest, const uint8_t **pp, | |||
| 482 | 496 | return 0; | |
| 483 | 497 | } | |
| 484 | 498 | ||
| 499 | + /* | ||
| 500 | + * decode_zero_param decodes zero length value from the buffer pointed | ||
| 501 | + * by |*pp| of length |end - *pp|. The length is encoded in varint | ||
| 502 | + * form. If it decodes zero length value successfully, it increments | ||
| 503 | + * |*pp| by 1, and returns 0. Otherwise it returns -1. | ||
| 504 | + */ | ||
| 505 | + static int decode_zero_param(const uint8_t **pp, const uint8_t *end) { | ||
| 506 | + if (*pp == end || **pp != 0) { | ||
| 507 | + return -1; | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + ++*pp; | ||
| 511 | + | ||
| 512 | + return 0; | ||
| 513 | + } | ||
| 514 | + | ||
| 485 | 515 | /* | |
| 486 | 516 | * decode_cid_param decodes length prefixed ngtcp2_cid from the buffer | |
| 487 | 517 | * pointed by |*pp| of length |end - *pp|. The length is encoded in | |
@@ -701,10 +731,7 @@ int ngtcp2_transport_params_decode_versioned(int transport_params_version, | |||
| 701 | 731 | params->preferred_addr_present = 1; | |
| 702 | 732 | break; | |
| 703 | 733 | case NGTCP2_TRANSPORT_PARAM_DISABLE_ACTIVE_MIGRATION: | |
| 704 | - if (decode_varint(&valuelen, &p, end) != 0) { | ||
| 705 | - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; | ||
| 706 | - } | ||
| 707 | - if (valuelen != 0) { | ||
| 734 | + if (decode_zero_param(&p, end) != 0) { | ||
| 708 | 735 | return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; | |
| 709 | 736 | } | |
| 710 | 737 | params->disable_active_migration = 1; | |
@@ -751,10 +778,7 @@ int ngtcp2_transport_params_decode_versioned(int transport_params_version, | |||
| 751 | 778 | } | |
| 752 | 779 | break; | |
| 753 | 780 | case NGTCP2_TRANSPORT_PARAM_GREASE_QUIC_BIT: | |
| 754 | - if (decode_varint(&valuelen, &p, end) != 0) { | ||
| 755 | - return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; | ||
| 756 | - } | ||
| 757 | - if (valuelen != 0) { | ||
| 781 | + if (decode_zero_param(&p, end) != 0) { | ||
| 758 | 782 | return NGTCP2_ERR_MALFORMED_TRANSPORT_PARAM; | |
| 759 | 783 | } | |
| 760 | 784 | params->grease_quic_bit = 1; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments