From 146b53b32f90c1fe21c712f3e685e0bbdb91d1b4 Mon Sep 17 00:00:00 2001 From: Yanmei-Liu Date: Tue, 28 Jan 2025 18:38:40 +0800 Subject: [PATCH] [+] add path cids blocked trigger logic. --- include/xquic/xqc_errno.h | 2 ++ src/transport/xqc_engine.c | 15 +++++++++++++-- src/transport/xqc_packet_out.c | 29 +++++++++++++++++++++++++++++ src/transport/xqc_packet_out.h | 2 ++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/xquic/xqc_errno.h b/include/xquic/xqc_errno.h index e4292deb..e229da56 100644 --- a/include/xquic/xqc_errno.h +++ b/include/xquic/xqc_errno.h @@ -283,6 +283,8 @@ typedef enum { XQC_PATH_NO_ERROR = 0x0, XQC_PATH_APPLICATION_ABANDON = 0x004150504142414E, /* Path abandon error code: APPLICATION_ABANDON */ XQC_PATH_RESOURCE_LIMIT_REACHED = 0x0052534C494D4954, /* Path abandon error code: RESOURCE_LIMIT_REACHED */ + XQC_PATH_UNSTABLE_INTERFACE = 0x00554e5f494e5446, /* Path abandon error code: UNSTABLE_INTERFACE */ + XQC_PATH_NO_CID_AVAILABLE = 0x004e4f5f4349445f, /* Path abandon error code: NO_CID_AVAILABLE */ } xqc_multipath_error_t; #define QPACK_ERR_START 900 diff --git a/src/transport/xqc_engine.c b/src/transport/xqc_engine.c index 40bbd0d2..75c0e961 100644 --- a/src/transport/xqc_engine.c +++ b/src/transport/xqc_engine.c @@ -651,7 +651,7 @@ xqc_engine_process_conn(xqc_connection_t *conn, xqc_usec_t now) xqc_log(conn->log, XQC_LOG_DEBUG, "|conn:%p|state:%s|flag:%s|now:%ui|", conn, xqc_conn_state_2_str(conn->conn_state), xqc_conn_flag_2_str(conn, conn->conn_flag), now); - int ret; + int ret = 0, rc = 0; xqc_bool_t wait_scid, wait_dcid; xqc_conn_timer_expire(conn, now); @@ -733,11 +733,22 @@ xqc_engine_process_conn(xqc_connection_t *conn, xqc_usec_t now) } if (conn->enable_multipath) { + ret = xqc_conn_get_available_path_id(conn, NULL); if ((conn->conn_flag & XQC_CONN_FLAG_MP_WAIT_MP_READY) - && xqc_conn_get_available_path_id(conn, NULL) == XQC_OK) + && ret == XQC_OK) { conn->conn_flag |= XQC_CONN_FLAG_MP_READY_NOTIFY; conn->conn_flag &= ~XQC_CONN_FLAG_MP_WAIT_MP_READY; + } else if (ret != XQC_OK) { + /* not enough cid for new path id */ + uint64_t path_id = conn->create_path_count; + xqc_cid_set_inner_t *dcid_inner_set = xqc_get_path_cid_set(&conn->dcid_set, path_id); + if (dcid_inner_set && dcid_inner_set->unused_cnt == 0) { + rc = xqc_write_path_cids_blocked_to_packet(conn, path_id); + if (rc) { + xqc_log(conn->log, XQC_LOG_WARN, "|xqc_write_path_cids_blocked_to_packet error|ret:%ui|", ret); + } + } } xqc_log(conn->log, XQC_LOG_DEBUG, "|create_path_count:%ui|remote_max_path_id:%ui|", diff --git a/src/transport/xqc_packet_out.c b/src/transport/xqc_packet_out.c index 41832dd5..2f82d75a 100644 --- a/src/transport/xqc_packet_out.c +++ b/src/transport/xqc_packet_out.c @@ -1839,6 +1839,35 @@ xqc_write_path_blocked_to_packet(xqc_connection_t *conn, uint64_t max_path_id) xqc_log(conn->log, XQC_LOG_DEBUG, "|max_path_id:%ui|", max_path_id); return XQC_OK; + error: + xqc_maybe_recycle_packet_out(packet_out, conn); + return -XQC_EWRITE_PKT; +} + + +int +xqc_write_path_cids_blocked_to_packet(xqc_connection_t *conn, uint64_t path_id) +{ + ssize_t ret = XQC_ERROR; + xqc_packet_out_t *packet_out; + xqc_log(conn->log, XQC_LOG_DEBUG, "|path blocked max_path_id:%ui|", path_id); + + packet_out = xqc_write_new_packet(conn, XQC_PTYPE_SHORT_HEADER); + if (packet_out == NULL) { + xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_write_new_packet error|"); + return -XQC_EWRITE_PKT; + } + + ret = xqc_gen_path_cids_blocked_frame(packet_out, path_id); + if (ret < 0) { + xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_gen_path_blocked_frame error|"); + goto error; + } + packet_out->po_used_size += ret; + xqc_send_queue_move_to_high_pri(&packet_out->po_list, conn->conn_send_queue); + xqc_log(conn->log, XQC_LOG_DEBUG, "|max_path_id:%ui|", path_id); + return XQC_OK; + error: xqc_maybe_recycle_packet_out(packet_out, conn); return -XQC_EWRITE_PKT; diff --git a/src/transport/xqc_packet_out.h b/src/transport/xqc_packet_out.h index 0168a85c..248a14f5 100644 --- a/src/transport/xqc_packet_out.h +++ b/src/transport/xqc_packet_out.h @@ -233,6 +233,8 @@ xqc_int_t xqc_write_mp_retire_conn_id_frame_to_packet(xqc_connection_t *conn, ui int xqc_write_max_path_id_to_packet(xqc_connection_t *conn, uint64_t max_path_id); int xqc_write_path_blocked_to_packet(xqc_connection_t *conn, uint64_t max_path_id); +int xqc_write_path_cids_blocked_to_packet(xqc_connection_t *conn, uint64_t path_id); + /** * @brief Get remained space size in packet out buff. *