From 5e115353d8538318d3ae49c487669152118203a7 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Thu, 29 Mar 2018 16:26:13 +0900 Subject: [PATCH] Log when a packet after last handshake packet was acknowledged --- lib/ngtcp2_acktr.c | 6 +++++- lib/ngtcp2_acktr.h | 6 +++++- lib/ngtcp2_conn.c | 9 +++++---- tests/ngtcp2_acktr_test.c | 20 ++++++++++++++------ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/ngtcp2_acktr.c b/lib/ngtcp2_acktr.c index 8149ed1b..9af50928 100644 --- a/lib/ngtcp2_acktr.c +++ b/lib/ngtcp2_acktr.c @@ -50,7 +50,7 @@ void ngtcp2_acktr_entry_del(ngtcp2_acktr_entry *ent, ngtcp2_mem *mem) { ngtcp2_mem_free(mem, ent); } -int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_mem *mem) { +int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log, ngtcp2_mem *mem) { int rv; rv = ngtcp2_ringbuf_init(&acktr->acks, 128, sizeof(ngtcp2_acktr_ack_entry), @@ -61,6 +61,7 @@ int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_mem *mem) { acktr->ent = NULL; acktr->tail = NULL; + acktr->log = log; acktr->mem = mem; acktr->nack = 0; acktr->last_hs_ack_pkt_num = UINT64_MAX; @@ -230,6 +231,9 @@ static void acktr_on_ack(ngtcp2_acktr *acktr, size_t ack_ent_offset) { if (ent->pkt_num >= acktr->last_hs_ack_pkt_num) { acktr->flags |= NGTCP2_ACKTR_FLAG_ACK_FINISHED_ACK; acktr->last_hs_ack_pkt_num = UINT64_MAX; + + ngtcp2_log_info(acktr->log, NGTCP2_LOG_EVENT_CON, + "packet after last handshake packet was acknowledged"); } /* Assume that ngtcp2_pkt_validate_ack(fr) returns 0 */ diff --git a/lib/ngtcp2_acktr.h b/lib/ngtcp2_acktr.h index 12fba895..177a462b 100644 --- a/lib/ngtcp2_acktr.h +++ b/lib/ngtcp2_acktr.h @@ -47,6 +47,9 @@ typedef struct ngtcp2_conn ngtcp2_conn; struct ngtcp2_acktr_entry; typedef struct ngtcp2_acktr_entry ngtcp2_acktr_entry; +struct ngtcp2_log; +typedef struct ngtcp2_log ngtcp2_log; + /* * ngtcp2_acktr_entry is a single packet which needs to be acked. */ @@ -110,6 +113,7 @@ typedef struct { /* ent points to the head of list which is ordered by the decreasing order of packet number. */ ngtcp2_acktr_entry *ent, *tail; + ngtcp2_log *log; ngtcp2_mem *mem; size_t nack; /* last_hs_ack_pkt_num is the earliest outgoing packet number which @@ -139,7 +143,7 @@ typedef struct { * NGTCP2_ERR_NOMEM * Out of memory. */ -int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_mem *mem); +int ngtcp2_acktr_init(ngtcp2_acktr *acktr, ngtcp2_log *log, ngtcp2_mem *mem); /* * ngtcp2_acktr_free frees resources allocated for |acktr|. It frees diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c index 30d20f4b..811a356b 100644 --- a/lib/ngtcp2_conn.c +++ b/lib/ngtcp2_conn.c @@ -192,13 +192,14 @@ static int conn_new(ngtcp2_conn **pconn, uint64_t conn_id, uint32_t version, goto fail_remote_uni_idtr_init; } - rv = ngtcp2_acktr_init(&(*pconn)->acktr, mem); + ngtcp2_log_init(&(*pconn)->log, &(*pconn)->conn_id, settings->log_fd, + settings->initial_ts); + + rv = ngtcp2_acktr_init(&(*pconn)->acktr, &(*pconn)->log, mem); if (rv != 0) { goto fail_acktr_init; } - ngtcp2_log_init(&(*pconn)->log, &(*pconn)->conn_id, settings->log_fd, - settings->initial_ts); ngtcp2_rtb_init(&(*pconn)->rtb, &(*pconn)->log, mem); (*pconn)->callbacks = *callbacks; @@ -2195,7 +2196,7 @@ static int conn_recv_server_stateless_retry(ngtcp2_conn *conn) { conn->strm0 = strm0; - ngtcp2_acktr_init(&conn->acktr, conn->mem); + ngtcp2_acktr_init(&conn->acktr, &conn->log, conn->mem); ngtcp2_rtb_init(&conn->rtb, &conn->log, conn->mem); ngtcp2_map_insert(&conn->strms, &conn->strm0->me); diff --git a/tests/ngtcp2_acktr_test.c b/tests/ngtcp2_acktr_test.c index aba772a7..bc61c0ca 100644 --- a/tests/ngtcp2_acktr_test.c +++ b/tests/ngtcp2_acktr_test.c @@ -37,8 +37,10 @@ void test_ngtcp2_acktr_add(void) { size_t i; int rv; ngtcp2_mem *mem = ngtcp2_mem_default(); + ngtcp2_log log; - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_log_init(&log, NULL, -1, 0); + ngtcp2_acktr_init(&acktr, &log, mem); ngtcp2_acktr_entry_new(&ents[0], 1, 1000, 0, mem); ngtcp2_acktr_entry_new(&ents[1], 5, 1001, 0, mem); @@ -73,7 +75,7 @@ void test_ngtcp2_acktr_add(void) { ngtcp2_acktr_free(&acktr); /* Check duplicates */ - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_acktr_init(&acktr, &log, mem); ngtcp2_acktr_entry_new(&ents[0], 1, 1000, 0, mem); rv = ngtcp2_acktr_add(&acktr, ents[0], 1, 999); @@ -93,8 +95,10 @@ void test_ngtcp2_acktr_eviction(void) { size_t i; ngtcp2_acktr_entry *ent, *next; const size_t extra = 17; + ngtcp2_log log; - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_log_init(&log, NULL, -1, 0); + ngtcp2_acktr_init(&acktr, &log, mem); for (i = 0; i < NGTCP2_ACKTR_MAX_ENT + extra; ++i) { ngtcp2_acktr_entry_new(&ent, i, 0, 0, mem); @@ -119,7 +123,7 @@ void test_ngtcp2_acktr_eviction(void) { ngtcp2_acktr_free(&acktr); /* Invert insertion order */ - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_acktr_init(&acktr, &log, mem); for (i = NGTCP2_ACKTR_MAX_ENT + extra; i > 0; --i) { ngtcp2_acktr_entry_new(&ent, i - 1, 0, 0, mem); @@ -149,8 +153,10 @@ void test_ngtcp2_acktr_forget(void) { ngtcp2_mem *mem = ngtcp2_mem_default(); size_t i; ngtcp2_acktr_entry *ent; + ngtcp2_log log; - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_log_init(&log, NULL, -1, 0); + ngtcp2_acktr_init(&acktr, &log, mem); for (i = 0; i < 7; ++i) { ngtcp2_acktr_entry_new(&ent, i, 0, 0, mem); @@ -185,8 +191,10 @@ void test_ngtcp2_acktr_recv_ack(void) { ngtcp2_acktr_entry *ent; uint64_t pkt_num; ngtcp2_ack_blk *blks; + ngtcp2_log log; - ngtcp2_acktr_init(&acktr, mem); + ngtcp2_log_init(&log, NULL, -1, 0); + ngtcp2_acktr_init(&acktr, &log, mem); for (i = 0; i < arraylen(rpkt_nums); ++i) { ngtcp2_acktr_entry_new(&ent, rpkt_nums[i], 1, 0, mem); -- GitLab