--tr to group

This commit is contained in:
ruti 2024-03-28 01:52:52 +03:00
parent a71def353b
commit dbbdb005a1
3 changed files with 46 additions and 38 deletions

26
main.c
View File

@ -306,17 +306,6 @@ void clear_params(void)
mem_destroy(params.mempool); mem_destroy(params.mempool);
params.mempool = 0; params.mempool = 0;
} }
if (params.spos) {
for (int i = 0; i < params.spos_n; i++) {
struct spos s = params.spos[i];
if (s.data != 0) {
free(s.data);
s.data = 0;;
}
}
free(params.spos);
params.spos = 0;
}
if (params.dp) { if (params.dp) {
for (int i = 0; i < params.dp_count; i++) { for (int i = 0; i < params.dp_count; i++) {
struct desync_params s = params.dp[i]; struct desync_params s = params.dp[i];
@ -328,6 +317,17 @@ void clear_params(void)
free(s.parts); free(s.parts);
s.parts = 0; s.parts = 0;
} }
if (s.spos) {
for (int x = 0; x < s.spos_n; x++) {
struct spos p = s.spos[x];
if (p.data != 0) {
free(p.data);
p.data = 0;;
}
}
free(s.spos);
s.spos = 0;
}
} }
free(params.dp); free(params.dp);
params.dp = 0; params.dp = 0;
@ -495,8 +495,8 @@ int main(int argc, char **argv)
break; break;
case 'P':; case 'P':;
struct spos *spos = add((void *)&params.spos, struct spos *spos = add((void *)&dp->spos,
&params.spos_n, sizeof(struct spos)); &dp->spos_n, sizeof(struct spos));
if (!spos) { if (!spos) {
clear_params(); clear_params();
return -1; return -1;

View File

@ -49,6 +49,8 @@ struct desync_params {
int mod_http; int mod_http;
int tlsrec_n; int tlsrec_n;
struct part *tlsrec; struct part *tlsrec;
int spos_n;
struct spos *spos;
}; };
struct params { struct params {
@ -63,8 +65,6 @@ struct params {
char tfo; char tfo;
unsigned int timeout; unsigned int timeout;
long cache_ttl; long cache_ttl;
int spos_n;
struct spos *spos;
char ipv6; char ipv6;
char resolve; char resolve;
int max_open; int max_open;

34
proxy.c
View File

@ -582,7 +582,8 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
LOG(LOG_E, "ss: invalid version: 0x%x (%lu)\n", *buffer, n); LOG(LOG_E, "ss: invalid version: 0x%x (%lu)\n", *buffer, n);
return -1; return -1;
} }
int m = mode_add_get(&dst, -1); int m = mode_add_get(
(struct sockaddr_ina *)&val->pair->in6, -1);
if (m >= 0) { if (m >= 0) {
val->attempt = m; val->attempt = m;
} }
@ -592,11 +593,15 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
} }
int try_again(struct poolhd *pool, struct eval *val) int try_again(struct poolhd *pool, struct eval *val, char data)
{ {
struct eval *client = val->pair; struct eval *client = val->pair;
int m = client->attempt + 1; int m = client->attempt + 1;
if (!data) for (; m < params.dp_count; m++) {
struct desync_params dp = params.dp[m];
if (!dp.spos_n) break;
}
if (m >= params.dp_count) { if (m >= params.dp_count) {
mode_add_get( mode_add_get(
(struct sockaddr_ina *)&val->in6, 0); (struct sockaddr_ina *)&val->in6, 0);
@ -615,10 +620,13 @@ int try_again(struct poolhd *pool, struct eval *val)
} }
char find_bad_data(char *buffer, ssize_t n) int find_bad_data(char *buffer, ssize_t n, int m)
{ {
for (int i = 0; i < params.spos_n; i++) { for (; m < params.dp_count; m++) {
struct spos bad_data = params.spos[i]; struct desync_params dp = params.dp[m];
for (int i = 0; i < dp.spos_n; i++) {
struct spos bad_data = dp.spos[i];
if (bad_data.start >= n) { if (bad_data.start >= n) {
continue; continue;
} }
@ -629,7 +637,8 @@ char find_bad_data(char *buffer, ssize_t n)
char *found = memmem(buffer + bad_data.start, char *found = memmem(buffer + bad_data.start,
end - bad_data.start, bad_data.data, bad_data.size); end - bad_data.start, bad_data.data, bad_data.size);
if (found) { if (found) {
return 1; return m;
}
} }
} }
return 0; return 0;
@ -651,13 +660,13 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
break; break;
default: return -1; default: return -1;
} }
return try_again(pool, val); return try_again(pool, val, 0);
} }
// //
char found_bd = find_bad_data(buffer, n); int d = find_bad_data(buffer, n, val->pair->attempt + 1);
if (found_bd && if (d) {
!try_again(pool, val)) { val->pair->attempt = d - 1;
return 0; return try_again(pool, val, 1);
} }
struct eval *pair = val->pair; struct eval *pair = val->pair;
@ -680,8 +689,7 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
int m = pair->attempt; int m = pair->attempt;
if ((m == 0 && val->attempt < 0) if ((m == 0 && val->attempt < 0)
|| (m && m == val->attempt) || (m && m == val->attempt)) {
|| found_bd) {
return 0; return 0;
} }
if (m == 0) { if (m == 0) {