Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/transport/xqc_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ xqc_conn_create(xqc_engine_t *engine, xqc_cid_t *dcid, xqc_cid_t *scid,
goto fail;
}

// Initial here as idle_timeout dependency
xqc_init_list_head(&xc->conn_paths_list);

xqc_conn_init_timer_manager(xc);

if (xc->conn_settings.datagram_redundant_probe) {
Expand Down Expand Up @@ -5818,17 +5821,6 @@ xqc_conn_get_local_transport_params(xqc_connection_t *conn, xqc_transport_params
conn->original_dcid.cid_buf, conn->original_dcid.cid_len);
params->original_dest_connection_id_present = 1;

xqc_gen_reset_token(&conn->original_dcid,
params->stateless_reset_token,
XQC_STATELESS_RESET_TOKENLEN,
conn->engine->config->reset_token_key,
conn->engine->config->reset_token_keylen);
params->stateless_reset_token_present = 1;

xqc_log(conn->log, XQC_LOG_INFO, "|generate sr_token[%s] for cid[%s]",
xqc_sr_token_str(conn->engine, params->stateless_reset_token),
xqc_scid_str(conn->engine, &conn->original_dcid));

} else {
params->original_dest_connection_id_present = 0;
}
Expand All @@ -5837,6 +5829,22 @@ xqc_conn_get_local_transport_params(xqc_connection_t *conn, xqc_transport_params
conn->initial_scid.cid_buf, conn->initial_scid.cid_len);
params->initial_source_connection_id_present = 1;

/* RFC 9000: server's stateless_reset_token is associated with its CID */
if (conn->conn_type == XQC_CONN_TYPE_SERVER
&& conn->initial_scid.cid_len > 0)
{
xqc_gen_reset_token(&conn->initial_scid,
params->stateless_reset_token,
XQC_STATELESS_RESET_TOKENLEN,
conn->engine->config->reset_token_key,
conn->engine->config->reset_token_keylen);
params->stateless_reset_token_present = 1;

xqc_log(conn->log, XQC_LOG_INFO, "|generate sr_token[%s] for cid[%s]|",
xqc_sr_token_str(conn->engine, params->stateless_reset_token),
xqc_scid_str(conn->engine, &conn->initial_scid));
}

if (conn->conn_type == XQC_CONN_TYPE_SERVER
&& conn->conn_flag & XQC_CONN_FLAG_RETRY_SENT
&& conn->retry_scid.cid_len > 0)
Expand Down Expand Up @@ -6393,8 +6401,19 @@ xqc_conn_get_idle_timeout(xqc_connection_t *conn)
? XQC_CONN_INITIAL_IDLE_TIMEOUT : conn->conn_settings.init_idle_time_out;

} else {
return conn->local_settings.max_idle_timeout == 0
xqc_msec_t local = conn->local_settings.max_idle_timeout == 0
? XQC_CONN_DEFAULT_IDLE_TIMEOUT : conn->local_settings.max_idle_timeout;

xqc_msec_t remote_idle_timeout = (xqc_msec_t)conn->remote_settings.max_idle_timeout;
xqc_msec_t idle_timeout = (remote_idle_timeout > 0) ? xqc_min(local, remote_idle_timeout) : local;
Comment on lines +6404 to +6408
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in xqc_conn_get_idle_timeout() alter timeout semantics (using both local and remote advertised values). There are no unit tests covering the effective idle-timeout calculation; please add targeted cases in tests/unittest/xqc_conn_test.c to prevent regressions.

Copilot uses AI. Check for mistakes.

xqc_usec_t pto = xqc_conn_get_max_pto(conn);
if (pto > 0) {
xqc_msec_t min_idle_timeout = (xqc_msec_t)((3 * pto + 999) / 1000);
idle_timeout = xqc_max(idle_timeout, min_idle_timeout);
}

Comment on lines +6410 to +6415
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xqc_conn_get_idle_timeout() computes the effective idle timeout as min(local, remote) but then increases it to at least 3PTO. This can make the actual idle timeout exceed the negotiated/advertised max_idle_timeout, which is contrary to RFC 9000’s definition of the effective value (minimum of the two advertised values). If you need a minimum duration of 3PTO, that should be applied to the closing/draining timers (or a separate timeout) rather than the negotiated idle timeout.

Suggested change
xqc_usec_t pto = xqc_conn_get_max_pto(conn);
if (pto > 0) {
xqc_msec_t min_idle_timeout = (xqc_msec_t)((3 * pto + 999) / 1000);
idle_timeout = xqc_max(idle_timeout, min_idle_timeout);
}

Copilot uses AI. Check for mistakes.
return idle_timeout;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/transport/xqc_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ struct xqc_connection_s {
xqc_usec_t conn_close_recv_time;
xqc_usec_t conn_close_send_time;
xqc_usec_t conn_last_send_time;
xqc_usec_t conn_last_ack_eliciting_send_time;
xqc_usec_t conn_last_recv_time;
xqc_usec_t conn_hsk_recv_time;

Expand Down
2 changes: 1 addition & 1 deletion src/transport/xqc_packet_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ xqc_int_t
xqc_packet_parse_stateless_reset(const unsigned char *buf, size_t buf_size,
const uint8_t **sr_token)
{
if (buf_size <= XQC_STATELESS_RESET_PKT_MIN_LEN) {
if (buf_size < XQC_STATELESS_RESET_PKT_MIN_LEN) {
return -XQC_EILLPKT;
}

Expand Down
13 changes: 12 additions & 1 deletion src/transport/xqc_send_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,17 @@ xqc_send_ctl_on_packet_sent(xqc_send_ctl_t *send_ctl, xqc_pn_ctl_t *pn_ctl, xqc_
if (XQC_CAN_IN_FLIGHT(packet_out->po_frame_types)) {

if (XQC_IS_ACK_ELICITING(packet_out->po_frame_types)) {
xqc_connection_t *conn = send_ctl->ctl_conn;

if (conn->conn_last_ack_eliciting_send_time <= conn->conn_last_recv_time) {
xqc_msec_t idle_timeout = xqc_conn_get_idle_timeout(conn);
if (idle_timeout > 0) {
xqc_timer_set(&conn->conn_timer_manager, XQC_TIMER_CONN_IDLE,
now, idle_timeout * 1000);
}
}
conn->conn_last_ack_eliciting_send_time = now;

send_ctl->ctl_time_of_last_sent_ack_eliciting_packet[pns] =
packet_out->po_sent_time;
send_ctl->ctl_last_sent_ack_eliciting_packet_number[pns] =
Expand Down Expand Up @@ -1930,4 +1941,4 @@ xqc_send_ctl_set_next_pn_for_packet(xqc_connection_t *conn, xqc_pn_ctl_t *pn_ctl
}
pn_ctl->ctl_packet_number[packet_out->po_pkt.pkt_pns] = packet_out->po_pkt.pkt_num + 1;
}
}
}
Loading