From 38f4fe169e8cd5efb14f74e646aeea8429a9de90 Mon Sep 17 00:00:00 2001 From: ruti <> Date: Sat, 9 Nov 2024 16:20:13 +0300 Subject: [PATCH] More details in logs --- desync.c | 8 ++++++++ extend.c | 4 ++-- proxy.c | 17 ++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/desync.c b/desync.c index c63c749..4bb3819 100644 --- a/desync.c +++ b/desync.c @@ -446,6 +446,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, len, host, host - buffer); host_pos = host - buffer; } + else { + size_t s = n > 16 ? 16 : n - (n % 4); + char hex[s * 2 + 1], *b = buffer; + for (size_t i = 0; i < s; i += 4) + snprintf(hex + i * 2, sizeof(hex) - i * 2, + "%02x%02x%02x%02x", b[i],b[i+1],b[i+2],b[i+3]); + LOG(LOG_S, "bytes: %s (%zd)\n", s ? hex : "", n); + } } // modify packet if (type == IS_HTTP && dp.mod_http) { diff --git a/extend.c b/extend.c index 37f8f70..c588103 100644 --- a/extend.c +++ b/extend.c @@ -454,7 +454,7 @@ ssize_t tcp_send_hook(struct eval *remote, skip = 1; } else { - LOG((m ? LOG_S : LOG_L), "desync TCP, m=%d, r=%d\n", m, r); + LOG(LOG_S, "desync TCP: group=%d, round=%d, fd=%d\n", m, r, remote->fd); ssize_t offset = remote->pair->round_sent; if (!offset && remote->round_count) offset = -1; @@ -541,7 +541,7 @@ ssize_t udp_hook(struct eval *val, if (!check_round(params.dp[m].rounds, r)) { return send(val->fd, buffer, n, 0); } - LOG(LOG_S, "desync UDP, m=%d, r=%d\n", m, r); + LOG(LOG_S, "desync UDP: group=%d, round=%d, fd=%d\n", m, r, val->fd); return desync_udp(val->fd, buffer, bfsize, n, &dst->sa, m); } diff --git a/proxy.c b/proxy.c index c918541..286e314 100644 --- a/proxy.c +++ b/proxy.c @@ -407,6 +407,11 @@ int create_conn(struct poolhd *pool, close(sfd); return -1; } + if (params.debug) { + INIT_ADDR_STR((*dst)); + LOG(LOG_S, "new conn: fd=%d, pair=%d, addr=%s:%d\n", + sfd, val->fd, ADDR_STR, ntohs(dst->in.sin_port)); + } int status = connect(sfd, &addr.sa, SA_SIZE(&addr)); if (status == 0 && params.tfo) { LOG(LOG_S, "TFO supported!\n"); @@ -435,12 +440,6 @@ int create_conn(struct poolhd *pool, #endif pair->flag = FLAG_CONN; //val->type = EV_IGNORE; - - if (params.debug) { - INIT_ADDR_STR((*dst)); - LOG(LOG_S, "new conn: fd=%d, addr=%s:%d\n", - val->pair->fd, ADDR_STR, ntohs(dst->in.sin_port)); - } return 0; } @@ -496,8 +495,8 @@ int udp_associate(struct poolhd *pool, } if (params.debug) { INIT_ADDR_STR((*dst)); - LOG(LOG_S, "udp associate: fds=%d,%d addr=%s:%d\n", - ufd, cfd, ADDR_STR, ntohs(dst->in.sin_port)); + LOG(LOG_S, "udp associate: fds=%d,%d,%d addr=%s:%d\n", + ufd, cfd, val->fd, ADDR_STR, ntohs(dst->in.sin_port)); } val->type = EV_IGNORE; val->pair = client; @@ -673,7 +672,7 @@ int on_tunnel(struct poolhd *pool, struct eval *val, return -1; } if (sn < n) { - LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd); + LOG(LOG_S, "send: %zd != %zd (fd=%d)\n", sn, n, pair->fd); assert(!(val->buff.size || val->buff.offset)); val->buff.size = n - sn;