feat: 增加链路统计信息,两个链路分别显示在前端,D向A汇报D与B的信息

This commit is contained in:
Mock
2026-04-09 13:38:10 +08:00
parent e72f7f3fd9
commit 11e67282c7
19 changed files with 573 additions and 40 deletions

View File

@@ -26,6 +26,16 @@ typedef struct kcp_session_stats_record {
int32_t srtt_ms;
int has_srttvar_ms;
int32_t srttvar_ms;
int has_snd_wnd;
uint32_t snd_wnd;
int has_rmt_wnd;
uint32_t rmt_wnd;
int has_inflight;
uint32_t inflight;
int has_window_limit;
uint32_t window_limit;
int has_window_pressure_pct;
double window_pressure_pct;
int has_bytes_sent;
uint64_t bytes_sent;
int has_bytes_received;

View File

@@ -14,6 +14,7 @@ int kcp_hub_serve_listener(kcp_hub_t *hub, kcp_listener_t *listener);
int kcp_hub_serve_session(kcp_hub_t *hub, kcp_conn_t *conn);
int kcp_hub_set_relay(kcp_hub_t *hub, int relay_fd, const struct sockaddr *peer_addr, socklen_t peer_addr_len, int learn_peer);
int kcp_hub_set_telemetry(kcp_hub_t *hub, const char *peer_id, int interval_ms);
int kcp_hub_serve_relay(kcp_hub_t *hub);
int kcp_hub_close(kcp_hub_t *hub);

View File

@@ -34,6 +34,14 @@ extern "C" {
#define KCP_VIDEO_RCV_WND 256
#define KCP_VIDEO_MTU 1400
#define KCP_TELEMETRY_NODELAY 0
#define KCP_TELEMETRY_INTERVAL_MS 50
#define KCP_TELEMETRY_RESEND 0
#define KCP_TELEMETRY_NC 0
#define KCP_TELEMETRY_SND_WND 64
#define KCP_TELEMETRY_RCV_WND 64
#define KCP_TELEMETRY_MTU 1400
#define KCP_NODELAY KCP_DEFAULT_NODELAY
#define KCP_INTERVAL KCP_DEFAULT_INTERVAL_MS
#define KCP_RESEND KCP_DEFAULT_RESEND
@@ -49,9 +57,19 @@ typedef struct kcp_runtime_stats {
uint32_t rto_ms;
int32_t srtt_ms;
int32_t srttvar_ms;
uint32_t snd_wnd;
uint32_t rmt_wnd;
uint32_t inflight;
uint32_t window_limit;
double window_pressure_pct;
uint32_t snd_queue;
uint32_t rcv_queue;
uint32_t snd_buffer;
uint64_t out_segs_total;
uint64_t retrans_total;
uint64_t fast_retrans_total;
uint64_t lost_total;
uint64_t repeat_total;
uint32_t xmit_total;
} kcp_runtime_stats_t;
typedef struct kcp_conn_options {
@@ -67,6 +85,7 @@ typedef struct kcp_conn_options {
void kcp_conn_options_init(kcp_conn_options_t *options);
void kcp_conn_options_set_control_defaults(kcp_conn_options_t *options);
void kcp_conn_options_set_video_defaults(kcp_conn_options_t *options);
void kcp_conn_options_set_telemetry_defaults(kcp_conn_options_t *options);
kcp_conn_t *kcp_conn_dial_with_options(const char *server_addr, const char *bind_ip, const char *bind_device, const kcp_conn_options_t *options, kcp_packet_debug_logger_t *packet_logger, latency_logger_t *logger, const char *node_role, const char *node_id, kcp_session_stats_logger_t *stats_logger, int stats_interval_ms);
kcp_conn_t *kcp_conn_dial(const char *server_addr, const char *bind_ip, const char *bind_device, kcp_packet_debug_logger_t *packet_logger, latency_logger_t *logger, const char *node_role, const char *node_id, kcp_session_stats_logger_t *stats_logger, int stats_interval_ms);
@@ -79,6 +98,7 @@ int kcp_conn_close(kcp_conn_t *conn);
void kcp_conn_free(kcp_conn_t *conn);
uint32_t kcp_conn_conv(const kcp_conn_t *conn);
int kcp_conn_local_addr(const kcp_conn_t *conn, struct sockaddr_storage *addr, socklen_t *addr_len);
int kcp_conn_remote_addr(const kcp_conn_t *conn, struct sockaddr_storage *addr, socklen_t *addr_len);
void kcp_conn_runtime_stats_snapshot(kcp_conn_t *conn, kcp_runtime_stats_t *out_stats);
kcp_listener_t *kcp_listener_listen(const char *listen_addr, const char *bind_device, kcp_packet_debug_logger_t *packet_logger, const char *node_role, const char *node_id);