mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Restore offset in splited request
This commit is contained in:
parent
721e5808fb
commit
a067afe6e4
13
conev.h
13
conev.h
@ -2,6 +2,7 @@
|
||||
#define CONEV_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#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 {
|
||||
|
34
desync.c
34
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
|
||||
|
5
extend.c
5
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;
|
||||
}
|
||||
|
||||
|
3
main.c
3
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;
|
||||
|
1
params.h
1
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
|
||||
|
6
proxy.c
6
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");
|
||||
|
Loading…
Reference in New Issue
Block a user