From 076da4264b4c8ec379a4e81c6a427b4425c6f7ba Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 4 Feb 2026 22:35:40 +0300 Subject: [PATCH] Fix: ACK section length calculation and increase socket buffers --- src/etcp.c | 29 +++++++++++++++-------------- src/etcp_connections.c | 12 +++++++++++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/etcp.c b/src/etcp.c index 82b49c47..071ba564 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -744,20 +744,21 @@ void etcp_conn_input(struct ETCP_DGRAM* pkt) { // Process sections as per protocol.txt switch (type) { - case ETCP_SECTION_ACK: { - int elm_cnt=data[1]; - uint32_t till=data[2] | (data[3]<<8) | (data[4]<<16) | (data[5]<<24); - data+=6; - for (int i=0; irx_ack_till-till<0) { etcp->rx_ack_till++; etcp_ack_recv(etcp, etcp->rx_ack_till, -1, -1); }// подтверждаем всё по till - break; - } + case ETCP_SECTION_ACK: { + int elm_cnt=data[1]; + uint32_t till=data[2] | (data[3]<<8) | (data[4]<<16) | (data[5]<<24); + int ack_section_len = 6 + elm_cnt * 8; + data+=ack_section_len; + len-=ack_section_len; + for (int i=0; irx_ack_till-till)<0) { etcp->rx_ack_till++; etcp_ack_recv(etcp, etcp->rx_ack_till, -1, -1); }// подтверждаем всё по till + break; + } case ETCP_SECTION_PAYLOAD: { if (len>=5) { diff --git a/src/etcp_connections.c b/src/etcp_connections.c index cb400e64..c9ec09dc 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -274,7 +274,17 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka if (setsockopt(e_sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) { DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_REUSEADDR: %s", strerror(errno)); } - + + // Increase socket buffers for high throughput + int sndbuf = 4 * 1024 * 1024; // 4MB send buffer + int rcvbuf = 4 * 1024 * 1024; // 4MB receive buffer + if (setsockopt(e_sock->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) { + DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_SNDBUF: %s", strerror(errno)); + } + if (setsockopt(e_sock->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) < 0) { + DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_RCVBUF: %s", strerror(errno)); + } + int flags = fcntl(e_sock->fd, F_GETFL, 0); fcntl(e_sock->fd, F_SETFL, flags | O_NONBLOCK);