diff --git a/lib/includes/ngtcp2/ngtcp2.h b/lib/includes/ngtcp2/ngtcp2.h index d22abee0e26898c5f5cabdd54552dc65a1e236e6..1bf5d745fffeed2d1266f2c2035c3941cf7b4d17 100644 --- a/lib/includes/ngtcp2/ngtcp2.h +++ b/lib/includes/ngtcp2/ngtcp2.h @@ -1056,12 +1056,22 @@ NGTCP2_EXTERN int ngtcp2_conn_update_rx_keys(ngtcp2_conn *conn, /** * @function * - * `ngtcp2_conn_earliest_expiry` returns the earliest expiry time - * point that application should call `ngtcp2_conn_write_pkt` before - * that expires. It returns 0 if there is no expiry. + * `ngtcp2_conn_earliest_expiry` returns the expiry time point of loss + * detection alarm. Application should call + * `ngtcp2_conn_on_loss_detection_alarm` when it expires. It returns + * UINT64_MAX if loss detection alarm is not armed. */ NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_earliest_expiry(ngtcp2_conn *conn); +/** + * @function + * + * `ngtcp2_conn_ack_delay_expiry` returns the expiry time point of + * delayed protected ACK. Application should call + * `ngtcp2_conn_write_pkt` (or `ngtcp2_conn_handshake` if handshake + * does not finished yet) when it expires. It returns UINT64_MAX if + * there is no expiry. + */ NGTCP2_EXTERN ngtcp2_tstamp ngtcp2_conn_ack_delay_expiry(ngtcp2_conn *conn); /** diff --git a/lib/ngtcp2_acktr.c b/lib/ngtcp2_acktr.c index dc821330723d7256747f2437f2a8970e083a9129..1c16fec088662a73eb7b969210c2aa945bb175a3 100644 --- a/lib/ngtcp2_acktr.c +++ b/lib/ngtcp2_acktr.c @@ -25,7 +25,6 @@ #include "ngtcp2_acktr.h" #include <assert.h> -#include <stdio.h> #include "ngtcp2_conn.h" #include "ngtcp2_macro.h" @@ -66,6 +65,8 @@ int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_mem *mem) { acktr->nack = 0; acktr->last_hs_ack_pkt_num = UINT64_MAX; acktr->flags = NGTCP2_ACKTR_FLAG_NONE; + /* Initialize it to 0 so that we can send first ACK without a + delay. */ acktr->first_unacked_ts = 0; return 0; diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c index ff7faf798040798541214c3b6f9516c1ebc68e5b..8244af7aa808bd7b1cab9ee05c11c5a6a7e1073f 100644 --- a/lib/ngtcp2_conn.c +++ b/lib/ngtcp2_conn.c @@ -1541,7 +1541,7 @@ static ssize_t conn_write_pkt(ngtcp2_conn *conn, uint8_t *dest, size_t destlen, pkt_empty = 0; if (conn->flags & NGTCP2_CONN_FLAG_PENDING_FINISHED_ACK) { - conn->flags &= (uint16_t)~NGTCP2_CONN_FLAG_PENDING_FINISHED_ACK; + conn->flags &= (uint8_t)~NGTCP2_CONN_FLAG_PENDING_FINISHED_ACK; conn->acktr.last_hs_ack_pkt_num = hd.pkt_num; /* TODO We don't have to send PING if we send a frame other than ACK. */ @@ -2199,7 +2199,7 @@ static int conn_recv_server_stateless_retry(ngtcp2_conn *conn) { ngtcp2_rtb_init(&conn->rtb, &conn->log, conn->mem); ngtcp2_map_insert(&conn->strms, &conn->strm0->me); - conn->flags &= (uint16_t)~NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED; + conn->flags &= (uint8_t)~NGTCP2_CONN_FLAG_CONN_ID_NEGOTIATED; conn->state = NGTCP2_CS_CLIENT_INITIAL; return 0; @@ -3811,7 +3811,6 @@ ssize_t ngtcp2_conn_handshake(ngtcp2_conn *conn, uint8_t *dest, size_t destlen, conn->state = NGTCP2_CS_POST_HANDSHAKE; conn->final_hs_tx_offset = conn->strm0->tx_offset; - conn->flags |= NGTCP2_CONN_FLAG_QUIC_HANDSHAKE_COMPLETED; if (conn->early_rtb) { rv = conn_process_early_rtb(conn); @@ -3895,7 +3894,6 @@ ssize_t ngtcp2_conn_handshake(ngtcp2_conn *conn, uint8_t *dest, size_t destlen, } conn->state = NGTCP2_CS_POST_HANDSHAKE; conn->final_hs_tx_offset = conn->strm0->tx_offset; - conn->flags |= NGTCP2_CONN_FLAG_QUIC_HANDSHAKE_COMPLETED; rv = conn_process_buffered_protected_pkt(conn, ts); if (rv != 0) { @@ -3926,7 +3924,7 @@ void ngtcp2_conn_handshake_completed(ngtcp2_conn *conn) { } int ngtcp2_conn_get_handshake_completed(ngtcp2_conn *conn) { - return (conn->flags & NGTCP2_CONN_FLAG_QUIC_HANDSHAKE_COMPLETED) != 0; + return (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) > 0; } int ngtcp2_conn_sched_ack(ngtcp2_conn *conn, uint64_t pkt_num, int active_ack, diff --git a/lib/ngtcp2_conn.h b/lib/ngtcp2_conn.h index c773cc8acd6e09f04a8f266cd8544b41d734d056..e9ac539be9e63396345bc7e0c88ec327b07768be 100644 --- a/lib/ngtcp2_conn.h +++ b/lib/ngtcp2_conn.h @@ -165,7 +165,6 @@ typedef enum { acknowledgement for ACK which acknowledges the last handshake packet from client (which contains TLSv1.3 Finished message). */ NGTCP2_CONN_FLAG_ACK_FINISHED_ACK = 0x80, - NGTCP2_CONN_FLAG_QUIC_HANDSHAKE_COMPLETED = 0x100, } ngtcp2_conn_flag; struct ngtcp2_conn { @@ -252,7 +251,7 @@ struct ngtcp2_conn { ngtcp2_rtb rtb; uint32_t version; /* flags is bitwise OR of zero or more of ngtcp2_conn_flag. */ - uint16_t flags; + uint8_t flags; int server; /* hs_tx_ckm is a cryptographic key, and iv to encrypt handshake packets. */ diff --git a/tests/ngtcp2_acktr_test.c b/tests/ngtcp2_acktr_test.c index e3d0306aa18191babc7bfde2b991250348710e26..aba772a7ca4044a99c329dc6e1b99cf12af29ccd 100644 --- a/tests/ngtcp2_acktr_test.c +++ b/tests/ngtcp2_acktr_test.c @@ -49,7 +49,7 @@ void test_ngtcp2_acktr_add(void) { ngtcp2_acktr_entry_new(&ents[6], 3, 1006, 0, mem); for (i = 0; i < arraylen(ents); ++i) { - rv = ngtcp2_acktr_add(&acktr, ents[i], 1); + rv = ngtcp2_acktr_add(&acktr, ents[i], 1, 999); CU_ASSERT(0 == rv); @@ -76,11 +76,11 @@ void test_ngtcp2_acktr_add(void) { ngtcp2_acktr_init(&acktr, mem); ngtcp2_acktr_entry_new(&ents[0], 1, 1000, 0, mem); - rv = ngtcp2_acktr_add(&acktr, ents[0], 1); + rv = ngtcp2_acktr_add(&acktr, ents[0], 1, 999); CU_ASSERT(0 == rv); - rv = ngtcp2_acktr_add(&acktr, ents[0], 1); + rv = ngtcp2_acktr_add(&acktr, ents[0], 1, 1003); CU_ASSERT(NGTCP2_ERR_PROTO == rv); @@ -98,7 +98,7 @@ void test_ngtcp2_acktr_eviction(void) { for (i = 0; i < NGTCP2_ACKTR_MAX_ENT + extra; ++i) { ngtcp2_acktr_entry_new(&ent, i, 0, 0, mem); - ngtcp2_acktr_add(&acktr, ent, 1); + ngtcp2_acktr_add(&acktr, ent, 1, 999 + i); } CU_ASSERT(NGTCP2_ACKTR_MAX_ENT == acktr.nack); @@ -123,7 +123,7 @@ void test_ngtcp2_acktr_eviction(void) { for (i = NGTCP2_ACKTR_MAX_ENT + extra; i > 0; --i) { ngtcp2_acktr_entry_new(&ent, i - 1, 0, 0, mem); - ngtcp2_acktr_add(&acktr, ent, 1); + ngtcp2_acktr_add(&acktr, ent, 1, 999 + i); } CU_ASSERT(NGTCP2_ACKTR_MAX_ENT == acktr.nack); @@ -154,7 +154,7 @@ void test_ngtcp2_acktr_forget(void) { for (i = 0; i < 7; ++i) { ngtcp2_acktr_entry_new(&ent, i, 0, 0, mem); - ngtcp2_acktr_add(&acktr, ent, 1); + ngtcp2_acktr_add(&acktr, ent, 1, 999 + i); } CU_ASSERT(7 == acktr.nack); @@ -190,7 +190,7 @@ void test_ngtcp2_acktr_recv_ack(void) { for (i = 0; i < arraylen(rpkt_nums); ++i) { ngtcp2_acktr_entry_new(&ent, rpkt_nums[i], 1, 0, mem); - ngtcp2_acktr_add(&acktr, ent, 1); + ngtcp2_acktr_add(&acktr, ent, 1, 999 + i); } for (pkt_num = 998; pkt_num <= 999; ++pkt_num) {