From a067afe6e418180da1dc5f336f3420eddb82a39b Mon Sep 17 00:00:00 2001 From: ruti <> Date: Wed, 16 Oct 2024 12:54:27 +0300 Subject: [PATCH] Restore offset in splited request --- conev.h | 13 +++++++------ desync.c | 34 ++++++++++++++++------------------ extend.c | 5 ++++- main.c | 3 ++- params.h | 1 + proxy.c | 6 +++--- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/conev.h b/conev.h index a3823ac..598cdd0 100644 --- a/conev.h +++ b/conev.h @@ -2,6 +2,7 @@ #define CONEV_H #include +#include #ifndef __linux__ #define NOEPOLL @@ -56,10 +57,10 @@ char *eid_name[] = { #endif struct buffer { - ssize_t size; - int offset; + size_t size; + unsigned int offset; char *data; - char locked; + bool locked; }; struct eval { @@ -75,11 +76,11 @@ struct eval { struct sockaddr_in6 in6; }; ssize_t recv_count; + ssize_t round_sent; unsigned int round_count; - char last_round; int attempt; - char cache; - char mark; // + bool cache; + bool mark; // }; struct poolhd { diff --git a/desync.c b/desync.c index feae490..7eac3f6 100644 --- a/desync.c +++ b/desync.c @@ -434,19 +434,19 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, char *host = 0; int len = 0, type = 0, host_pos = 0; - // parse packet - if ((len = parse_tls(buffer, n, &host))) { - type = IS_HTTPS; + if (offset == 0) { + if ((len = parse_tls(buffer, n, &host))) { + type = IS_HTTPS; + } + else if ((len = parse_http(buffer, n, &host, 0))) { + type = IS_HTTP; + } + if (len && host) { + LOG(LOG_S, "host: %.*s (%zd)\n", + len, host, host - buffer); + host_pos = host - buffer; + } } - else if ((len = parse_http(buffer, n, &host, 0))) { - type = IS_HTTP; - } - if (len && host) { - LOG(LOG_S, "host: %.*s (%zd)\n", - len, host, host - buffer); - host_pos = host - buffer; - } - // modify packet if (type == IS_HTTP && dp.mod_http) { LOG(LOG_S, "modify HTTP: n=%zd\n", n); @@ -484,9 +484,8 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, lp = pos + 5; } } - // desync #ifdef __linux__ - if (dp.drop_sack && drop_sack(sfd)) { + if (!offset && dp.drop_sack && drop_sack(sfd)) { return -1; } #endif @@ -504,15 +503,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, pos += part.s * (part.r - r); - // after EAGAIN - if (offset && pos <= offset) { + if (!(part.flag & OFFSET_START) && offset && pos <= offset) { continue; } - else if (pos < 0 || pos > n || pos < lp) { + if (pos < 0 || pos > n || pos < lp) { LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%zd\n", lp, pos, n); break; } - // send part + ssize_t s = 0; switch (part.m) { #ifdef FAKE_SUPPORT diff --git a/extend.c b/extend.c index 2e4c727..a642e92 100644 --- a/extend.c +++ b/extend.c @@ -367,8 +367,11 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote, int m = client->attempt; LOG((m ? LOG_S : LOG_L), "desync params index: %d\n", m); + ssize_t offset = client->round_sent + client->buff.offset; + if (!offset && remote->round_count) offset = -1; + sn = desync(remote->fd, buffer, bfsize, n, - 0, (struct sockaddr *)&remote->in6, m); + offset, (struct sockaddr *)&remote->in6, m); return sn; } diff --git a/main.c b/main.c index 03c1c18..3a8bb90 100644 --- a/main.c +++ b/main.c @@ -421,7 +421,8 @@ int parse_offset(struct part *part, const char *str) case 'r': part->flag |= OFFSET_RAND; break; - case 's':; + case 's': + part->flag |= OFFSET_START; } } part->pos = val; diff --git a/params.h b/params.h index 3609ed0..1fdade9 100644 --- a/params.h +++ b/params.h @@ -26,6 +26,7 @@ #define OFFSET_RAND 4 #define OFFSET_SNI 8 #define OFFSET_HOST 16 +#define OFFSET_START 32 #define DETECT_HTTP_LOCAT 1 #define DETECT_TLS_ERR 2 diff --git a/proxy.c b/proxy.c index fd6c7e4..c61ce50 100644 --- a/proxy.c +++ b/proxy.c @@ -686,13 +686,13 @@ int on_tunnel(struct poolhd *pool, struct eval *val, return -1; } val->recv_count += n; - if (!val->last_round) { + if (val->round_sent == 0) { val->round_count++; - val->last_round = 1; - pair->last_round = 0; + pair->round_sent = 0; } ssize_t sn = tcp_send_hook(pool, pair, buffer, bfsize, n); + val->round_sent += sn > 0 ? sn : 0; if (sn < n) { if (sn < 0) { uniperror("send");