From c7d29aa6f95d4c28b6f2ff5be0d3b7f8792df7b1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Sun, 7 Jun 2020 18:48:40 +0900 Subject: [PATCH] Use fields directly --- lib/ngtcp2_conn.c | 14 +++++++------- lib/ngtcp2_rtb.c | 8 -------- lib/ngtcp2_rtb.h | 17 +++-------------- tests/ngtcp2_conn_test.c | 14 +++++++------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c index 5b6a58d7..3cf43d17 100644 --- a/lib/ngtcp2_conn.c +++ b/lib/ngtcp2_conn.c @@ -1975,7 +1975,7 @@ static void conn_discard_pktns(ngtcp2_conn *conn, ngtcp2_pktns **ppktns, ngtcp2_pktns *pktns = *ppktns; uint64_t bytes_in_flight; - bytes_in_flight = ngtcp2_rtb_get_cc_bytes_in_flight(&pktns->rtb); + bytes_in_flight = pktns->rtb.cc_bytes_in_flight; assert(conn->cstat.bytes_in_flight >= bytes_in_flight); @@ -2996,7 +2996,7 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, uint8_t *dest, } if ((rtb_entry_flags & NGTCP2_RTB_FLAG_ACK_ELICITING) && - ngtcp2_rtb_num_ack_eliciting(&pktns->rtb) == 0 && conn->cc.event) { + pktns->rtb.num_ack_eliciting == 0 && conn->cc.event) { conn->cc.event(&conn->cc, &conn->cstat, NGTCP2_CC_EVENT_TYPE_TX_START, ts); } @@ -3196,9 +3196,9 @@ static int conn_handshake_remnants_left(ngtcp2_conn *conn) { ngtcp2_pktns *hs_pktns = conn->hs_pktns; return !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED) || - (in_pktns && (ngtcp2_rtb_num_ack_eliciting(&in_pktns->rtb) || + (in_pktns && (in_pktns->rtb.num_ack_eliciting || ngtcp2_ksl_len(&in_pktns->crypto.tx.frq))) || - (hs_pktns && (ngtcp2_rtb_num_ack_eliciting(&hs_pktns->rtb) || + (hs_pktns && (hs_pktns->rtb.num_ack_eliciting || ngtcp2_ksl_len(&hs_pktns->crypto.tx.frq))); } @@ -9061,9 +9061,9 @@ void ngtcp2_conn_set_loss_detection_timer(ngtcp2_conn *conn, ngtcp2_tstamp ts) { return; } - if ((!in_pktns || ngtcp2_rtb_num_ack_eliciting(&in_pktns->rtb) == 0) && - (!hs_pktns || ngtcp2_rtb_num_ack_eliciting(&hs_pktns->rtb) == 0) && - (ngtcp2_rtb_num_ack_eliciting(&pktns->rtb) == 0 || + if ((!in_pktns || in_pktns->rtb.num_ack_eliciting == 0) && + (!hs_pktns || hs_pktns->rtb.num_ack_eliciting == 0) && + (pktns->rtb.num_ack_eliciting == 0 || !(conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_COMPLETED)) && (conn->server || (conn->flags & (NGTCP2_CONN_FLAG_SERVER_ADDR_VERIFIED | diff --git a/lib/ngtcp2_rtb.c b/lib/ngtcp2_rtb.c index 8f473afe..e7e6762e 100644 --- a/lib/ngtcp2_rtb.c +++ b/lib/ngtcp2_rtb.c @@ -703,14 +703,6 @@ int ngtcp2_rtb_empty(ngtcp2_rtb *rtb) { return ngtcp2_ksl_len(&rtb->ents) == 0; } -uint64_t ngtcp2_rtb_get_cc_bytes_in_flight(ngtcp2_rtb *rtb) { - return rtb->cc_bytes_in_flight; -} - -size_t ngtcp2_rtb_num_ack_eliciting(ngtcp2_rtb *rtb) { - return rtb->num_ack_eliciting; -} - void ngtcp2_rtb_reset_cc_state(ngtcp2_rtb *rtb, int64_t cc_pkt_num) { rtb->cc_pkt_num = cc_pkt_num; rtb->cc_bytes_in_flight = 0; diff --git a/lib/ngtcp2_rtb.h b/lib/ngtcp2_rtb.h index 5c497342..6dac9b63 100644 --- a/lib/ngtcp2_rtb.h +++ b/lib/ngtcp2_rtb.h @@ -215,6 +215,7 @@ typedef struct { /* largest_acked_tx_pkt_num is the largest packet number acknowledged by the peer. */ int64_t largest_acked_tx_pkt_num; + /* num_ack_eliciting is the number of ACK eliciting entries. */ size_t num_ack_eliciting; /* probe_pkt_left is the number of probe packet to send */ size_t probe_pkt_left; @@ -224,7 +225,8 @@ typedef struct { ngtcp2_conn_stat.bytes_in_flight. */ int64_t cc_pkt_num; /* cc_bytes_in_flight is the number of in-flight bytes that is - contributed to ngtcp2_conn_stat.bytes_in_flight. */ + contributed to ngtcp2_conn_stat.bytes_in_flight. It only + includes the bytes after congestion state is reset. */ uint64_t cc_bytes_in_flight; } ngtcp2_rtb; @@ -315,19 +317,6 @@ int ngtcp2_rtb_on_crypto_timeout(ngtcp2_rtb *rtb, ngtcp2_frame_chain **pfrc, */ int ngtcp2_rtb_empty(ngtcp2_rtb *rtb); -/* - * ngtcp2_rtb_get_cc_bytes_in_flight returns the sum of bytes - * in-flight for the stored entries. It only includes the bytes after - * congestion state is reset. - */ -uint64_t ngtcp2_rtb_get_cc_bytes_in_flight(ngtcp2_rtb *rtb); - -/* - * ngtcp2_rtb_num_ack_eliciting returns the number of ACK eliciting - * entries. - */ -size_t ngtcp2_rtb_num_ack_eliciting(ngtcp2_rtb *rtb); - /* * ngtcp2_rtb_reset_cc_state resets congestion state in |rtb|. * |cc_pkt_num| is the next outbound packet number which is sent under diff --git a/tests/ngtcp2_conn_test.c b/tests/ngtcp2_conn_test.c index 4f0d8547..dbc96bce 100644 --- a/tests/ngtcp2_conn_test.c +++ b/tests/ngtcp2_conn_test.c @@ -4695,7 +4695,7 @@ void test_ngtcp2_conn_handshake_probe(void) { spktlen = ngtcp2_conn_write_pkt(conn, NULL, buf, sizeof(buf), ++t); CU_ASSERT(spktlen > 0); - CU_ASSERT(1 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(1 == conn->in_pktns->rtb.num_ack_eliciting); rv = ngtcp2_conn_on_loss_detection_timer(conn, ++t); @@ -4706,7 +4706,7 @@ void test_ngtcp2_conn_handshake_probe(void) { CU_ASSERT(spktlen > 0); /* We don't make the first packet lost */ - CU_ASSERT(2 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(2 == conn->in_pktns->rtb.num_ack_eliciting); CU_ASSERT(0 == conn->in_pktns->rtb.probe_pkt_left); fr.type = NGTCP2_FRAME_ACK; @@ -4721,12 +4721,12 @@ void test_ngtcp2_conn_handshake_probe(void) { rv = ngtcp2_conn_read_pkt(conn, &null_path, buf, pktlen, ++t); CU_ASSERT(0 == rv); - CU_ASSERT(1 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(1 == conn->in_pktns->rtb.num_ack_eliciting); rv = ngtcp2_conn_on_loss_detection_timer(conn, ++t); CU_ASSERT(0 == rv); - CU_ASSERT(0 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(0 == conn->in_pktns->rtb.num_ack_eliciting); CU_ASSERT(1 == conn->in_pktns->rtb.probe_pkt_left); /* This sends anti-deadlock padded Initial packet even if we have @@ -4734,7 +4734,7 @@ void test_ngtcp2_conn_handshake_probe(void) { spktlen = ngtcp2_conn_write_pkt(conn, NULL, buf, sizeof(buf), ++t); CU_ASSERT(spktlen > 0); - CU_ASSERT(1 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(1 == conn->in_pktns->rtb.num_ack_eliciting); CU_ASSERT(0 == conn->in_pktns->rtb.probe_pkt_left); it = ngtcp2_rtb_head(&conn->in_pktns->rtb); @@ -4752,7 +4752,7 @@ void test_ngtcp2_conn_handshake_probe(void) { rv = ngtcp2_conn_on_loss_detection_timer(conn, ++t); CU_ASSERT(0 == rv); - CU_ASSERT(1 == ngtcp2_rtb_num_ack_eliciting(&conn->in_pktns->rtb)); + CU_ASSERT(1 == conn->in_pktns->rtb.num_ack_eliciting); CU_ASSERT(1 == conn->hs_pktns->rtb.probe_pkt_left); /* This sends anti-deadlock Handshake packet even if we have nothing @@ -4760,7 +4760,7 @@ void test_ngtcp2_conn_handshake_probe(void) { spktlen = ngtcp2_conn_write_pkt(conn, NULL, buf, sizeof(buf), ++t); CU_ASSERT(spktlen > 0); - CU_ASSERT(1 == ngtcp2_rtb_num_ack_eliciting(&conn->hs_pktns->rtb)); + CU_ASSERT(1 == conn->hs_pktns->rtb.num_ack_eliciting); CU_ASSERT(0 == conn->hs_pktns->rtb.probe_pkt_left); it = ngtcp2_rtb_head(&conn->hs_pktns->rtb); -- GitLab