@@ -5329,7 +5329,6 @@ static int conn_recv_ack(ngtcp2_conn *conn, ngtcp2_pktns *pktns, ngtcp2_ack *fr,
53295329 num_acked = ngtcp2_rtb_recv_ack (& pktns -> rtb , fr , & conn -> cstat , conn , pktns ,
53305330 pkt_ts , ts );
53315331 if (num_acked < 0 ) {
5332- /* TODO assert this */
53335332 assert (ngtcp2_err_is_fatal ((int )num_acked ));
53345333 return (int )num_acked ;
53355334 }
@@ -5790,9 +5789,8 @@ static int conn_recv_path_response(ngtcp2_conn *conn, ngtcp2_path_response *fr,
57905789 }
57915790
57925791 if (!(pv -> flags & NGTCP2_PV_FLAG_DONT_CARE )) {
5793- if (!( pv -> flags & NGTCP2_PV_FLAG_FALLBACK_ON_FAILURE ) ) {
5792+ if (pv -> dcid . seq != conn -> dcid . current . seq ) {
57945793 assert (!conn -> server );
5795- assert (pv -> dcid .seq != conn -> dcid .current .seq );
57965794 assert (conn -> dcid .current .cid .datalen );
57975795
57985796 rv = conn_retire_dcid (conn , & conn -> dcid .current , ts );
@@ -5871,25 +5869,6 @@ static int conn_recv_path_response(ngtcp2_conn *conn, ngtcp2_path_response *fr,
58715869 return conn_stop_pv (conn , ts );
58725870}
58735871
5874- /*
5875- * pkt_num_bits returns the number of bits available when packet
5876- * number is encoded in |pkt_numlen| bytes.
5877- */
5878- static size_t pkt_num_bits (size_t pkt_numlen ) {
5879- switch (pkt_numlen ) {
5880- case 1 :
5881- return 8 ;
5882- case 2 :
5883- return 16 ;
5884- case 3 :
5885- return 24 ;
5886- case 4 :
5887- return 32 ;
5888- default :
5889- ngtcp2_unreachable ();
5890- }
5891- }
5892-
58935872/*
58945873 * pktns_pkt_num_is_duplicate returns nonzero if |pkt_num| is
58955874 * duplicated packet number.
@@ -6020,9 +5999,7 @@ static int conn_verify_fixed_bit(ngtcp2_conn *conn, ngtcp2_pkt_hd *hd) {
60205999 case NGTCP2_PKT_INITIAL :
60216000 case NGTCP2_PKT_0RTT :
60226001 case NGTCP2_PKT_HANDSHAKE :
6023- /* TODO we cannot determine whether a token comes from NEW_TOKEN
6024- frame or Retry packet. RFC 9287 requires that a token from
6025- NEW_TOKEN. */
6002+ /* RFC 9287 requires that a token from NEW_TOKEN. */
60266003 if (!(conn -> flags & NGTCP2_CONN_FLAG_INITIAL_PKT_PROCESSED ) &&
60276004 (conn -> local .settings .token_type != NGTCP2_TOKEN_TYPE_NEW_TOKEN ||
60286005 !conn -> local .settings .tokenlen )) {
@@ -6145,7 +6122,8 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
61456122 return NGTCP2_ERR_DISCARD_PKT ;
61466123 }
61476124
6148- if (hd .type == NGTCP2_PKT_VERSION_NEGOTIATION ) {
6125+ switch (hd .type ) {
6126+ case NGTCP2_PKT_VERSION_NEGOTIATION :
61496127 hdpktlen = (size_t )nread ;
61506128
61516129 ngtcp2_log_rx_pkt_hd (& conn -> log , & hd );
@@ -6181,7 +6159,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
61816159 return NGTCP2_ERR_DISCARD_PKT ;
61826160 }
61836161 return NGTCP2_ERR_RECV_VERSION_NEGOTIATION ;
6184- } else if ( hd . type == NGTCP2_PKT_RETRY ) {
6162+ case NGTCP2_PKT_RETRY :
61856163 hdpktlen = (size_t )nread ;
61866164
61876165 ngtcp2_log_rx_pkt_hd (& conn -> log , & hd );
@@ -6402,10 +6380,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
64026380
64036381 break ;
64046382 default :
6405- /* unknown packet type */
6406- ngtcp2_log_info (& conn -> log , NGTCP2_LOG_EVENT_PKT ,
6407- "packet was ignored because of unknown packet type" );
6408- return (ngtcp2_ssize )pktlen ;
6383+ ngtcp2_unreachable ();
64096384 }
64106385
64116386 hp_mask = conn -> callbacks .hp_mask ;
@@ -6438,7 +6413,7 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
64386413 payloadlen = hd .len - hd .pkt_numlen ;
64396414
64406415 hd .pkt_num = ngtcp2_pkt_adjust_pkt_num (pktns -> rx .max_pkt_num , hd .pkt_num ,
6441- pkt_num_bits ( hd .pkt_numlen ) );
6416+ hd .pkt_numlen );
64426417 if (hd .pkt_num > NGTCP2_MAX_PKT_NUM ) {
64436418 ngtcp2_log_info (& conn -> log , NGTCP2_LOG_EVENT_PKT ,
64446419 "pkn=%" PRId64 " is greater than maximum pkn" , hd .pkt_num );
@@ -6624,14 +6599,8 @@ conn_recv_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
66246599
66256600 pktns_increase_ecn_counts (pktns , pi );
66266601
6627- /* TODO Initial and Handshake are always acknowledged without
6628- delay. */
6629- if (require_ack &&
6630- (++ pktns -> acktr .rx_npkt >= conn -> local .settings .ack_thresh ||
6631- (pi -> ecn & NGTCP2_ECN_MASK ) == NGTCP2_ECN_CE )) {
6632- ngtcp2_acktr_immediate_ack (& pktns -> acktr );
6633- }
6634-
6602+ /* Initial and Handshake are always acknowledged without delay. No
6603+ need to call ngtcp2_acktr_immediate_ack(). */
66356604 rv = ngtcp2_conn_sched_ack (conn , & pktns -> acktr , hd .pkt_num , require_ack ,
66366605 pkt_ts );
66376606 if (rv != 0 ) {
@@ -7057,7 +7026,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) {
70577026 if (strm == NULL ) {
70587027 return NGTCP2_ERR_NOMEM ;
70597028 }
7060- /* TODO Perhaps, call new_stream callback? */
7029+
70617030 rv = ngtcp2_conn_init_stream (conn , strm , fr -> stream_id , NULL );
70627031 if (rv != 0 ) {
70637032 ngtcp2_objalloc_strm_release (& conn -> strm_objalloc , strm );
@@ -7464,7 +7433,7 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74647433 return 0 ;
74657434 }
74667435
7467- /* Frame is received reset before we create ngtcp2_strm
7436+ /* STOP_SENDING frame is received before we create ngtcp2_strm
74687437 object. */
74697438 strm = ngtcp2_objalloc_strm_get (& conn -> strm_objalloc );
74707439 if (strm == NULL ) {
@@ -7482,6 +7451,10 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74827451 }
74837452 }
74847453
7454+ if (strm -> flags & NGTCP2_STRM_FLAG_STOP_SENDING_RECVED ) {
7455+ return 0 ;
7456+ }
7457+
74857458 ngtcp2_strm_set_app_error_code (strm , fr -> app_error_code );
74867459
74877460 /* No RESET_STREAM is required if we have sent FIN and all data have
@@ -7494,7 +7467,9 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74947467 }
74957468 }
74967469
7497- strm -> flags |= NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_RESET_STREAM ;
7470+ strm -> flags |= NGTCP2_STRM_FLAG_SHUT_WR |
7471+ NGTCP2_STRM_FLAG_STOP_SENDING_RECVED |
7472+ NGTCP2_STRM_FLAG_RESET_STREAM ;
74987473
74997474 ngtcp2_strm_streamfrq_clear (strm );
75007475
@@ -8751,12 +8726,8 @@ conn_recv_delayed_handshake_pkt(ngtcp2_conn *conn, const ngtcp2_pkt_info *pi,
87518726
87528727 pktns_increase_ecn_counts (pktns , pi );
87538728
8754- if (require_ack &&
8755- (++ pktns -> acktr .rx_npkt >= conn -> local .settings .ack_thresh ||
8756- (pi -> ecn & NGTCP2_ECN_MASK ) == NGTCP2_ECN_CE )) {
8757- ngtcp2_acktr_immediate_ack (& pktns -> acktr );
8758- }
8759-
8729+ /* Initial and Handshake are always acknowledged without delay. No
8730+ need to call ngtcp2_acktr_immediate_ack(). */
87608731 rv = ngtcp2_conn_sched_ack (conn , & pktns -> acktr , hd -> pkt_num , require_ack ,
87618732 pkt_ts );
87628733 if (rv != 0 ) {
@@ -9020,7 +8991,7 @@ static ngtcp2_ssize conn_recv_pkt(ngtcp2_conn *conn, const ngtcp2_path *path,
90208991 payloadlen = pktlen - hdpktlen ;
90218992
90228993 hd .pkt_num = ngtcp2_pkt_adjust_pkt_num (pktns -> rx .max_pkt_num , hd .pkt_num ,
9023- pkt_num_bits ( hd .pkt_numlen ) );
8994+ hd .pkt_numlen );
90248995 if (hd .pkt_num > NGTCP2_MAX_PKT_NUM ) {
90258996 ngtcp2_log_info (& conn -> log , NGTCP2_LOG_EVENT_PKT ,
90268997 "pkn=%" PRId64 " is greater than maximum pkn" , hd .pkt_num );
@@ -12551,7 +12522,8 @@ static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm,
1255112522 uint64_t app_error_code ) {
1255212523 ngtcp2_strm_set_app_error_code (strm , app_error_code );
1255312524
12554- if (strm -> flags & NGTCP2_STRM_FLAG_STOP_SENDING ) {
12525+ if (strm -> flags &
12526+ (NGTCP2_STRM_FLAG_STOP_SENDING | NGTCP2_STRM_FLAG_RESET_STREAM_RECVED )) {
1255512527 return 0 ;
1255612528 }
1255712529 if ((strm -> flags & NGTCP2_STRM_FLAG_SHUT_RD ) &&
0 commit comments