Remove delay on non-Linux

This commit is contained in:
ruti 2024-11-19 04:21:02 +03:00
parent 5e8ff5ca19
commit 649ec06a85
3 changed files with 13 additions and 27 deletions

View file

@ -31,6 +31,8 @@
#include "packets.h" #include "packets.h"
#include "error.h" #include "error.h"
#define WAIT_LIMIT_MS 500
int setttl(int fd, int ttl) int setttl(int fd, int ttl)
{ {
@ -80,15 +82,14 @@ static inline void delay(long ms)
}; };
nanosleep(&time, 0); nanosleep(&time, 0);
} }
#else
#define delay(ms) Sleep(ms)
#endif #endif
#ifdef __linux__ #ifdef __linux__
static void wait_send(int sfd) static void wait_send_if_support(int sfd)
{ {
for (int i = 0; params.wait_send && i < 500; i++) { int i = 0;
struct tcp_info tcpi = {}; for (; params.wait_send && i < WAIT_LIMIT_MS; i++) {
struct tcp_info tcpi;
socklen_t ts = sizeof(tcpi); socklen_t ts = sizeof(tcpi);
if (getsockopt(sfd, IPPROTO_TCP, if (getsockopt(sfd, IPPROTO_TCP,
@ -98,27 +99,22 @@ static void wait_send(int sfd)
} }
if (tcpi.tcpi_state != 1) { if (tcpi.tcpi_state != 1) {
LOG(LOG_E, "state: %d\n", tcpi.tcpi_state); LOG(LOG_E, "state: %d\n", tcpi.tcpi_state);
return; break;
} }
size_t s = (char *)&tcpi.tcpi_notsent_bytes - (char *)&tcpi.tcpi_state; if (ts <= offsetof(struct tcp_info, tcpi_notsent_bytes)) {
if (ts < s) {
LOG(LOG_E, "tcpi_notsent_bytes not provided\n"); LOG(LOG_E, "tcpi_notsent_bytes not provided\n");
params.wait_send = 0; params.wait_send = 0;
break; break;
} }
if (tcpi.tcpi_notsent_bytes == 0) { if (tcpi.tcpi_notsent_bytes == 0) {
return; break;
} }
LOG(LOG_S, "not sent after %d ms\n", i);
delay(1); delay(1);
} }
delay(params.sfdelay); if (i) LOG(LOG_S, "waiting for send: %d ms\n", i);
} }
#define wait_send_if_support(sfd) \
if (params.wait_send) wait_send(sfd)
#else #else
#define wait_send(sfd) delay(params.sfdelay) #define wait_send_if_support(sfd)
#define wait_send_if_support(sfd) // :(
#endif #endif
static struct packet get_tcp_fake(const char *buffer, size_t n, static struct packet get_tcp_fake(const char *buffer, size_t n,
@ -209,7 +205,7 @@ static ssize_t send_fake(int sfd, const char *buffer,
uniperror("splice"); uniperror("splice");
break; break;
} }
wait_send(sfd); wait_send_if_support(sfd);
memcpy(p, buffer, pos); memcpy(p, buffer, pos);
if (setttl(sfd, params.def_ttl) < 0) { if (setttl(sfd, params.def_ttl) < 0) {
@ -305,7 +301,7 @@ static ssize_t send_fake(int sfd, const char *buffer,
break; break;
} }
} }
wait_send(sfd); //Sleep(3);
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer"); uniperror("SetFilePointer");

9
main.c
View file

@ -39,7 +39,6 @@ fake_udp = {
struct params params = { struct params params = {
.sfdelay = 3,
.wait_send = 1, .wait_send = 1,
.cache_ttl = 100800, .cache_ttl = 100800,
@ -163,7 +162,6 @@ const struct option options[] = {
{"tlsrec", 1, 0, 'r'}, {"tlsrec", 1, 0, 'r'},
{"udp-fake", 1, 0, 'a'}, {"udp-fake", 1, 0, 'a'},
{"def-ttl", 1, 0, 'g'}, {"def-ttl", 1, 0, 'g'},
{"delay", 1, 0, 'w'}, //
{"not-wait-send", 0, 0, 'W'}, // {"not-wait-send", 0, 0, 'W'}, //
#ifdef __linux__ #ifdef __linux__
{"drop-sack", 0, 0, 'Y'}, {"drop-sack", 0, 0, 'Y'},
@ -903,13 +901,6 @@ int main(int argc, char **argv)
case 'Y': case 'Y':
dp->drop_sack = 1; dp->drop_sack = 1;
break; break;
case 'w': //
params.sfdelay = strtol(optarg, &end, 0);
if (params.sfdelay < 0 || optarg == end
|| params.sfdelay >= 1000 || *end)
invalid = 1;
break;
case 'W': case 'W':
params.wait_send = 0; params.wait_send = 0;

View file

@ -98,7 +98,6 @@ struct desync_params {
struct params { struct params {
int dp_count; int dp_count;
struct desync_params *dp; struct desync_params *dp;
long sfdelay;
bool wait_send; bool wait_send;
int def_ttl; int def_ttl;
bool custom_ttl; bool custom_ttl;