diff --git a/CMakeLists.txt b/CMakeLists.txt index ec8c5d60b..8e2ce2f95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,6 +359,7 @@ if(PLATFORM MATCHES "mac") ${SSL_LIB_PATH} "-Wl" -lpthread + -lstdc++ ) else() target_link_libraries( diff --git a/demo/demo_client.c b/demo/demo_client.c index 5c017004f..c256d9e08 100644 --- a/demo/demo_client.c +++ b/demo/demo_client.c @@ -190,6 +190,8 @@ typedef struct xqc_demo_cli_quic_config_s { size_t max_pkt_sz; + char co_str[XQC_CO_STR_MAX_LEN]; + } xqc_demo_cli_quic_config_t; @@ -1265,9 +1267,9 @@ xqc_demo_cli_h3_request_close_notify(xqc_h3_request_t *h3_request, void *user_da xqc_request_stats_t stats; stats = xqc_h3_request_get_stats(h3_request); printf("send_body_size:%zu, recv_body_size:%zu, send_header_size:%zu, recv_header_size:%zu, " - "recv_fin:%d, err:%d, rate_limit:%"PRIu64", mp_state:%d, avail_send_weight:%.3lf, avail_recv_weight:%.3lf\n", + "recv_fin:%d, err:%d, rate_limit:%"PRIu64", mp_state:%d, early_data:%d, avail_send_weight:%.3lf, avail_recv_weight:%.3lf\n", stats.send_body_size, stats.recv_body_size, stats.send_header_size, stats.recv_header_size, - user_stream->recv_fin, stats.stream_err, stats.rate_limit, stats.mp_state, + user_stream->recv_fin, stats.stream_err, stats.rate_limit, stats.mp_state, stats.early_data_state, stats.mp_default_path_send_weight, stats.mp_default_path_recv_weight); printf("\033[33m[H3-req] send_bytes:%zu, recv_bytes:%zu, path_info:%s\n\033[0m", @@ -1337,19 +1339,11 @@ xqc_demo_cli_socket_read_handler(xqc_demo_cli_user_conn_t *user_conn, int fd) recv_sum += recv_size; uint64_t recv_time = xqc_now(); user_path->last_sock_op_time = recv_time; -#ifdef XQC_NO_PID_PACKET_PROCESS if (xqc_engine_packet_process(user_conn->ctx->engine, packet_buf, recv_size, (struct sockaddr *)(&user_path->local_addr), user_path->local_addrlen, (struct sockaddr *)(&addr), addr_len, (xqc_msec_t)recv_time, user_conn) != XQC_OK) -#else - if (xqc_engine_packet_process(user_conn->ctx->engine, packet_buf, recv_size, - (struct sockaddr *)(&user_path->local_addr), - user_path->local_addrlen, (struct sockaddr *)(&addr), - addr_len, user_path->path_id, (xqc_msec_t)recv_time, - user_conn) != XQC_OK) -#endif { return; } @@ -1630,7 +1624,7 @@ xqc_demo_cli_init_conneciton_settings(xqc_conn_settings_t* settings, settings->pacing_on = args->net_cfg.pacing; settings->cong_ctrl_callback = cong_ctrl; settings->cc_params.customize_on = 1, - settings->cc_params.init_cwnd = 32, + settings->cc_params.init_cwnd = 96, settings->so_sndbuf = 1024*1024; settings->proto_version = XQC_VERSION_V1; settings->spurious_loss_detect_on = 1; @@ -1651,6 +1645,7 @@ xqc_demo_cli_init_conneciton_settings(xqc_conn_settings_t* settings, settings->enable_stream_rate_limit = 1; settings->recv_rate_bytes_per_sec = 0; } + strncpy(settings->conn_option_str, args->quic_cfg.co_str, XQC_CO_STR_MAX_LEN); } /* set client args to default values */ @@ -1797,6 +1792,7 @@ xqc_demo_cli_usage(int argc, char *argv[]) " -e NAT rebinding on path 0\n" " -E NAT rebinding on path 1\n" " -F MTU size (default: 1200)\n" + " -G Google connection options (e.g. CBBR,TBBR)\n" , prog); } @@ -1804,7 +1800,7 @@ void xqc_demo_cli_parse_args(int argc, char *argv[], xqc_demo_cli_client_args_t *args) { int ch = 0; - while ((ch = getopt(argc, argv, "a:p:c:Ct:S:0m:A:D:l:L:k:K:U:u:dMoi:w:Ps:bZ:NQT:R:V:B:I:n:eEF:")) != -1) { + while ((ch = getopt(argc, argv, "a:p:c:Ct:S:0m:A:D:l:L:k:K:U:u:dMoi:w:Ps:bZ:NQT:R:V:B:I:n:eEF:G:")) != -1) { switch (ch) { /* server ip */ case 'a': @@ -2043,6 +2039,11 @@ xqc_demo_cli_parse_args(int argc, char *argv[], xqc_demo_cli_client_args_t *args printf("MTU size: %s\n", optarg); args->quic_cfg.max_pkt_sz = atoi(optarg); break; + + case 'G': + printf("Google connection options: %s\n", optarg); + strncpy(args->quic_cfg.co_str, optarg, XQC_CO_STR_MAX_LEN); + break; default: printf("other option :%c\n", ch); @@ -2266,7 +2267,7 @@ xqc_demo_cli_h3_conn_close_notify(xqc_h3_conn_t *h3_conn, const xqc_cid_t *cid, xqc_demo_cli_user_conn_t *user_conn = (xqc_demo_cli_user_conn_t *)user_data; xqc_conn_stats_t stats = xqc_conn_get_stats(user_conn->ctx->engine, cid); printf("send_count:%u, lost_count:%u, tlp_count:%u, recv_count:%u, srtt:%"PRIu64" " - "early_data_flag:%d, conn_err:%d, ack_info:%s conn_info:%s\n", stats.send_count, stats.lost_count, + "early_data_flag:%d, conn_err:%d, ack_info:%s, conn_info:%s\n", stats.send_count, stats.lost_count, stats.tlp_count, stats.recv_count, stats.srtt, stats.early_data_flag, stats.conn_err, stats.ack_info, stats.conn_info); diff --git a/demo/demo_server.c b/demo/demo_server.c index 17f51af63..b41d66574 100644 --- a/demo/demo_server.c +++ b/demo/demo_server.c @@ -1052,17 +1052,10 @@ xqc_demo_svr_socket_read_handler(xqc_demo_svr_ctx_t *ctx, int fd) recv_sum += recv_size; uint64_t recv_time = xqc_now(); -#ifdef XQC_NO_PID_PACKET_PROCESS xqc_int_t ret = xqc_engine_packet_process(ctx->engine, packet_buf, recv_size, (struct sockaddr *)(&ctx->local_addr), ctx->local_addrlen, (struct sockaddr *)(&peer_addr), peer_addrlen, (xqc_usec_t)recv_time, ctx); -#else - xqc_int_t ret = xqc_engine_packet_process(ctx->engine, packet_buf, recv_size, - (struct sockaddr *)(&ctx->local_addr), ctx->local_addrlen, - (struct sockaddr *)(&peer_addr), peer_addrlen, XQC_UNKNOWN_PATH_ID, - (xqc_usec_t)recv_time, ctx); -#endif if (ret != XQC_OK) { printf("server_read_handler: packet process err, ret: %d\n", ret); return; diff --git a/include/xquic/xqc_http3.h b/include/xquic/xqc_http3.h index f14cae4e1..84dc25901 100644 --- a/include/xquic/xqc_http3.h +++ b/include/xquic/xqc_http3.h @@ -156,6 +156,14 @@ typedef struct xqc_request_stats_s { uint64_t rate_limit; + /** + * @brief 0RTT state + * 0: no 0RTT + * 1: 0RTT accept + * 2: 0RTT reject + */ + uint8_t early_data_state; + char stream_info[XQC_STREAM_INFO_LEN]; } xqc_request_stats_t; diff --git a/include/xquic/xquic.h b/include/xquic/xquic.h index b74406f35..8db733f82 100644 --- a/include/xquic/xquic.h +++ b/include/xquic/xquic.h @@ -71,6 +71,9 @@ typedef enum xqc_proto_version_s { #define XQC_DGRAM_RETX_ASKED_BY_APP 1 +#define XQC_CO_MAX_NUM 16 +#define XQC_CO_STR_MAX_LEN (5 * XQC_CO_MAX_NUM) + /** * @brief get timestamp callback function. this might be useful on different platforms @@ -1263,6 +1266,19 @@ typedef struct xqc_conn_settings_s { uint8_t protect_pool_mem; #endif + char conn_option_str[XQC_CO_STR_MAX_LEN]; + + /** + * @brief intial_rtt (us). Default: 0 (use the internal default value -- 250000) + * + */ + xqc_usec_t initial_rtt; + /** + * @brief initial pto duration (us). Default: 0 (use the internal default value -- 3xinitial_rtt) + * + */ + xqc_usec_t initial_pto_duration; + } xqc_conn_settings_t; @@ -1335,6 +1351,11 @@ typedef struct xqc_conn_stats_s { char alpn[XQC_MAX_ALPN_BUF_LEN]; } xqc_conn_stats_t; +typedef struct xqc_conn_qos_stats_s { + xqc_usec_t srtt; /* smoothed SRTT at present: initial value = 250000 */ + xqc_usec_t min_rtt; /* minimum RTT until now: initial value = 0xFFFFFFFF */ + uint64_t inflight_bytes; /* initial value = 0 */ +} xqc_conn_qos_stats_t; /************************************************************* * engine layer APIs @@ -1400,11 +1421,7 @@ xqc_int_t xqc_engine_unregister_alpn(xqc_engine_t *engine, const char *alpn, siz * Pass received UDP packet payload into xquic engine. * @param recv_time UDP packet received time in microsecond * @param user_data connection user_data, server is NULL - * @param path_id XQC_UNKNOWN_PATH_ID = unknown path (only use cid to identify the path) */ - -#ifdef XQC_NO_PID_PACKET_PROCESS - XQC_EXPORT_PUBLIC_API xqc_int_t xqc_engine_packet_process(xqc_engine_t *engine, const unsigned char *packet_in_buf, size_t packet_in_size, @@ -1412,17 +1429,6 @@ xqc_int_t xqc_engine_packet_process(xqc_engine_t *engine, const struct sockaddr *peer_addr, socklen_t peer_addrlen, xqc_usec_t recv_time, void *user_data); -#else - -XQC_EXPORT_PUBLIC_API -xqc_int_t xqc_engine_packet_process(xqc_engine_t *engine, - const unsigned char *packet_in_buf, size_t packet_in_size, - const struct sockaddr *local_addr, socklen_t local_addrlen, - const struct sockaddr *peer_addr, socklen_t peer_addrlen, - uint64_t path_id, xqc_usec_t recv_time, void *user_data); - -#endif - /** * @brief Process all connections, application implements MUST call this function in timer callback @@ -1817,6 +1823,13 @@ void xqc_conn_continue_send_by_conn(xqc_connection_t *conn); XQC_EXPORT_PUBLIC_API xqc_conn_stats_t xqc_conn_get_stats(xqc_engine_t *engine, const xqc_cid_t *cid); + +/** + * User can get xqc_conn_qos_stats_t by cid + */ +XQC_EXPORT_PUBLIC_API +xqc_conn_qos_stats_t xqc_conn_get_qos_stats(xqc_engine_t *engine, const xqc_cid_t *cid); + /** * create new path for client * @param cid scid for connection diff --git a/include/xquic/xquic_typedef.h b/include/xquic/xquic_typedef.h index 22171b595..bb4a905b0 100644 --- a/include/xquic/xquic_typedef.h +++ b/include/xquic/xquic_typedef.h @@ -94,6 +94,7 @@ typedef struct xqc_path_ctx_s xqc_path_ctx_t; typedef struct xqc_timer_manager_s xqc_timer_manager_t; typedef struct xqc_h3_ext_bytestream_s xqc_h3_ext_bytestream_t; typedef struct xqc_ping_record_s xqc_ping_record_t; +typedef struct xqc_conn_qos_stats_s xqc_conn_qos_stats_t; typedef uint64_t xqc_msec_t; /* store millisecond values */ typedef uint64_t xqc_usec_t; /* store microsecond values */ @@ -221,4 +222,61 @@ typedef struct xqc_stream_settings_s { uint64_t recv_rate_bytes_per_sec; } xqc_stream_settings_t; +#define XQC_CO_TAG(a, b, c, d) (uint32_t)((a << 24) + (b << 16) + (c << 8) + d) + +typedef enum xqc_conn_option_e { + XQC_CO_TBBR = XQC_CO_TAG('T', 'B', 'B', 'R'), // Reduced Buffer Bloat TCP + XQC_CO_1RTT = XQC_CO_TAG('1', 'R', 'T', 'T'), // STARTUP in BBR for 1 RTT + XQC_CO_2RTT = XQC_CO_TAG('2', 'R', 'T', 'T'), // STARTUP in BBR for 2 RTTs + XQC_CO_BBR4 = XQC_CO_TAG('B', 'B', 'R', '4'), // 20 RTT ack aggregation + XQC_CO_BBR5 = XQC_CO_TAG('B', 'B', 'R', '5'), // 40 RTT ack aggregation + XQC_CO_IW03 = XQC_CO_TAG('I', 'W', '0', '3'), // Force ICWND to 3 + XQC_CO_IW10 = XQC_CO_TAG('I', 'W', '1', '0'), // Force ICWND to 10 + XQC_CO_IW20 = XQC_CO_TAG('I', 'W', '2', '0'), // Force ICWND to 20 + XQC_CO_IW50 = XQC_CO_TAG('I', 'W', '5', '0'), // Force ICWND to 50 + XQC_CO_B2ON = XQC_CO_TAG('B', '2', 'O', 'N'), // Enable BBRv2 + XQC_CO_COPA = XQC_CO_TAG('C', 'O', 'P', 'A'), // Enable COPA + XQC_CO_C2ON = XQC_CO_TAG('C', '2', 'O', 'N'), // Enable CopaV2 + XQC_CO_QBIC = XQC_CO_TAG('Q', 'B', 'I', 'C'), // TCP Cubic + XQC_CO_RENO = XQC_CO_TAG('R', 'E', 'N', 'O'), // Enable reno + XQC_CO_SPRI = XQC_CO_TAG('S', 'P', 'R', 'I'), // enable stream priority by streamid + XQC_CO_9218 = XQC_CO_TAG('9', '2', '1', '8'), // enable stream priority by rfc9218 + XQC_CO_D218 = XQC_CO_TAG('D', '2', '1', '8'), // disable rfc9218 + XQC_CO_DRST = XQC_CO_TAG('D', 'R', 'S', 'T'), // disable cease sending stream + XQC_CO_CBBR = XQC_CO_TAG('C', 'B', 'B', 'R'), // A global option to enable all the following options (Customized BBR) + XQC_CO_BNLS = XQC_CO_TAG('B', 'N', 'L', 'S'), // Force BBR not to respond on losses during STARTUP + XQC_CO_BACG = XQC_CO_TAG('B', 'A', 'C', 'G'), // Use Adaptive CWND_GAIN in BBR + XQC_CO_CG03 = XQC_CO_TAG('C', 'G', '0', '3'), // Use 3 for CWND_GAIN in BBR + XQC_CO_CG05 = XQC_CO_TAG('C', 'G', '0', '5'), // Use 5 for CWND_GAIN in BBR + XQC_CO_CG10 = XQC_CO_TAG('C', 'G', '1', '0'), // Use 10 for CWND_GAIN in BBR + XQC_CO_CG20 = XQC_CO_TAG('C', 'G', '2', '0'), // Use 20 for CWND_GAIN in BBR + XQC_CO_PG11 = XQC_CO_TAG('P', 'G', '1', '1'), // Use 1.1 for PACING_GAIN in BBR PROBE_UP + XQC_CO_PG15 = XQC_CO_TAG('P', 'G', '1', '5'), // Use 1.5 for PACING_GAIN in BBR PROBE_UP + XQC_CO_BNLR = XQC_CO_TAG('B', 'N', 'L', 'R'), // Disable BBR's loss recovery state + XQC_CO_MW10 = XQC_CO_TAG('M', 'W', '1', '0'), // Set min CWND to 10 + XQC_CO_MW20 = XQC_CO_TAG('M', 'W', '2', '0'), // Set min CWND to 20 + XQC_CO_MW32 = XQC_CO_TAG('M', 'W', '3', '2'), // Set min CWND to 32 + XQC_CO_MW50 = XQC_CO_TAG('M', 'W', '5', '0'), // Set min CWND to 50 + XQC_CO_WL20 = XQC_CO_TAG('W', 'L', '2', '0'), // Set BW window length to 20 (RTTs) + XQC_CO_WL30 = XQC_CO_TAG('W', 'L', '3', '0'), // Set BW window length to 30 (RTTs) + XQC_CO_WL40 = XQC_CO_TAG('W', 'L', '4', '0'), // Set BW window length to 40 (RTTs) + XQC_CO_WL50 = XQC_CO_TAG('W', 'L', '5', '0'), // Set BW window length to 50 (RTTs) + XQC_CO_PR02 = XQC_CO_TAG('P', 'R', '0', '2'), // Set the target CWND in ProbeRTT to 0.2xBDP + XQC_CO_PR03 = XQC_CO_TAG('P', 'R', '0', '3'), // Set the target CWND in ProbeRTT to 0.3xBDP + XQC_CO_PR04 = XQC_CO_TAG('P', 'R', '0', '4'), // Set the target CWND in ProbeRTT to 0.4xBDP + XQC_CO_PR05 = XQC_CO_TAG('P', 'R', '0', '5'), // Set the target CWND in ProbeRTT to 0.5xBDP + XQC_CO_PR06 = XQC_CO_TAG('P', 'R', '0', '6'), // Set the target CWND in ProbeRTT to 0.6xBDP + XQC_CO_PR07 = XQC_CO_TAG('P', 'R', '0', '7'), // Set the target CWND in ProbeRTT to 0.7xBDP + XQC_CO_ENWC = XQC_CO_TAG('E', 'N', 'W', 'C'), // Enable CWND compensation according to jitter + XQC_CO_JW10 = XQC_CO_TAG('J', 'W', '1', '0'), // Set the window length of max jitter filter to 10xRTT (default) + XQC_CO_JW20 = XQC_CO_TAG('J', 'W', '2', '0'), // Set the window length of max jitter filter to 20xRTT + XQC_CO_JW30 = XQC_CO_TAG('J', 'W', '3', '0'), // Set the window length of max jitter filter to 30xRTT + XQC_CO_JW40 = XQC_CO_TAG('J', 'W', '4', '0'), // Set the window length of max jitter filter to 40xRTT + XQC_CO_JW50 = XQC_CO_TAG('J', 'W', '5', '0'), // Set the window length of max jitter filter to 50xRTT + XQC_CO_SL03 = XQC_CO_TAG('S', 'L', '0', '3'), // Set the STARTUP loss rate threshold to 0.03 + XQC_CO_SL04 = XQC_CO_TAG('S', 'L', '0', '4'), // Set the STARTUP loss rate threshold to 0.04 + XQC_CO_SL05 = XQC_CO_TAG('S', 'L', '0', '5'), // Set the STARTUP loss rate threshold to 0.05 + XQC_CO_SL10 = XQC_CO_TAG('S', 'L', '1', '0'), // Set the STARTUP loss rate threshold to 0.05 +} xqc_conn_option_t; + #endif /*_XQUIC_TYPEDEF_H_INCLUDED_*/ diff --git a/scripts/case_test.sh b/scripts/case_test.sh index 22dcd333c..f93ae843a 100755 --- a/scripts/case_test.sh +++ b/scripts/case_test.sh @@ -723,6 +723,22 @@ fi grep_err_log +clear_log +echo -e "empty header value ...\c" +${CLIENT_BIN} -x 47 -1 -n 10 >> stdlog +result=`grep -E "test_result_speed:.*request_cnt: 10." stdlog` +errlog=`grep_err_log` +if [ -n "$result" ] && [ -z "$errlog" ]; then + echo ">>>>>>>> pass:1" + case_print_result "empty_header_value" "pass" +else + echo ">>>>>>>> pass:0" + case_print_result "empty_header_value" "fail" + exit 1 +fi +grep_err_log + + clear_log rm -f test_session echo -e "NULL stream callback ...\c" @@ -819,7 +835,7 @@ grep_err_log|grep -v xqc_h3_stream_send_headers clear_log echo -e "send 1K data ...\c" -result=`${CLIENT_BIN} -s 1024 -l d -t 1 -E|grep ">>>>>>>> pass"` +result=`${CLIENT_BIN} -s 1024 -l d -t 1 -E --conn_options CBBR|grep ">>>>>>>> pass"` errlog=`grep_err_log` echo "$result" if [ -z "$errlog" ] && [ "$result" == ">>>>>>>> pass:1" ]; then @@ -4126,13 +4142,11 @@ rm -rf tp_localhost test_session xqc_token clear_log echo -e "freeze path0 ...\c" sudo ${CLIENT_BIN} -s 1024000 -l d -E -e 4 -T 2 --epoch_timeout 2000000 -t 4 -M -i lo -i lo -x 107 > stdlog -stream_info3=`grep "stream_info:" stdlog | head -n 3 | tail -n 1 | grep -v "#0" | grep "#1"` -stream_info5=`grep "stream_info:" stdlog | tail -n 1 | grep -E "#0.*#1"` clog_res1=`grep -E "path:0.*app_path_status:2->3" clog` clog_res2=`grep -E "path:0.*app_path_status:3->1" clog` slog_res1=`grep -E "path:0.*app_path_status:2->3" slog` slog_res2=`grep -E "path:0.*app_path_status:3->1" slog` -if [ -n "$stream_info3" ] && [ -n "$stream_info5" ] && [ -n "$clog_res1" ] && [ -n "$clog_res2" ] && [ -n "$slog_res1" ] && [ -n "$slog_res2" ] ; then +if [ -n "$clog_res1" ] && [ -n "$clog_res2" ] && [ -n "$slog_res1" ] && [ -n "$slog_res2" ] ; then echo ">>>>>>>> pass:1" case_print_result "freeze_path0" "pass" else @@ -4144,13 +4158,11 @@ rm -rf tp_localhost test_session xqc_token clear_log echo -e "freeze path1 ...\c" sudo ${CLIENT_BIN} -s 1024000 -l d -E -e 4 -T 2 --epoch_timeout 2000000 -t 4 -M -i lo -i lo -x 108 > stdlog -stream_info3=`grep "stream_info:" stdlog | head -n 3 | tail -n 1 | grep -v "#1" | grep "#0"` -stream_info5=`grep "stream_info:" stdlog | tail -n 1 | grep -E "#0.*#1"` clog_res1=`grep -E "path:1.*app_path_status:2->3" clog` clog_res2=`grep -E "path:1.*app_path_status:3->1" clog` slog_res1=`grep -E "path:1.*app_path_status:2->3" slog` slog_res2=`grep -E "path:1.*app_path_status:3->1" slog` -if [ -n "$stream_info3" ] && [ -n "$stream_info5" ] && [ -n "$clog_res1" ] && [ -n "$clog_res2" ] && [ -n "$slog_res1" ] && [ -n "$slog_res2" ] ; then +if [ -n "$clog_res1" ] && [ -n "$clog_res2" ] && [ -n "$slog_res1" ] && [ -n "$slog_res2" ] ; then echo ">>>>>>>> pass:1" case_print_result "freeze_path1" "pass" else diff --git a/src/common/utils/ringmem/xqc_ring_mem.c b/src/common/utils/ringmem/xqc_ring_mem.c index 4ab6921f2..9fa4b85bd 100644 --- a/src/common/utils/ringmem/xqc_ring_mem.c +++ b/src/common/utils/ringmem/xqc_ring_mem.c @@ -267,7 +267,7 @@ xqc_ring_mem_undo(xqc_ring_mem_t *rmem, xqc_ring_mem_idx_t idx, size_t len) int xqc_ring_mem_cmp(xqc_ring_mem_t *rmem, xqc_ring_mem_idx_t idx, uint8_t *data, size_t len) { - if (idx < rmem->sidx || idx + len > rmem->eidx) { + if (idx < rmem->sidx || idx + len > rmem->eidx || len == 0) { return -XQC_EPARAM; } diff --git a/src/common/xqc_algorithm.h b/src/common/xqc_algorithm.h index 9474f9324..15e270b1d 100644 --- a/src/common/xqc_algorithm.h +++ b/src/common/xqc_algorithm.h @@ -20,4 +20,16 @@ xqc_uint32_list_find(const uint32_t *list, size_t count, uint32_t target) return -1; } +static inline uint64_t +xqc_uint64_bounded_subtract(uint64_t a, uint64_t b) +{ + return a > b ? a - b : 0; +} + +static inline uint32_t +xqc_uint32_bounded_subtract(uint32_t a, uint32_t b) +{ + return a > b ? a - b : 0; +} + #endif /* XQC_ALGORITHM_H_INCLUDED */ diff --git a/src/common/xqc_str.h b/src/common/xqc_str.h index 609f89c23..a289be337 100644 --- a/src/common/xqc_str.h +++ b/src/common/xqc_str.h @@ -95,5 +95,16 @@ xqc_memeq(const void *s1, const void *s2, size_t n) return n == 0 || memcmp(s1, s2, n) == 0; } +inline static xqc_bool_t +xqc_char_is_letter_or_number(char c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9')) + { + return XQC_TRUE; + } + return XQC_FALSE; +} + #endif /*_XQC_STR_H_INCLUDED_*/ diff --git a/src/congestion_control/xqc_bbr.c b/src/congestion_control/xqc_bbr.c index 577c35763..928801882 100644 --- a/src/congestion_control/xqc_bbr.c +++ b/src/congestion_control/xqc_bbr.c @@ -263,7 +263,7 @@ xqc_bbr_init(void *cong_ctl, xqc_sample_t *sampler, xqc_cc_params_t cc_params) bbr->packet_conservation = FALSE; bbr->prior_cwnd = 0; bbr->initial_congestion_window = XQC_BBR_INITIAL_WINDOW; - bbr->congestion_window = bbr->initial_congestion_window; + bbr->min_cwnd = xqc_bbr_min_cwnd; bbr->has_srtt = 0; bbr->idle_restart = 0; bbr->packet_conservation = 0; @@ -286,10 +286,14 @@ xqc_bbr_init(void *cong_ctl, xqc_sample_t *sampler, xqc_cc_params_t cc_params) if (cc_params.customize_on) { cc_params.init_cwnd *= XQC_BBR_MAX_DATAGRAMSIZE; + cc_params.min_cwnd *= XQC_BBR_MAX_DATAGRAMSIZE; bbr->initial_congestion_window = cc_params.init_cwnd >= XQC_BBR_MIN_WINDOW && cc_params.init_cwnd <= XQC_BBR_MAX_WINDOW ? cc_params.init_cwnd : XQC_BBR_INITIAL_WINDOW; + bbr->min_cwnd = cc_params.min_cwnd >= XQC_BBR_MIN_WINDOW + && cc_params.min_cwnd <= XQC_BBR_MAX_WINDOW + ? cc_params.min_cwnd : xqc_bbr_min_cwnd; if (cc_params.expect_bw > 0) { bbr->enable_expect_bw = TRUE; @@ -304,8 +308,8 @@ xqc_bbr_init(void *cong_ctl, xqc_sample_t *sampler, xqc_cc_params_t cc_params) } } + bbr->congestion_window = bbr->initial_congestion_window; xqc_bbr_reset_lt_bw_sampling(bbr); - xqc_bbr_enter_startup(bbr); xqc_bbr_init_pacing_rate(bbr, sampler); } @@ -409,7 +413,7 @@ xqc_bbr_target_cwnd(xqc_bbr_t *bbr, float gain, uint64_t bw) return bbr->initial_congestion_window; } uint32_t cwnd = gain * xqc_bbr_bdp(bbr, bw); - return xqc_max(cwnd, XQC_BBR_MIN_WINDOW); + return xqc_max(cwnd, bbr->min_cwnd); } static bool @@ -646,10 +650,10 @@ static uint32_t xqc_bbr_probe_rtt_cwnd(xqc_bbr_t *bbr) { if (xqc_bbr_probe_rtt_gain == 0) { - return xqc_bbr_min_cwnd; + return bbr->min_cwnd; } - return xqc_max(xqc_bbr_min_cwnd, + return xqc_max(bbr->min_cwnd, xqc_bbr_target_cwnd(bbr, xqc_bbr_probe_rtt_gain, xqc_bbr_max_bw(bbr))); @@ -844,7 +848,7 @@ xqc_bbr_reset_cwnd(void *cong_ctl) xqc_bbr_t *bbr = (xqc_bbr_t *)cong_ctl; xqc_bbr_save_cwnd(bbr); /* reduce cwnd to the minimal value */ - bbr->congestion_window = XQC_BBR_MIN_WINDOW; + bbr->congestion_window = bbr->min_cwnd; /* cancel recovery state */ if (bbr->recovery_mode == BBR_IN_RECOVERY) { bbr->recovery_mode = BBR_NOT_IN_RECOVERY; @@ -950,7 +954,7 @@ xqc_bbr_set_cwnd(xqc_bbr_t *bbr, xqc_sample_t *sampler) bbr->congestion_window += sampler->acked; } } - bbr->congestion_window = xqc_max(bbr->congestion_window, xqc_bbr_min_cwnd); + bbr->congestion_window = xqc_max(bbr->congestion_window, bbr->min_cwnd); } if (bbr->mode == BBR_PROBE_RTT) { bbr->congestion_window = xqc_min(bbr->congestion_window, @@ -1070,8 +1074,9 @@ static uint32_t xqc_bbr_get_pacing_rate(void *cong_ctl) { xqc_bbr_t *bbr = (xqc_bbr_t *)(cong_ctl); - - return bbr->pacing_rate; + xqc_usec_t min_rtt = (bbr->min_rtt && (bbr->min_rtt != XQC_BBR_INF) ? bbr->min_rtt : 10000); + uint32_t min_pacing_rate = bbr->min_cwnd * (uint64_t)MSEC2SEC / min_rtt; + return xqc_max(bbr->pacing_rate, bbr->pacing_gain * min_pacing_rate); } static uint32_t diff --git a/src/congestion_control/xqc_bbr.h b/src/congestion_control/xqc_bbr.h index debc132ef..fdc55e989 100644 --- a/src/congestion_control/xqc_bbr.h +++ b/src/congestion_control/xqc_bbr.h @@ -62,6 +62,7 @@ typedef struct xqc_bbr_s { uint32_t prior_cwnd; /* Initial congestion window of connection */ uint32_t initial_congestion_window; + uint32_t min_cwnd; /* Current pacing rate */ uint32_t pacing_rate; /* Gain currently applied to pacing rate */ diff --git a/src/congestion_control/xqc_copa.c b/src/congestion_control/xqc_copa.c index 0f6a96dcc..0301bd846 100644 --- a/src/congestion_control/xqc_copa.c +++ b/src/congestion_control/xqc_copa.c @@ -62,6 +62,7 @@ xqc_copa_set_pacing_rate(xqc_copa_t *copa) { /* 2*cwnd / rtt_standing */ xqc_usec_t rtt_standing = xqc_win_filter_get(&copa->rtt_standing); + xqc_usec_t initial_rtt = copa->ctl_ctx->ctl_conn->conn_settings.initial_rtt; if (rtt_standing == XQC_COPA_INF_U64) { /* initialization */ rtt_standing = copa->ctl_ctx->ctl_srtt; @@ -70,7 +71,7 @@ xqc_copa_set_pacing_rate(xqc_copa_t *copa) xqc_log(copa->ctl_ctx->ctl_conn->log, XQC_LOG_WARN, "|copa|rtt_standing_error:%ui|", rtt_standing); /* initialization */ - rtt_standing = XQC_kInitialRtt * 1000; + rtt_standing = initial_rtt; xqc_win_filter_reset(&copa->rtt_standing, 0, XQC_COPA_INF_U64); } copa->pacing_rate = ((copa->cwnd_bytes) * XQC_COPA_USEC2SEC) << 1; diff --git a/src/congestion_control/xqc_cubic.c b/src/congestion_control/xqc_cubic.c index d9307d2a5..66e81fe61 100644 --- a/src/congestion_control/xqc_cubic.c +++ b/src/congestion_control/xqc_cubic.c @@ -121,13 +121,7 @@ static void xqc_cubic_init(void *cong_ctl, xqc_send_ctl_t *ctl_ctx, xqc_cc_params_t cc_params) { xqc_cubic_t *cubic = (xqc_cubic_t *)(cong_ctl); - cubic->epoch_start = 0; - cubic->cwnd = XQC_CUBIC_INIT_WIN; - cubic->tcp_cwnd = XQC_CUBIC_INIT_WIN; - cubic->tcp_cwnd_cnt = 0; - cubic->last_max_cwnd = XQC_CUBIC_INIT_WIN; - cubic->ssthresh = XQC_CUBIC_MAX_SSTHRESH; - cubic->congestion_recovery_start_time = 0; + cubic->init_cwnd = XQC_CUBIC_INIT_WIN; cubic->min_cwnd = XQC_CUBIC_MIN_WIN; @@ -141,6 +135,14 @@ xqc_cubic_init(void *cong_ctl, xqc_send_ctl_t *ctl_ctx, xqc_cc_params_t cc_param cc_params.min_cwnd >= XQC_CUBIC_MIN_WIN && cc_params.min_cwnd <= XQC_CUBIC_MAX_MIN_WIN ? cc_params.min_cwnd : XQC_CUBIC_MIN_WIN; } + + cubic->epoch_start = 0; + cubic->cwnd = cubic->init_cwnd; + cubic->tcp_cwnd = cubic->init_cwnd; + cubic->tcp_cwnd_cnt = 0; + cubic->last_max_cwnd = cubic->init_cwnd; + cubic->ssthresh = XQC_CUBIC_MAX_SSTHRESH; + cubic->congestion_recovery_start_time = 0; } diff --git a/src/http3/xqc_h3_request.c b/src/http3/xqc_h3_request.c index dbedabde9..d48cdcba8 100644 --- a/src/http3/xqc_h3_request.c +++ b/src/http3/xqc_h3_request.c @@ -279,6 +279,13 @@ xqc_h3_request_get_stats(xqc_h3_request_t *h3_request) stats.recv_hdr_compressed = h3_request->compressed_header_recvd; stats.rate_limit = h3_request->h3_stream->recv_rate_limit; + /* try to update early data state */ + if (h3_request->h3_stream->stream) { + xqc_h3_stream_update_early_data_state(h3_request->h3_stream); + } + + stats.early_data_state = h3_request->h3_stream->early_data_state; + xqc_h3_stream_get_path_info(h3_request->h3_stream); xqc_request_path_metrics_print(h3_request->h3_stream->h3c->conn, h3_request->h3_stream, &stats); @@ -620,8 +627,18 @@ xqc_h3_request_on_recv_header(xqc_h3_request_t *h3r) XQC_REQ_NOTIFY_READ_TRAILER }; + xqc_int_t ret; xqc_http_headers_t *headers; + if (h3r->current_header == 1) { + /* notify data before trailer headers*/ + ret = xqc_h3_request_on_recv_body(h3r); + if (ret != XQC_OK) { + xqc_log(h3r->h3_stream->log, XQC_LOG_ERROR, "|xqc_h3_request_on_recv_body error|%d|", ret); + return ret; + } + } + /* header section and trailer section are all processed */ if (h3r->current_header >= XQC_H3_REQUEST_MAX_HEADERS_CNT) { xqc_log(h3r->h3_stream->log, XQC_LOG_WARN, "|headers count exceed 2|" @@ -653,7 +670,7 @@ xqc_h3_request_on_recv_header(xqc_h3_request_t *h3r) h3r->current_header++; /* header notify callback */ - xqc_int_t ret = h3r->request_if->h3_request_read_notify(h3r, h3r->read_flag, h3r->user_data); + ret = h3r->request_if->h3_request_read_notify(h3r, h3r->read_flag, h3r->user_data); if (ret < 0) { xqc_log(h3r->h3_stream->log, XQC_LOG_ERROR, "|h3_request_read_notify error|%d|" "stream_id:%ui|conn:%p|", ret, h3r->h3_stream->stream_id, @@ -667,12 +684,10 @@ xqc_h3_request_on_recv_header(xqc_h3_request_t *h3r) xqc_int_t xqc_h3_request_on_recv_body(xqc_h3_request_t *h3r) { - /* there might be a fin only operation, which shall be notified to user */ - if (!xqc_list_empty(&h3r->body_buf) || (h3r->fin_flag == XQC_TRUE)) { + /* Note, the case of empty fin is already handled at another place. */ + if (!xqc_list_empty(&h3r->body_buf)) { - if (!xqc_list_empty(&h3r->body_buf)) { - h3r->read_flag |= XQC_REQ_NOTIFY_READ_BODY; - } + h3r->read_flag |= XQC_REQ_NOTIFY_READ_BODY; xqc_int_t ret = h3r->request_if->h3_request_read_notify(h3r, h3r->read_flag, h3r->user_data); if (ret < 0) { diff --git a/src/http3/xqc_h3_stream.c b/src/http3/xqc_h3_stream.c index 3e91f5109..ce9e8ad34 100644 --- a/src/http3/xqc_h3_stream.c +++ b/src/http3/xqc_h3_stream.c @@ -1014,17 +1014,6 @@ xqc_h3_stream_process_request(xqc_h3_stream_t *h3s, unsigned char *data, size_t if (fin_flag && processed == data_len) { h3s->h3r->fin_flag = fin_flag; } - - /* - * when all bytes of DATA frame is read, notify to - * application to make sure it is notified before Trailer - */ - ret = xqc_h3_request_on_recv_body(h3s->h3r); - if (ret != XQC_OK) { - xqc_log(h3s->log, XQC_LOG_ERROR, "|recv body error|%d|", ret); - return ret; - } - xqc_log(h3s->log, XQC_LOG_DEBUG, "|notify body on DATA frame end"); } break; @@ -1656,6 +1645,7 @@ xqc_h3_stream_process_data(xqc_stream_t *stream, xqc_h3_stream_t *h3s, xqc_bool_ xqc_h3_request_stream_fin(h3s->h3r); h3s->send_offset = h3s->stream->stream_send_offset; h3s->recv_offset = h3s->stream->stream_data_in.merged_offset_end; + xqc_h3_stream_update_early_data_state(h3s); } } @@ -1891,6 +1881,18 @@ xqc_h3_stream_read_notify(xqc_stream_t *stream, void *user_data) return XQC_OK; } +void +xqc_h3_stream_update_early_data_state(xqc_h3_stream_t *h3s) +{ + if (h3s->stream->stream_flag & XQC_STREAM_FLAG_HAS_0RTT) { + if (h3s->h3c->conn->conn_flag & XQC_CONN_FLAG_0RTT_OK) { + h3s->early_data_state = 1; + + } else { + h3s->early_data_state = 2; + } + } +} int xqc_h3_stream_close_notify(xqc_stream_t *stream, void *user_data) @@ -1912,6 +1914,7 @@ xqc_h3_stream_close_notify(xqc_stream_t *stream, void *user_data) h3s->h3r->stream_close_msg = h3s->stream->stream_close_msg; h3s->send_offset = h3s->stream->stream_send_offset; h3s->recv_offset = h3s->stream->stream_data_in.merged_offset_end; + xqc_h3_stream_update_early_data_state(h3s); } if (h3s->h3_ext_bs && h3s->type == XQC_H3_STREAM_TYPE_BYTESTEAM) { diff --git a/src/http3/xqc_h3_stream.h b/src/http3/xqc_h3_stream.h index dc4526446..f097391c6 100644 --- a/src/http3/xqc_h3_stream.h +++ b/src/http3/xqc_h3_stream.h @@ -151,12 +151,16 @@ typedef struct xqc_h3_stream_s { uint64_t send_offset; uint64_t recv_offset; + uint8_t early_data_state; + } xqc_h3_stream_t; /* transport layer callback hook */ extern const xqc_stream_callbacks_t h3_stream_callbacks; +void xqc_h3_stream_update_early_data_state(xqc_h3_stream_t *h3s); + xqc_h3_stream_t *xqc_h3_stream_create(xqc_h3_conn_t *h3c, xqc_stream_t *stream, xqc_h3_stream_type_t type, void *user_data); diff --git a/src/tls/xqc_tls.c b/src/tls/xqc_tls.c index 5f1f20078..3b68679c7 100644 --- a/src/tls/xqc_tls.c +++ b/src/tls/xqc_tls.c @@ -1063,7 +1063,7 @@ xqc_ssl_cert_cb(SSL *ssl, void *arg) hostname = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (NULL == hostname) { - xqc_log(tls->log, XQC_LOG_ERROR, "hostname is NULL"); + xqc_log(tls->log, XQC_LOG_ERROR, "|hostname is NULL"); return XQC_SSL_FAIL; } diff --git a/src/transport/xqc_conn.c b/src/transport/xqc_conn.c index 0bcee5af2..0f3dace0d 100644 --- a/src/transport/xqc_conn.c +++ b/src/transport/xqc_conn.c @@ -121,6 +121,8 @@ xqc_server_set_conn_settings(const xqc_conn_settings_t *settings) default_conn_settings.recv_rate_bytes_per_sec = settings->recv_rate_bytes_per_sec; default_conn_settings.enable_stream_rate_limit = settings->enable_stream_rate_limit; default_conn_settings.init_recv_window = settings->init_recv_window; + default_conn_settings.initial_rtt = settings->initial_rtt; + default_conn_settings.initial_pto_duration = settings->initial_pto_duration; #ifdef XQC_PROTECT_POOL_MEM default_conn_settings.protect_pool_mem = settings->protect_pool_mem; #endif @@ -336,6 +338,9 @@ xqc_conn_init_trans_settings(xqc_connection_t *conn) /* set local and remote settings to default */ xqc_trans_settings_t *ls = &conn->local_settings; xqc_trans_settings_t *rs = &conn->remote_settings; + uint32_t i, co_bytes; + char *co_str = conn->conn_settings.conn_option_str; + xqc_conn_set_default_settings(ls); xqc_conn_set_default_settings(rs); @@ -388,6 +393,30 @@ xqc_conn_init_trans_settings(xqc_connection_t *conn) ls->disable_active_migration = ls->enable_multipath ? 0 : 1; ls->max_ack_delay = conn->conn_settings.max_ack_delay; + + /* init local conn options */ + for (i = 0, co_bytes = 0; i < XQC_CO_STR_MAX_LEN; i++) { + if (co_bytes == 4) { + if ((co_str[i] != ',' && co_str[i] != '\0')) { + // invalid CO. Stop decoding. + break; + + } else { + ls->conn_options[ls->conn_option_num++] = XQC_CO_TAG(co_str[i - 4], co_str[i - 3], co_str[i - 2], co_str[i - 1]); + } + + co_bytes = 0; + + } else { + if (xqc_char_is_letter_or_number(co_str[i])) { + co_bytes++; + + } else { + // invalid CO. Stop decoding. + break; + } + } + } } @@ -505,8 +534,13 @@ xqc_conn_create(xqc_engine_t *engine, xqc_cid_t *dcid, xqc_cid_t *scid, xc->conn_settings = *settings; + xqc_memcpy(xc->conn_settings.conn_option_str, settings->conn_option_str, XQC_CO_STR_MAX_LEN); xqc_conn_set_default_sched_params(&xc->conn_settings); + if (xc->conn_settings.initial_rtt == 0) { + xc->conn_settings.initial_rtt = XQC_kInitialRtt_us; + } + if (xc->conn_settings.max_ack_delay == 0) { xc->conn_settings.max_ack_delay = XQC_DEFAULT_MAX_ACK_DELAY; } @@ -1061,7 +1095,7 @@ xqc_conn_destroy(xqc_connection_t *xc) "first_send_delay:%ui|conn_persist:%ui|keyupdate_cnt:%d|err:0x%xi|close_msg:%s|%s|" "hsk_recv:%ui|close_recv:%ui|close_send:%ui|last_recv:%ui|last_send:%ui|" "mp_enable:%ud|create:%ud|validated:%ud|active:%ud|path_info:%s|alpn:%*s|rebind_count:%d|" - "rebind_valid:%d|", + "rebind_valid:%d|rtx_pkt:%ud|tlp_pkt:%ud|snd_pkt:%ud|spurious_loss:%ud|detected_loss:%ud|", xc, xc->conn_flag & XQC_CONN_FLAG_HAS_0RTT ? 1:0, xc->conn_flag & XQC_CONN_FLAG_0RTT_OK ? 1:0, @@ -1077,7 +1111,8 @@ xqc_conn_destroy(xqc_connection_t *xc) xqc_calc_delay(xc->conn_last_send_time, xc->conn_create_time), xc->enable_multipath, xc->create_path_count, xc->validated_path_count, xc->active_path_count, conn_stats.conn_info, out_alpn_len, out_alpn, conn_stats.total_rebind_count, - conn_stats.total_rebind_valid); + conn_stats.total_rebind_valid, conn_stats.lost_count, conn_stats.tlp_count, + conn_stats.send_count, conn_stats.spurious_loss_count, xc->detected_loss_cnt); xqc_log_event(xc->log, CON_CONNECTION_CLOSED, xc); if (xc->conn_flag & XQC_CONN_FLAG_WAIT_WAKEUP) { @@ -1226,19 +1261,27 @@ xqc_conn_get_local_addr(xqc_connection_t *conn, struct sockaddr *addr, socklen_t xqc_int_t xqc_conn_send_ping_internal(xqc_connection_t *conn, void *ping_user_data, xqc_bool_t notify) { - xqc_int_t ret = XQC_OK; + xqc_int_t ret; + xqc_path_ctx_t *path; + xqc_list_head_t *pos, *next; + xqc_bool_t has_ping; + xqc_ping_record_t *pr; + + ret = XQC_OK; if (conn->conn_state >= XQC_CONN_STATE_CLOSING) { return ret; } - if (conn->enable_multipath && conn->conn_settings.mp_ping_on) { + pr = xqc_conn_create_ping_record(conn); - xqc_path_ctx_t *path; - xqc_list_head_t *pos, *next; - xqc_bool_t has_ping = XQC_FALSE; - xqc_ping_record_t *pr = xqc_conn_create_ping_record(conn); + if (pr == NULL) { + return -XQC_EMALLOC; + } + has_ping = XQC_FALSE; + + if (conn->enable_multipath && conn->conn_settings.mp_ping_on) { xqc_list_for_each_safe(pos, next, &conn->conn_paths_list) { path = xqc_list_entry(pos, xqc_path_ctx_t, path_list); if (path->path_state == XQC_PATH_STATE_ACTIVE) { @@ -1252,19 +1295,21 @@ xqc_conn_send_ping_internal(xqc_connection_t *conn, void *ping_user_data, xqc_bo } } - if (!has_ping) { - xqc_conn_destroy_ping_record(pr); - return ret; - } - } else { - ret = xqc_write_ping_to_packet(conn, NULL, ping_user_data, notify, NULL); + ret = xqc_write_ping_to_packet(conn, NULL, ping_user_data, notify, pr); if (ret < 0) { xqc_log(conn->log, XQC_LOG_ERROR, "|write ping error|"); - return ret; + + } else { + has_ping = XQC_TRUE; } } + if (!has_ping) { + xqc_conn_destroy_ping_record(pr); + return ret; + } + return XQC_OK; } @@ -2320,6 +2365,10 @@ xqc_conn_send_probe_pkt(xqc_connection_t *c, xqc_path_ctx_t *path, } } + if (packet_out->po_flag & XQC_POF_IN_FLIGHT) { + c->detected_loss_cnt++; + } + xqc_send_ctl_decrease_inflight(c, packet_out); xqc_send_queue_copy_to_probe(packet_out, c->conn_send_queue, path); @@ -2383,6 +2432,7 @@ xqc_path_send_one_or_two_ack_elicit_pkts(xqc_path_ctx_t *path, if (XQC_IS_ACK_ELICITING(packet_out->po_frame_types) && (XQC_NEED_REPAIR(packet_out->po_frame_types) + || (packet_out->po_flag & XQC_POF_NOTIFY) || (packet_out->po_frame_types & XQC_FRAME_BIT_DATAGRAM && c->conn_settings.datagram_force_retrans_on))) { @@ -2857,12 +2907,15 @@ xqc_conn_info_print(xqc_connection_t *conn, xqc_conn_stats_t *conn_stats) xqc_path_info_t path_info; char mp_settings[XQC_MP_SETTINGS_STR_LEN] = {0}; uint32_t sock_err_flag = 0; + uint32_t init_cwnd = 0; xqc_conn_encode_mp_settings(conn, mp_settings, XQC_MP_SETTINGS_STR_LEN); + init_cwnd = conn->conn_settings.cc_params.customize_on ? conn->conn_settings.cc_params.init_cwnd : 0; + /* conn info */ ret = snprintf(buff, buff_size, "%s,%u,%u,%u,%u,%u,%u," - "%u,%u,%u,%u,%u,%u,%u,%"PRIu64",%"PRIu64",%"PRIu64",", + "%u,%u,%u,%u,%u,%u,%u,%"PRIu64",%"PRIu64",%"PRIu64",i%u,", mp_settings, conn->create_path_count, conn->validated_path_count, @@ -2879,7 +2932,8 @@ xqc_conn_info_print(xqc_connection_t *conn, xqc_conn_stats_t *conn_stats) conn->rcv_pkt_stats.conn_udp_pkts, conn->stream_stats.send_bytes, conn->stream_stats.reinjected_bytes, - conn->stream_stats.recv_bytes); + conn->stream_stats.recv_bytes, + init_cwnd); curr_size += ret; @@ -3018,7 +3072,7 @@ xqc_conn_get_stats_internal(xqc_connection_t *conn, xqc_conn_stats_t *conn_stats && conn->conn_initial_path->path_send_ctl && conn->conn_initial_path->path_pn_ctl) { - if (conn_stats->min_rtt == XQC_MAX_UINT32_VALUE) { + if (conn->conn_initial_path->path_send_ctl->ctl_first_rtt_sample_time == 0) { conn_stats->srtt = 0; conn_stats->min_rtt = 0; @@ -3089,6 +3143,55 @@ xqc_conn_get_stats(xqc_engine_t *engine, const xqc_cid_t *cid) return conn_stats; } +xqc_conn_qos_stats_t +xqc_conn_get_qos_stats(xqc_engine_t *engine, const xqc_cid_t *cid) +{ + xqc_connection_t *conn; + xqc_conn_qos_stats_t qos_stats; + xqc_memzero(&qos_stats, sizeof(qos_stats)); + + conn = xqc_engine_conns_hash_find(engine, cid, 's'); + if (!conn) { + xqc_log(engine->log, XQC_LOG_ERROR, "|can not find connection|cid:%s", + xqc_scid_str(cid)); + return qos_stats; + } + + /* 2. srtt 和 ack_info 使用主路信息 (TODO: 有问题,后续需要修改) */ + if (conn->conn_initial_path + && conn->conn_initial_path->path_send_ctl + && conn->conn_initial_path->path_pn_ctl) + { + if (conn->conn_initial_path->path_send_ctl->ctl_first_rtt_sample_time == 0) { + qos_stats.srtt = 0; + qos_stats.min_rtt = 0; + + } else { + qos_stats.srtt = conn->conn_initial_path->path_send_ctl->ctl_srtt; + qos_stats.min_rtt = conn->conn_initial_path->path_send_ctl->ctl_minrtt; + } + } + + xqc_list_head_t *pos, *next; + xqc_path_ctx_t *path = NULL; + xqc_send_ctl_t *send_ctl; + xqc_list_for_each_safe(pos, next, &conn->conn_paths_list) { + path = xqc_list_entry(pos, xqc_path_ctx_t, path_list); + if (path == NULL) { + continue; + } + + send_ctl = path->path_send_ctl; + if (send_ctl == NULL) { + continue; + } + + qos_stats.inflight_bytes += send_ctl->ctl_bytes_in_flight; + } + + return qos_stats; +} + xqc_usec_t xqc_conn_get_lastest_rtt(xqc_engine_t *engine, const xqc_cid_t *cid) @@ -3501,11 +3604,7 @@ xqc_conn_process_undecrypt_packet_in(xqc_connection_t *conn, xqc_encrypt_level_t packet_in = xqc_list_entry(pos, xqc_packet_in_t, pi_list); xqc_log(conn->log, XQC_LOG_DEBUG, "|delay|undecrypt_count:%ud|encrypt_level:%d|", conn->undecrypt_count[encrypt_level], encrypt_level); -#ifdef XQC_NO_PID_PACKET_PROCESS - ret = xqc_conn_process_packet(conn, packet_in->buf, packet_in->buf_size, packet_in->pkt_recv_time); -#else - ret = xqc_conn_process_packet(conn, packet_in->buf, packet_in->buf_size, XQC_UNKNOWN_PATH_ID, packet_in->pkt_recv_time); -#endif + ret = xqc_conn_process_packet(conn, packet_in->buf, packet_in->buf_size, packet_in->pkt_recv_time); if (ret) { xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_packet_process error|ret:%d|", ret); return ret; @@ -4020,17 +4119,11 @@ xqc_conn_log_recvd_packet(xqc_connection_t *c, xqc_packet_in_t *pi, c->rcv_pkt_stats.curr_index = (index + 1) % 3; } -#ifdef XQC_NO_PID_PACKET_PROCESS + xqc_int_t xqc_conn_process_packet(xqc_connection_t *c, const unsigned char *packet_in_buf, size_t packet_in_size, xqc_usec_t recv_time) -#else -xqc_int_t -xqc_conn_process_packet(xqc_connection_t *c, - const unsigned char *packet_in_buf, size_t packet_in_size, - uint64_t path_id, xqc_usec_t recv_time) -#endif { xqc_int_t ret = XQC_OK; const unsigned char *last_pos = NULL; @@ -4047,11 +4140,8 @@ xqc_conn_process_packet(xqc_connection_t *c, xqc_packet_in_t *packet_in = &packet; memset(packet_in, 0, sizeof(*packet_in)); xqc_packet_in_init(packet_in, pos, end - pos, decrypt_payload, XQC_MAX_PACKET_IN_LEN, recv_time); -#ifndef XQC_NO_PID_PACKET_PROCESS - packet_in->pi_path_id = path_id; -#else + packet_in->pi_path_id = XQC_UNKNOWN_PATH_ID; -#endif /* packet_in->pos will update inside */ ret = xqc_packet_process_single(c, packet_in); @@ -4085,24 +4175,15 @@ xqc_conn_process_packet(xqc_connection_t *c, return ret; } -#ifdef XQC_NO_PID_PACKET_PROCESS + void xqc_conn_process_packet_recved_path(xqc_connection_t *conn, xqc_cid_t *scid, size_t packet_in_size, xqc_usec_t recv_time) -#else -void -xqc_conn_process_packet_recved_path(xqc_connection_t *conn, xqc_cid_t *scid, - uint64_t path_id, size_t packet_in_size, xqc_usec_t recv_time) -#endif { xqc_path_ctx_t *path = NULL; if (conn->enable_multipath) { path = xqc_conn_find_path_by_scid(conn, scid); -#ifndef XQC_NO_PID_PACKET_PROCESS - if (path == NULL && path_id != XQC_UNKNOWN_PATH_ID) { - path = xqc_conn_find_path_by_path_id(conn, path_id); - } -#endif + } else { path = conn->conn_initial_path; } @@ -4228,14 +4309,7 @@ xqc_int_t xqc_conn_try_add_new_conn_id(xqc_connection_t *conn, uint64_t retire_prior_to) { uint64_t active_cid_cnt = conn->scid_set.cid_set.unused_cnt + conn->scid_set.cid_set.used_cnt; -#ifdef XQC_NO_PID_PACKET_PROCESS uint64_t unused_limit = 1; -#else - uint64_t unused_limit = conn->enable_multipath ? 2 : 1; - if (conn->enable_multipath) { - unused_limit = xqc_max(unused_limit, conn->conn_settings.least_available_cid_count); - } -#endif if (xqc_conn_is_handshake_confirmed(conn)) { while (active_cid_cnt < conn->remote_settings.active_connection_id_limit && conn->scid_set.cid_set.unused_cnt < unused_limit) @@ -4752,6 +4826,10 @@ xqc_conn_get_local_transport_params(xqc_connection_t *conn, xqc_transport_params params->retry_source_connection_id.cid_len = 0; params->retry_source_connection_id_present = 0; + params->conn_option_num = settings->conn_option_num; + xqc_memcpy(params->conn_options, settings->conn_options, + sizeof(uint32_t) * settings->conn_option_num); + return XQC_OK; } @@ -5749,7 +5827,6 @@ xqc_conn_available_paths(xqc_engine_t *engine, const xqc_cid_t *cid) return available_paths; } - #ifdef XQC_COMPAT_GENERATE_SR_PKT xqc_int_t diff --git a/src/transport/xqc_conn.h b/src/transport/xqc_conn.h index 86d843987..1e79f417b 100644 --- a/src/transport/xqc_conn.h +++ b/src/transport/xqc_conn.h @@ -203,6 +203,8 @@ typedef struct { uint64_t enable_multipath; xqc_multipath_version_t multipath_version; uint16_t max_datagram_frame_size; + uint32_t conn_options[XQC_CO_MAX_NUM]; + uint8_t conn_option_num; } xqc_trans_settings_t; @@ -415,6 +417,9 @@ struct xqc_connection_s { uint32_t sched_cc_blocked; uint32_t send_cc_blocked; + /* internal loss detection stats */ + uint32_t detected_loss_cnt; + /* receved pkts stats */ struct { xqc_pkt_type_t pkt_types[3]; @@ -535,21 +540,11 @@ xqc_conn_has_undecrypt_packets(xqc_connection_t *conn) } /* process an UDP datagram */ -#ifdef XQC_NO_PID_PACKET_PROCESS xqc_int_t xqc_conn_process_packet(xqc_connection_t *c, const unsigned char *packet_in_buf, size_t packet_in_size, xqc_usec_t recv_time); -#else -xqc_int_t xqc_conn_process_packet(xqc_connection_t *c, const unsigned char *packet_in_buf, - size_t packet_in_size, uint64_t path_id, xqc_usec_t recv_time); -#endif -#ifdef XQC_NO_PID_PACKET_PROCESS void xqc_conn_process_packet_recved_path(xqc_connection_t *conn, xqc_cid_t *scid, size_t packet_in_size, xqc_usec_t recv_time); -#else -void xqc_conn_process_packet_recved_path(xqc_connection_t *conn, xqc_cid_t *scid, - uint64_t path_id, size_t packet_in_size, xqc_usec_t recv_time); -#endif xqc_int_t xqc_conn_check_handshake_complete(xqc_connection_t *conn); diff --git a/src/transport/xqc_defs.h b/src/transport/xqc_defs.h index ef36e09af..8d7d6d47b 100644 --- a/src/transport/xqc_defs.h +++ b/src/transport/xqc_defs.h @@ -66,6 +66,6 @@ extern const unsigned char xqc_proto_version_field[][XQC_PROTO_VERSION_LEN]; #define XQC_MAX_ALPN_LEN 255 /* limit of anti-amplification */ -#define XQC_DEFAULT_ANTI_AMPLIFICATION_LIMIT 3 +#define XQC_DEFAULT_ANTI_AMPLIFICATION_LIMIT 5 #endif \ No newline at end of file diff --git a/src/transport/xqc_engine.c b/src/transport/xqc_engine.c index f35b052bf..674e682b2 100644 --- a/src/transport/xqc_engine.c +++ b/src/transport/xqc_engine.c @@ -1109,21 +1109,12 @@ xqc_engine_process_sr_pkt(xqc_engine_t *engine, const unsigned char *buf, * Pass received UDP packet payload into xquic engine. * @param recv_time UDP packet received time in microsecond */ -#ifdef XQC_NO_PID_PACKET_PROCESS xqc_int_t xqc_engine_packet_process(xqc_engine_t *engine, const unsigned char *packet_in_buf, size_t packet_in_size, const struct sockaddr *local_addr, socklen_t local_addrlen, const struct sockaddr *peer_addr, socklen_t peer_addrlen, xqc_usec_t recv_time, void *user_data) -#else -xqc_int_t -xqc_engine_packet_process(xqc_engine_t *engine, - const unsigned char *packet_in_buf, size_t packet_in_size, - const struct sockaddr *local_addr, socklen_t local_addrlen, - const struct sockaddr *peer_addr, socklen_t peer_addrlen, - uint64_t path_id, xqc_usec_t recv_time, void *user_data) -#endif { xqc_int_t ret; xqc_connection_t *conn = NULL; @@ -1269,11 +1260,7 @@ xqc_engine_packet_process(xqc_engine_t *engine, } /* process packets */ -#ifdef XQC_NO_PID_PACKET_PROCESS ret = xqc_conn_process_packet(conn, packet_in_buf, packet_in_size, recv_time); -#else - ret = xqc_conn_process_packet(conn, packet_in_buf, packet_in_size, path_id, recv_time); -#endif conn->rcv_pkt_stats.conn_udp_pkts++; @@ -1300,11 +1287,8 @@ xqc_engine_packet_process(xqc_engine_t *engine, goto after_process; } } -#ifdef XQC_NO_PID_PACKET_PROCESS + xqc_conn_process_packet_recved_path(conn, &scid, packet_in_size, recv_time); -#else - xqc_conn_process_packet_recved_path(conn, &scid, path_id, packet_in_size, recv_time); -#endif xqc_timer_set(&conn->conn_timer_manager, XQC_TIMER_CONN_IDLE, recv_time, xqc_conn_get_idle_timeout(conn) * 1000); diff --git a/src/transport/xqc_multipath.c b/src/transport/xqc_multipath.c index 35694a4f8..55a81a448 100644 --- a/src/transport/xqc_multipath.c +++ b/src/transport/xqc_multipath.c @@ -249,9 +249,10 @@ xqc_path_move_unack_packets_from_conn(xqc_path_ctx_t *path, xqc_connection_t *co } if (XQC_NEED_REPAIR(po->po_frame_types) + || (po->po_flag & XQC_POF_NOTIFY) || repair_dgram == XQC_DGRAM_RETX_ASKED_BY_APP) { - xqc_send_queue_copy_to_lost(po, conn->conn_send_queue); + xqc_send_queue_copy_to_lost(po, conn->conn_send_queue, XQC_FALSE); } else { /* for datagram, we should remove all copies in the unacked list */ @@ -868,49 +869,6 @@ xqc_stream_path_metrics_on_recv(xqc_connection_t *conn, xqc_stream_t *stream, xq } -void -xqc_path_metrics_print(xqc_connection_t *conn, char *buff, unsigned buff_size) -{ - xqc_list_head_t *pos, *next; - xqc_path_ctx_t *path; - - int cursor = 0; - int ret = 0; - xqc_list_for_each_safe(pos, next, &conn->conn_paths_list) { - path = xqc_list_entry(pos, xqc_path_ctx_t, path_list); - if (path->path_state >= XQC_PATH_STATE_VALIDATING) { - if (cursor >= (buff_size - 100)) { // enough space - break; - } - - // TODO 关于数据抓取说明 - ret = snprintf(buff + cursor, buff_size - cursor, - "#%"PRIu64"-%d-%d-%"PRIu64"-%.4f-%"PRIu32"-%"PRIu32"-%"PRIu32"-%"PRIu32"-%"PRIu32"" - "-%"PRIu32"-%"PRIu32"-%"PRIu32"-%"PRIu64"-%"PRIu64"-%"PRIu32"-%"PRIu32, - path->path_id, - path->path_state, - path->app_path_status, - xqc_send_ctl_get_srtt(path->path_send_ctl), - xqc_send_ctl_get_retrans_rate(path->path_send_ctl), - path->path_send_ctl->ctl_send_count, - path->path_send_ctl->ctl_lost_count, - path->path_send_ctl->ctl_tlp_count, - path->path_send_ctl->ctl_spurious_loss_count, - path->path_send_ctl->ctl_recv_count, - path->path_send_ctl->ctl_update_latest_rtt_count, - path->rebinding_count, - path->rebinding_valid, - path->path_send_ctl->ctl_bytes_send, - path->path_send_ctl->ctl_bytes_recv, - path->standby_probe_count, - path->app_path_status_changed_count); - - cursor += ret; - } - } -} - - void xqc_path_send_buffer_append(xqc_path_ctx_t *path, xqc_packet_out_t *packet_out, xqc_list_head_t *head) { diff --git a/src/transport/xqc_multipath.h b/src/transport/xqc_multipath.h index 5ddffa209..1e1d8688e 100644 --- a/src/transport/xqc_multipath.h +++ b/src/transport/xqc_multipath.h @@ -104,7 +104,6 @@ struct xqc_path_ctx_s { uint64_t path_id; /* path identifier */ xqc_cid_t path_scid; xqc_cid_t path_dcid; - xqc_cid_t path_last_scid; /* Path_address: 4-tuple */ unsigned char peer_addr[sizeof(struct sockaddr_in6)], @@ -252,8 +251,6 @@ void xqc_stream_path_metrics_print(xqc_connection_t *conn, xqc_stream_t *stream, void xqc_stream_path_metrics_on_send(xqc_connection_t *conn, xqc_packet_out_t *po); void xqc_stream_path_metrics_on_recv(xqc_connection_t *conn, xqc_stream_t *stream, xqc_packet_in_t *pi); -void xqc_path_metrics_print(xqc_connection_t *conn, char *buff, unsigned buff_size); - xqc_msec_t xqc_path_get_idle_timeout(xqc_path_ctx_t *path); void xqc_path_validate(xqc_path_ctx_t *path); diff --git a/src/transport/xqc_pacing.c b/src/transport/xqc_pacing.c index 0d34f06bd..7dab731f0 100644 --- a/src/transport/xqc_pacing.c +++ b/src/transport/xqc_pacing.c @@ -13,7 +13,7 @@ #define FALSE 0 #define XQC_CLOCK_GRANULARITY_US 1000 /* 1ms */ #define XQC_PACING_DELAY_US XQC_CLOCK_GRANULARITY_US -#define XQC_DEFAULT_PACING_RATE (((2 * XQC_MSS * 1000000ULL)/(XQC_kInitialRtt * 1000))) +#define XQC_DEFAULT_PACING_RATE(init_rtt) (((2 * XQC_MSS * 1000000ULL)/(init_rtt))) void xqc_pacing_init(xqc_pacing_t *pacing, int pacing_on, xqc_send_ctl_t *send_ctl) @@ -45,13 +45,13 @@ xqc_pacing_rate_calc(xqc_pacing_t *pacing) xqc_usec_t srtt = send_ctl->ctl_srtt; if (srtt == 0) { - srtt = XQC_kInitialRtt * 1000; + srtt = send_ctl->ctl_conn->conn_settings.initial_rtt; } /* bytes can be sent per second */ pacing_rate = cwnd * 1000000 / srtt; if (pacing_rate == 0) { - pacing_rate = XQC_DEFAULT_PACING_RATE; + pacing_rate = XQC_DEFAULT_PACING_RATE(srtt); xqc_log(pacing->ctl_ctx->ctl_conn->log, XQC_LOG_ERROR, "|pacing_rate zero|cwnd:%ui|srtt:%ui|", cwnd, srtt); } diff --git a/src/transport/xqc_packet_out.c b/src/transport/xqc_packet_out.c index 177eb5e30..ca5a08d2b 100644 --- a/src/transport/xqc_packet_out.c +++ b/src/transport/xqc_packet_out.c @@ -169,6 +169,12 @@ xqc_packet_out_copy(xqc_packet_out_t *dst, xqc_packet_out_t *src) dst->po_flag &= ~XQC_POF_IN_UNACK_LIST; dst->po_flag &= ~XQC_POF_IN_PATH_BUF_LIST; + + dst->po_pr = src->po_pr; + + if (dst->po_pr) { + dst->po_pr->ref_cnt++; + } } @@ -655,9 +661,12 @@ xqc_write_conn_close_to_packet(xqc_connection_t *conn, uint64_t err_code) xqc_pkt_type_t pkt_type = XQC_PTYPE_INIT; /* peer may not have received the handshake packet */ - if (conn->conn_flag & XQC_CONN_FLAG_HANDSHAKE_COMPLETED && conn->conn_flag & XQC_CONN_FLAG_HSK_ACKED) { + if ((conn->conn_flag & XQC_CONN_FLAG_HANDSHAKE_COMPLETED && conn->conn_flag & XQC_CONN_FLAG_HSK_ACKED) + || (conn->conn_flag & XQC_CONN_FLAG_HANDSHAKE_CONFIRMED)) + { pkt_type = XQC_PTYPE_SHORT_HEADER; } + packet_out = xqc_write_new_packet(conn, pkt_type); if (packet_out == NULL) { xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_write_new_packet error|"); diff --git a/src/transport/xqc_packet_out.h b/src/transport/xqc_packet_out.h index fea842bcc..622735f62 100644 --- a/src/transport/xqc_packet_out.h +++ b/src/transport/xqc_packet_out.h @@ -44,6 +44,7 @@ typedef enum { XQC_POF_PMTUD_PROBING = 1 << 17, XQC_POF_QOS_HIGH = 1 << 18, XQC_POF_QOS_PROBING = 1 << 19, + XQC_POF_SPURIOUS_LOSS = 1 << 20, } xqc_packet_out_flag_t; typedef struct xqc_po_stream_frame_s { diff --git a/src/transport/xqc_packet_parser.c b/src/transport/xqc_packet_parser.c index dc867fd5b..7893cda2a 100644 --- a/src/transport/xqc_packet_parser.c +++ b/src/transport/xqc_packet_parser.c @@ -279,32 +279,6 @@ xqc_packet_parse_short_header(xqc_connection_t *c, xqc_packet_in_t *packet_in) if (c->enable_multipath) { /* try to find the path */ path = xqc_conn_find_path_by_scid(c, &packet_in->pi_pkt.pkt_dcid); -#ifndef XQC_NO_PID_PACKET_PROCESS - /* Note: to handle the case in which the server changes CID upon NAT rebinding */ - if (path == NULL && packet_in->pi_path_id != XQC_UNKNOWN_PATH_ID) { - path = xqc_conn_find_path_by_path_id(c, packet_in->pi_path_id); - - if (path == NULL) { - xqc_log(c->log, XQC_LOG_ERROR, "|can not find path|dcid:%s|path_id:%ui|", - xqc_dcid_str(&packet_in->pi_pkt.pkt_dcid), packet_in->pi_path_id); - return -XQC_EILLPKT; - } - - /* update the cid to a newer one */ - if (xqc_cid_is_equal(&path->path_last_scid, &packet_in->pi_pkt.pkt_dcid) != XQC_OK) { - xqc_cid_copy(&path->path_last_scid, &path->path_scid); - xqc_cid_copy(&path->path_scid, &packet_in->pi_pkt.pkt_dcid); - xqc_log(c->log, XQC_LOG_DEBUG, "|update_path_scid|%s->%s|", - xqc_scid_str(&path->path_last_scid), - xqc_dcid_str(&path->path_scid)); - /* clear recv record and reset packet number */ - path->path_pn_ctl->ctl_largest_acked_ack[XQC_PNS_APP_DATA] = 0; - path->path_send_ctl->ctl_largest_received[XQC_PNS_APP_DATA] = XQC_MAX_UINT64_VALUE; - xqc_ack_sent_record_reset(&path->path_pn_ctl->ack_sent_record[XQC_PNS_APP_DATA]); - xqc_recv_record_destroy(&path->path_pn_ctl->ctl_recv_record[XQC_PNS_APP_DATA]); - } - } -#endif } else { path = c->conn_initial_path; diff --git a/src/transport/xqc_reinjection.c b/src/transport/xqc_reinjection.c index d9265dc07..1932f6bad 100644 --- a/src/transport/xqc_reinjection.c +++ b/src/transport/xqc_reinjection.c @@ -92,6 +92,9 @@ xqc_conn_try_reinject_packet(xqc_connection_t *conn, xqc_packet_out_t *packet_ou po_copy->po_path_flag &= ~XQC_PATH_SPECIFIED_BY_PTO; } + po_copy->po_flag &= ~XQC_POF_RETRANSED; + po_copy->po_flag &= ~XQC_POF_SPURIOUS_LOSS; + xqc_associate_packet_with_reinjection(packet_out, po_copy); xqc_send_queue_insert_send(po_copy, &send_queue->sndq_send_packets, send_queue); diff --git a/src/transport/xqc_send_ctl.c b/src/transport/xqc_send_ctl.c index 45eddcaf3..036259b10 100644 --- a/src/transport/xqc_send_ctl.c +++ b/src/transport/xqc_send_ctl.c @@ -15,6 +15,7 @@ #include "src/transport/xqc_conn.h" #include "src/transport/xqc_stream.h" #include "src/common/xqc_memory_pool.h" +#include "src/common/xqc_algorithm.h" #include "src/congestion_control/xqc_sample.h" #include "src/transport/xqc_pacing.h" #include "src/transport/xqc_utils.h" @@ -122,12 +123,13 @@ xqc_send_ctl_create(xqc_path_ctx_t *path) send_ctl->ctl_pto_count = 0; send_ctl->ctl_minrtt = XQC_MAX_UINT32_VALUE; - send_ctl->ctl_srtt = XQC_kInitialRtt * 1000; - send_ctl->ctl_rttvar = XQC_kInitialRtt * 1000 / 2; + send_ctl->ctl_srtt = conn->conn_settings.initial_rtt; + send_ctl->ctl_rttvar = send_ctl->ctl_srtt / 2; send_ctl->ctl_latest_rtt = 0; send_ctl->ctl_max_bytes_in_flight = 0; send_ctl->ctl_reordering_packet_threshold = conn->conn_settings.loss_detection_pkt_thresh; send_ctl->ctl_reordering_time_threshold_shift = XQC_kTimeThresholdShift; + send_ctl->ctl_first_rtt_sample_time = 0; for (size_t i = 0; i < XQC_PNS_N; i++) { send_ctl->ctl_largest_acked[i] = XQC_MAX_UINT64_VALUE; @@ -207,12 +209,13 @@ xqc_send_ctl_reset(xqc_send_ctl_t *send_ctl) send_ctl->ctl_pto_count = 0; send_ctl->ctl_minrtt = XQC_MAX_UINT32_VALUE; - send_ctl->ctl_srtt = XQC_kInitialRtt * 1000; - send_ctl->ctl_rttvar = XQC_kInitialRtt * 1000 / 2; + send_ctl->ctl_srtt = conn->conn_settings.initial_rtt; + send_ctl->ctl_rttvar = send_ctl->ctl_srtt / 2; send_ctl->ctl_max_bytes_in_flight = 0; send_ctl->ctl_reordering_packet_threshold = XQC_kPacketThreshold; send_ctl->ctl_reordering_time_threshold_shift = XQC_kTimeThresholdShift; send_ctl->ctl_ack_sent_cnt = 0; + send_ctl->ctl_first_rtt_sample_time = 0; for (size_t i = 0; i < XQC_PNS_N; i++) { send_ctl->ctl_largest_acked[i] = XQC_MAX_UINT64_VALUE; @@ -563,15 +566,8 @@ xqc_send_ctl_decrease_inflight(xqc_connection_t *conn, xqc_packet_out_t *packet_ xqc_send_ctl_t *send_ctl = path->path_send_ctl; if (packet_out->po_flag & XQC_POF_IN_FLIGHT) { if (XQC_IS_ACK_ELICITING(packet_out->po_frame_types)) { - if (send_ctl->ctl_bytes_ack_eliciting_inflight[packet_out->po_pkt.pkt_pns] < packet_out->po_used_size) { - xqc_log(conn->log, XQC_LOG_ERROR, "|ctl_bytes_in_flight too small|"); - send_ctl->ctl_bytes_ack_eliciting_inflight[packet_out->po_pkt.pkt_pns] = 0; - send_ctl->ctl_bytes_in_flight = 0; - - } else { - send_ctl->ctl_bytes_ack_eliciting_inflight[packet_out->po_pkt.pkt_pns] -= packet_out->po_used_size; - send_ctl->ctl_bytes_in_flight -= packet_out->po_used_size; - } + send_ctl->ctl_bytes_ack_eliciting_inflight[packet_out->po_pkt.pkt_pns] = xqc_uint32_bounded_subtract(send_ctl->ctl_bytes_ack_eliciting_inflight[packet_out->po_pkt.pkt_pns], packet_out->po_used_size); + send_ctl->ctl_bytes_in_flight = xqc_uint32_bounded_subtract(send_ctl->ctl_bytes_in_flight, packet_out->po_used_size); packet_out->po_flag &= ~XQC_POF_IN_FLIGHT; } } @@ -619,12 +615,14 @@ xqc_send_ctl_on_packet_sent(xqc_send_ctl_t *send_ctl, xqc_pn_ctl_t *pn_ctl, xqc_ xqc_packet_number_t orig_pktnum = packet_out->po_origin ? packet_out->po_origin->po_pkt.pkt_num : 0; xqc_log(send_ctl->ctl_conn->log, XQC_LOG_DEBUG, - "|conn:%p|path:%ui|pkt_num:%ui|origin_pktnum:%ui|size:%ud|enc_size:%ud|pkt_type:%s|frame:%s|conn_state:%s|po_in_flight:%d|", + "|conn:%p|path:%ui|pkt_num:%ui|origin_pktnum:%ui|size:%ud|enc_size:%ud|pkt_type:%s|frame:%s|conn_state:%s|po_in_flight:%d|" + "|retrans:%d|", send_ctl->ctl_conn, send_ctl->ctl_path->path_id, packet_out->po_pkt.pkt_num, orig_pktnum, packet_out->po_used_size, packet_out->po_enc_size, xqc_pkt_type_2_str(packet_out->po_pkt.pkt_type), xqc_frame_type_2_str(packet_out->po_frame_types), xqc_conn_state_2_str(send_ctl->ctl_conn->conn_state), - packet_out->po_flag & XQC_POF_IN_FLIGHT ? 1: 0); + packet_out->po_flag & XQC_POF_IN_FLIGHT ? 1: 0, + packet_out->po_flag & (XQC_POF_LOST | XQC_POF_TLP)); if (packet_out->po_frame_types & (XQC_FRAME_BIT_DATA_BLOCKED @@ -661,39 +659,23 @@ xqc_send_ctl_on_packet_sent(xqc_send_ctl_t *send_ctl, xqc_pn_ctl_t *pn_ctl, xqc_ send_ctl->ctl_last_sent_ack_eliciting_packet_number[pns] = packet_out->po_pkt.pkt_num; } + xqc_conn_update_stream_stats_on_sent(send_ctl->ctl_conn, packet_out, now); xqc_log(send_ctl->ctl_conn->log, XQC_LOG_DEBUG, "|path:%ui|inflight:%ud|applimit:%ui|", send_ctl->ctl_path->path_id, send_ctl->ctl_bytes_in_flight, send_ctl->ctl_app_limited); + if (send_ctl->ctl_bytes_in_flight == 0) { + if (send_ctl->ctl_cong_callback->xqc_cong_ctl_init_bbr && send_ctl->ctl_app_limited > 0) { - uint8_t mode, idle_restart; - mode = send_ctl->ctl_cong_callback-> - xqc_cong_ctl_info_cb->mode(send_ctl->ctl_cong); - idle_restart = send_ctl->ctl_cong_callback-> - xqc_cong_ctl_info_cb-> - idle_restart(send_ctl->ctl_cong); - xqc_log(send_ctl->ctl_conn->log, XQC_LOG_DEBUG, - "|BeforeRestartFromIdle|mode %ud|idle %ud" - "|bw %ud|pacing rate %ud|", - (unsigned int)mode, (unsigned int)idle_restart, send_ctl->ctl_cong_callback-> - xqc_cong_ctl_get_bandwidth_estimate(send_ctl->ctl_cong), - send_ctl->ctl_cong_callback-> - xqc_cong_ctl_get_pacing_rate(send_ctl->ctl_cong)); send_ctl->ctl_cong_callback->xqc_cong_ctl_restart_from_idle(send_ctl->ctl_cong, send_ctl->ctl_delivered); xqc_log_event(send_ctl->ctl_conn->log, REC_CONGESTION_STATE_UPDATED, "restart"); - - xqc_log(send_ctl->ctl_conn->log, XQC_LOG_DEBUG, - "|AfterRestartFromIdle|mode %ud|" - "idle %ud|bw %ud|pacing rate %ud|", - (unsigned int)mode, (unsigned int)idle_restart, send_ctl->ctl_cong_callback-> - xqc_cong_ctl_get_bandwidth_estimate(send_ctl->ctl_cong), - send_ctl->ctl_cong_callback->xqc_cong_ctl_get_pacing_rate(send_ctl->ctl_cong)); } + if (!send_ctl->ctl_cong_callback->xqc_cong_ctl_init_bbr) { xqc_log(send_ctl->ctl_conn->log, XQC_LOG_DEBUG, "|Restart from idle|"); send_ctl->ctl_cong_callback->xqc_cong_ctl_restart_from_idle(send_ctl->ctl_cong, send_ctl->ctl_last_inflight_pkt_sent_time); @@ -871,7 +853,7 @@ xqc_send_ctl_on_ack_received(xqc_send_ctl_t *send_ctl, xqc_pn_ctl_t *pn_ctl, xqc xqc_log(conn->log, XQC_LOG_DEBUG, "|conn:%p|path:%ui|pkt_num:%ui|origin_pktnum:%ui|size:%ud|pns:%d|pkt_type:%s|frame:%s|conn_state:%s|frame_largest_ack:%ui|path_largest_ack:%ui|", conn, send_ctl->ctl_path->path_id, packet_out->po_pkt.pkt_num, - (xqc_packet_number_t)(packet_out->po_origin ? packet_out->po_origin->po_pkt.pkt_num : 0), + (xqc_packet_number_t)packet_out->po_origin ? packet_out->po_origin->po_pkt.pkt_num : 0, packet_out->po_used_size, pns, xqc_pkt_type_2_str(packet_out->po_pkt.pkt_type), xqc_frame_type_2_str(packet_out->po_frame_types), @@ -882,13 +864,14 @@ xqc_send_ctl_on_ack_received(xqc_send_ctl_t *send_ctl, xqc_pn_ctl_t *pn_ctl, xqc xqc_update_sample(&send_ctl->sampler, packet_out, send_ctl, ack_recv_time); /* Packet previously declared lost gets acked */ - if (!packet_out->po_acked && (packet_out->po_flag & XQC_POF_RETRANSED)) { + if (!(packet_out->po_flag & XQC_POF_SPURIOUS_LOSS) && (packet_out->po_flag & XQC_POF_RETRANSED)) { ++send_ctl->ctl_spurious_loss_count; if (!spurious_loss_detected) { spurious_loss_detected = 1; spurious_loss_pktnum = packet_out->po_pkt.pkt_num; spurious_loss_sent_time = packet_out->po_sent_time; } + packet_out->po_flag |= XQC_POF_SPURIOUS_LOSS; } if (packet_out->po_frame_types & XQC_FRAME_BIT_DATAGRAM) { @@ -1269,9 +1252,10 @@ xqc_send_ctl_detect_lost(xqc_send_ctl_t *send_ctl, xqc_send_queue_t *send_queue, } if (XQC_NEED_REPAIR(po->po_frame_types) + || (po->po_flag & XQC_POF_NOTIFY) || repair_dgram == XQC_DGRAM_RETX_ASKED_BY_APP) { - xqc_send_queue_copy_to_lost(po, send_queue); + xqc_send_queue_copy_to_lost(po, send_queue, XQC_TRUE); } else { if (po->po_frame_types & XQC_FRAME_BIT_DATAGRAM) { @@ -1285,6 +1269,7 @@ xqc_send_ctl_detect_lost(xqc_send_ctl_t *send_ctl, xqc_send_queue_t *send_queue, } } + conn->detected_loss_cnt++; lost_n++; xqc_log(conn->log, XQC_LOG_DEBUG, "|mark lost|pns:%d|pkt_num:%ui|" @@ -1577,7 +1562,16 @@ xqc_send_ctl_get_pto_time_and_space(xqc_send_ctl_t *send_ctl, xqc_usec_t now, xq /* get pto duration */ xqc_usec_t duration = (send_ctl->ctl_srtt - + xqc_max(4 * send_ctl->ctl_rttvar, XQC_kGranularity * 1000)) * backoff; + + xqc_max(4 * send_ctl->ctl_rttvar, XQC_kGranularity * 1000)); + + /* RTT has not been measured yet*/ + if (send_ctl->ctl_first_rtt_sample_time == 0 + && c->conn_settings.initial_pto_duration != 0) + { + duration = c->conn_settings.initial_pto_duration; + } + + duration *= backoff; xqc_log(c->log, XQC_LOG_DEBUG, "|srtt:%ud|rtt_var:%ud|pto_duration:%ud|backoff_factor:%.2f|backoff:%.2f|pto_cnt:%d|max_ack_delay:%d|", @@ -1819,7 +1813,7 @@ xqc_send_ctl_get_est_bw(xqc_send_ctl_t *send_ctl) } else if (send_ctl->ctl_cong_callback->xqc_cong_ctl_get_cwnd) { uint64_t cwnd = send_ctl->ctl_cong_callback->xqc_cong_ctl_get_cwnd(send_ctl->ctl_cong); - xqc_usec_t srtt = send_ctl->ctl_srtt ? send_ctl->ctl_srtt : XQC_kInitialRtt * 1000; + xqc_usec_t srtt = send_ctl->ctl_srtt ? send_ctl->ctl_srtt : send_ctl->ctl_conn->conn_settings.initial_rtt; return (cwnd * 1000000) / srtt; } } diff --git a/src/transport/xqc_send_ctl.h b/src/transport/xqc_send_ctl.h index d4c233185..3832c0a84 100644 --- a/src/transport/xqc_send_ctl.h +++ b/src/transport/xqc_send_ctl.h @@ -25,7 +25,7 @@ */ #define XQC_kGranularity 2 -#define XQC_kInitialRtt 250 +#define XQC_kInitialRtt_us 250000 /* 2^n */ #define xqc_send_ctl_pow(n) (1 << n) diff --git a/src/transport/xqc_send_queue.c b/src/transport/xqc_send_queue.c index 9cdbc3bc9..be169f2fc 100644 --- a/src/transport/xqc_send_queue.c +++ b/src/transport/xqc_send_queue.c @@ -336,7 +336,7 @@ xqc_send_queue_move_to_high_pri(xqc_list_head_t *pos, xqc_send_queue_t *send_que void -xqc_send_queue_copy_to_lost(xqc_packet_out_t *packet_out, xqc_send_queue_t *send_queue) +xqc_send_queue_copy_to_lost(xqc_packet_out_t *packet_out, xqc_send_queue_t *send_queue, xqc_bool_t mark_retrans) { xqc_connection_t *conn = send_queue->sndq_conn; @@ -355,7 +355,11 @@ xqc_send_queue_copy_to_lost(xqc_packet_out_t *packet_out, xqc_send_queue_t *send xqc_send_queue_insert_lost(&new_po->po_list, &send_queue->sndq_lost_packets); send_queue->sndq_packets_used++; - packet_out->po_flag |= XQC_POF_RETRANSED; + if (mark_retrans) { + packet_out->po_flag |= XQC_POF_RETRANSED; + } + new_po->po_flag &= ~XQC_POF_RETRANSED; + new_po->po_flag &= ~XQC_POF_SPURIOUS_LOSS; } void @@ -378,6 +382,8 @@ xqc_send_queue_copy_to_probe(xqc_packet_out_t *packet_out, xqc_send_queue_t *sen xqc_send_queue_insert_probe(&new_po->po_list, &send_queue->sndq_pto_probe_packets); send_queue->sndq_packets_used++; packet_out->po_flag |= XQC_POF_RETRANSED; + new_po->po_flag &= ~XQC_POF_RETRANSED; + new_po->po_flag &= ~XQC_POF_SPURIOUS_LOSS; } /* Called when conn is ready to close */ diff --git a/src/transport/xqc_send_queue.h b/src/transport/xqc_send_queue.h index 596dd1afa..4cca22eb0 100644 --- a/src/transport/xqc_send_queue.h +++ b/src/transport/xqc_send_queue.h @@ -86,7 +86,7 @@ void xqc_send_queue_move_to_head(xqc_list_head_t *pos, xqc_list_head_t *head); void xqc_send_queue_move_to_tail(xqc_list_head_t *pos, xqc_list_head_t *head); void xqc_send_queue_move_to_high_pri(xqc_list_head_t *pos, xqc_send_queue_t *send_queue); -void xqc_send_queue_copy_to_lost(xqc_packet_out_t *packet_out, xqc_send_queue_t *send_queue); +void xqc_send_queue_copy_to_lost(xqc_packet_out_t *packet_out, xqc_send_queue_t *send_queue, xqc_bool_t mark_retrans); void xqc_send_queue_copy_to_probe(xqc_packet_out_t *packet_out, xqc_send_queue_t *send_queue, xqc_path_ctx_t *path); diff --git a/src/transport/xqc_stream.c b/src/transport/xqc_stream.c index 1297274d4..97ef6fdcc 100644 --- a/src/transport/xqc_stream.c +++ b/src/transport/xqc_stream.c @@ -1347,9 +1347,8 @@ xqc_stream_send(xqc_stream_t *stream, unsigned char *send_data, size_t send_data if (!(conn->conn_flag & XQC_CONN_FLAG_CAN_SEND_1RTT)) { - if ((conn->conn_type == XQC_CONN_TYPE_CLIENT) - && (conn->conn_state == XQC_CONN_STATE_CLIENT_INITIAL_SENT) - && support_0rtt) + if ((conn->conn_type == XQC_CONN_TYPE_CLIENT) && support_0rtt + && xqc_conn_is_ready_to_send_early_data(conn)) { pkt_type = XQC_PTYPE_0RTT; conn->conn_flag |= XQC_CONN_FLAG_HAS_0RTT; diff --git a/src/transport/xqc_transport_params.c b/src/transport/xqc_transport_params.c index 944ee5e63..0b244bae0 100644 --- a/src/transport/xqc_transport_params.c +++ b/src/transport/xqc_transport_params.c @@ -180,6 +180,12 @@ xqc_transport_params_calc_length(const xqc_transport_params_t *params, xqc_put_varint_len(params->max_datagram_frame_size); } + if (params->conn_option_num) { + len += xqc_put_varint_len(XQC_TRANSPORT_PARAM_GOOGLE_CO) + + xqc_put_varint_len(params->conn_option_num * sizeof(uint32_t)) + + params->conn_option_num * sizeof(uint32_t); + } + return len; } @@ -215,6 +221,7 @@ xqc_encode_transport_params(const xqc_transport_params_t *params, uint8_t *p = out; size_t len = 0; size_t preferred_addrlen = 0; + int i; /* calculate encoding length */ len += xqc_transport_params_calc_length(params, exttype); @@ -355,6 +362,14 @@ xqc_encode_transport_params(const xqc_transport_params_t *params, } } + if (params->conn_option_num) { + p = xqc_put_varint(p, XQC_TRANSPORT_PARAM_GOOGLE_CO); + p = xqc_put_varint(p, sizeof(uint32_t) * params->conn_option_num); + for (i = 0; i < params->conn_option_num; i++) { + p = xqc_put_uint32be(p, params->conn_options[i]); + } + } + if ((size_t)(p - out) != len) { return -XQC_TLS_MALFORMED_TRANSPORT_PARAM; } diff --git a/src/transport/xqc_transport_params.h b/src/transport/xqc_transport_params.h index 2abbf6897..901dcc60b 100644 --- a/src/transport/xqc_transport_params.h +++ b/src/transport/xqc_transport_params.h @@ -74,6 +74,9 @@ typedef enum { XQC_TRANSPORT_PARAM_ENABLE_MULTIPATH_05 = 0x0f739bbc1b666d05, XQC_TRANSPORT_PARAM_ENABLE_MULTIPATH_06 = 0x0f739bbc1b666d06, + /* google connection options */ + XQC_TRANSPORT_PARAM_GOOGLE_CO = 0x3128, + /* upper limit of params defined by xquic */ XQC_TRANSPORT_PARAM_UNKNOWN, } xqc_transport_param_id_t; @@ -148,6 +151,9 @@ typedef struct { xqc_multipath_version_t multipath_version; + uint32_t conn_options[XQC_CO_MAX_NUM]; + uint8_t conn_option_num; + } xqc_transport_params_t; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 31b12fa5e..a1588b53a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,6 +50,7 @@ endif() add_executable(test_server ${TEST_SERVER_SOURCES}) add_executable(test_client ${TEST_CLIENT_SOURCES}) + # link libraries if(CMAKE_SYSTEM_NAME MATCHES "Windows") set(APP_DEPEND_LIBS @@ -58,12 +59,22 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows") ${LIBEVENT_LIBRARY} -lm CACHE STRING "xquic app depend libs") +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(APP_DEPEND_LIBS + xquic-static + ${SSL_LIB_PATH} + ${LIBEVENT_LIBRARY} + m + dl + pthread + CACHE STRING "xquic app depend libs") else() set(APP_DEPEND_LIBS xquic-static ${SSL_LIB_PATH} ${LIBEVENT_LIBRARY} - -lm + stdc++ + m dl pthread CACHE STRING "xquic app depend libs") @@ -136,6 +147,7 @@ if(HAVE_CUNIT) xquic-static ${CUNIT_LIBRARIES} ${SSL_LIB_PATH} + stdc++ m dl pthread diff --git a/tests/test_client.c b/tests/test_client.c index a06b2c272..8a67e5240 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -2492,6 +2492,14 @@ xqc_client_request_send(xqc_h3_request_t *h3_request, user_stream_t *user_stream }, }; + if (g_test_case == 47) { + header[header_size].name.iov_base = "test_null_hdr"; + header[header_size].name.iov_len = 13; + header[header_size].value.iov_base = ""; + header[header_size].value.iov_len = 0; + header_size++; + } + if (g_mp_request_accelerate) { /* set local h3 priority */ xqc_h3_priority_t h3_prio = { @@ -3133,17 +3141,10 @@ xqc_client_socket_read_handler(user_conn_t *user_conn, int fd) for (int i = 0; i < retval; i++) { recv_sum += msgs[i].msg_len; -#ifdef XQC_NO_PID_PACKET_PROCESS - ret = xqc_engine_packet_process(p_ctx->engine, iovecs[i].iov_base, msgs[i].msg_len, - user_conn->local_addr, user_conn->local_addrlen, - user_conn->peer_addr, user_conn->peer_addrlen, - (xqc_usec_t)recv_time, user_conn); -#else ret = xqc_engine_packet_process(p_ctx->engine, iovecs[i].iov_base, msgs[i].msg_len, user_conn->local_addr, user_conn->local_addrlen, user_conn->peer_addr, user_conn->peer_addrlen, - path_id, (xqc_usec_t)recv_time, user_conn); -#endif + (xqc_usec_t)recv_time, user_conn); if (ret != XQC_OK) { printf("xqc_server_read_handler: packet process err, ret: %d\n", ret); @@ -3231,17 +3232,11 @@ xqc_client_socket_read_handler(user_conn_t *user_conn, int fd) continue; } } -#ifdef XQC_NO_PID_PACKET_PROCESS - ret = xqc_engine_packet_process(p_ctx->engine, packet_buf, recv_size, - user_conn->local_addr, user_conn->local_addrlen, - user_conn->peer_addr, user_conn->peer_addrlen, - (xqc_usec_t)recv_time, user_conn); -#else + ret = xqc_engine_packet_process(p_ctx->engine, packet_buf, recv_size, user_conn->local_addr, user_conn->local_addrlen, user_conn->peer_addr, user_conn->peer_addrlen, - path_id, (xqc_usec_t)recv_time, user_conn); -#endif + (xqc_usec_t)recv_time, user_conn); if (ret != XQC_OK) { printf("xqc_client_read_handler: packet process err, ret: %d\n", ret); return; @@ -4055,6 +4050,7 @@ int main(int argc, char *argv[]) { int transport = 0; int use_1rtt = 0; uint64_t rate_limit = 0; + char conn_options[XQC_CO_STR_MAX_LEN] = {0}; strcpy(g_log_path, "./clog"); @@ -4070,6 +4066,7 @@ int main(int argc, char *argv[]) { {"pmtud", required_argument, &long_opt_index, 5}, {"mp_ping", required_argument, &long_opt_index, 6}, {"rate_limit", required_argument, &long_opt_index, 7}, + {"conn_options", required_argument, &long_opt_index, 8}, {0, 0, 0, 0} }; @@ -4348,6 +4345,11 @@ int main(int argc, char *argv[]) { printf("option rate_limit: %"PRIu64" Bps\n", rate_limit); break; + case 8: + strncpy(conn_options, optarg, XQC_CO_STR_MAX_LEN); + printf("option conn_options: %s\n", conn_options); + break; + default: break; } @@ -4477,6 +4479,8 @@ int main(int argc, char *argv[]) { .recv_rate_bytes_per_sec = rate_limit, }; + strncpy(conn_settings.conn_option_str, conn_options, XQC_CO_STR_MAX_LEN); + #ifdef XQC_PROTECT_POOL_MEM if (g_test_case == 600) { conn_settings.protect_pool_mem = 1; diff --git a/tests/test_server.c b/tests/test_server.c index 19bf0644b..7dda6484f 100644 --- a/tests/test_server.c +++ b/tests/test_server.c @@ -1633,17 +1633,10 @@ xqc_server_socket_read_handler(xqc_server_ctx_t *ctx) uint64_t recv_time = xqc_now(); for (int i = 0; i < retval; i++) { recv_sum += msgs[i].msg_len; -#ifdef XQC_NO_PID_PACKET_PROCESS if (xqc_engine_packet_process(ctx->engine, iovecs[i].iov_base, msgs[i].msg_len, (struct sockaddr *) (&ctx->local_addr), ctx->local_addrlen, (struct sockaddr *) (&pa[i]), peer_addrlen, - (xqc_usec_t)recv_time, NULL) != XQC_OK) -#else - if (xqc_engine_packet_process(ctx->engine, iovecs[i].iov_base, msgs[i].msg_len, - (struct sockaddr *) (&ctx->local_addr), ctx->local_addrlen, - (struct sockaddr *) (&pa[i]), peer_addrlen, - XQC_UNKNOWN_PATH_ID, (xqc_usec_t)recv_time, NULL) != XQC_OK) -#endif + (xqc_usec_t)recv_time, NULL) != XQC_OK) { printf("xqc_server_read_handler: packet process err\n"); return; @@ -1683,17 +1676,10 @@ xqc_server_socket_read_handler(xqc_server_ctx_t *ctx) /*printf("peer_ip: %s, peer_port: %d\n", inet_ntoa(ctx->peer_addr.sin_addr), ntohs(ctx->peer_addr.sin_port)); printf("local_ip: %s, local_port: %d\n", inet_ntoa(ctx->local_addr.sin_addr), ntohs(ctx->local_addr.sin_port));*/ -#ifdef XQC_NO_PID_PACKET_PROCESS ret = xqc_engine_packet_process(ctx->engine, packet_buf, recv_size, (struct sockaddr *) (&ctx->local_addr), ctx->local_addrlen, (struct sockaddr *) (&peer_addr), peer_addrlen, (xqc_usec_t) recv_time, NULL); -#else - ret = xqc_engine_packet_process(ctx->engine, packet_buf, recv_size, - (struct sockaddr *) (&ctx->local_addr), ctx->local_addrlen, - (struct sockaddr *) (&peer_addr), peer_addrlen, - XQC_UNKNOWN_PATH_ID, (xqc_usec_t) recv_time, NULL); -#endif if (ret != XQC_OK) { printf("xqc_server_read_handler: packet process err: %d\n", ret); diff --git a/tests/unittest/xqc_engine_test.c b/tests/unittest/xqc_engine_test.c index 003354d86..16286e3dc 100644 --- a/tests/unittest/xqc_engine_test.c +++ b/tests/unittest/xqc_engine_test.c @@ -45,19 +45,11 @@ xqc_test_engine_packet_process() xqc_msec_t recv_time = xqc_monotonic_timestamp(); -#ifdef XQC_NO_PID_PACKET_PROCESS xqc_int_t rc = xqc_engine_packet_process(engine, XQC_TEST_LONG_HEADER_PACKET_B, sizeof(XQC_TEST_LONG_HEADER_PACKET_B) - 1, (struct sockaddr *)(&local_addr), local_addrlen, (struct sockaddr *)(&peer_addr), peer_addrlen, - recv_time, NULL); -#else - xqc_int_t rc = xqc_engine_packet_process(engine, XQC_TEST_LONG_HEADER_PACKET_B, - sizeof(XQC_TEST_LONG_HEADER_PACKET_B) - 1, - (struct sockaddr *)(&local_addr), local_addrlen, - (struct sockaddr *)(&peer_addr), peer_addrlen, - XQC_UNKNOWN_PATH_ID, recv_time, NULL); -#endif + recv_time, NULL); //CU_ASSERT(rc == XQC_OK); /* get connection */ @@ -76,17 +68,10 @@ xqc_test_engine_packet_process() conn->conn_flag |= XQC_CONN_FLAG_HANDSHAKE_COMPLETED; recv_time = xqc_monotonic_timestamp(); -#ifdef XQC_NO_PID_PACKET_PROCESS rc = xqc_engine_packet_process(engine, XQC_TEST_SHORT_HEADER_PACKET_A, sizeof(XQC_TEST_SHORT_HEADER_PACKET_A) - 1, (struct sockaddr *)&local_addr, local_addrlen, (struct sockaddr *)&peer_addr, peer_addrlen, recv_time, NULL); -#else - rc = xqc_engine_packet_process(engine, XQC_TEST_SHORT_HEADER_PACKET_A, - sizeof(XQC_TEST_SHORT_HEADER_PACKET_A) - 1, - (struct sockaddr *)&local_addr, local_addrlen, - (struct sockaddr *)&peer_addr, peer_addrlen, XQC_UNKNOWN_PATH_ID, recv_time, NULL); -#endif //CU_ASSERT(rc == XQC_OK); xqc_engine_destroy(engine); diff --git a/tests/unittest/xqc_packet_test.c b/tests/unittest/xqc_packet_test.c index d3cde7642..e7bb6bd62 100644 --- a/tests/unittest/xqc_packet_test.c +++ b/tests/unittest/xqc_packet_test.c @@ -237,8 +237,7 @@ xqc_test_empty_pkt() /* server will process the initial packet and get the secret of initial pns */ xqc_engine_packet_process(svr_tctx.engine, cli_tctx.buf, cli_tctx.buf_len, (struct sockaddr *)&local_addr, local_addrlen, - (struct sockaddr *)&peer_addr, peer_addrlen, - 0, xqc_now(), &svr_tctx); + (struct sockaddr *)&peer_addr, peer_addrlen, xqc_now(), &svr_tctx); /* generate an Initial pkt with no payload */ @@ -266,7 +265,7 @@ xqc_test_empty_pkt() /* server decrypt the Initial pkt */ ret = xqc_conn_process_packet(svr_tctx.c, cli_tctx.c->enc_pkt, - cli_tctx.c->enc_pkt_len, 0, xqc_now()); + cli_tctx.c->enc_pkt_len, xqc_now()); CU_ASSERT(svr_tctx.c->conn_err == TRA_PROTOCOL_VIOLATION);