Skip to content

Commit

Permalink
Remove delay on non-Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ruti committed Nov 19, 2024
1 parent 5e8ff5c commit 649ec06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
30 changes: 13 additions & 17 deletions desync.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "packets.h"
#include "error.h"

#define WAIT_LIMIT_MS 500


int setttl(int fd, int ttl)
{
Expand Down Expand Up @@ -80,15 +82,14 @@ static inline void delay(long ms)
};
nanosleep(&time, 0);
}
#else
#define delay(ms) Sleep(ms)
#endif

#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++) {
struct tcp_info tcpi = {};
int i = 0;
for (; params.wait_send && i < WAIT_LIMIT_MS; i++) {
struct tcp_info tcpi;
socklen_t ts = sizeof(tcpi);

if (getsockopt(sfd, IPPROTO_TCP,
Expand All @@ -98,27 +99,22 @@ static void wait_send(int sfd)
}
if (tcpi.tcpi_state != 1) {
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 < s) {
if (ts <= offsetof(struct tcp_info, tcpi_notsent_bytes)) {
LOG(LOG_E, "tcpi_notsent_bytes not provided\n");
params.wait_send = 0;
break;
}
if (tcpi.tcpi_notsent_bytes == 0) {
return;
break;
}
LOG(LOG_S, "not sent after %d ms\n", i);
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
#define wait_send(sfd) delay(params.sfdelay)
#define wait_send_if_support(sfd) // :(
#define wait_send_if_support(sfd)
#endif

static struct packet get_tcp_fake(const char *buffer, size_t n,
Expand Down Expand Up @@ -209,7 +205,7 @@ static ssize_t send_fake(int sfd, const char *buffer,
uniperror("splice");
break;
}
wait_send(sfd);
wait_send_if_support(sfd);
memcpy(p, buffer, pos);

if (setttl(sfd, params.def_ttl) < 0) {
Expand Down Expand Up @@ -305,7 +301,7 @@ static ssize_t send_fake(int sfd, const char *buffer,
break;
}
}
wait_send(sfd);
//Sleep(3);

if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer");
Expand Down
9 changes: 0 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fake_udp = {


struct params params = {
.sfdelay = 3,
.wait_send = 1,

.cache_ttl = 100800,
Expand Down Expand Up @@ -163,7 +162,6 @@ const struct option options[] = {
{"tlsrec", 1, 0, 'r'},
{"udp-fake", 1, 0, 'a'},
{"def-ttl", 1, 0, 'g'},
{"delay", 1, 0, 'w'}, //
{"not-wait-send", 0, 0, 'W'}, //
#ifdef __linux__
{"drop-sack", 0, 0, 'Y'},
Expand Down Expand Up @@ -903,13 +901,6 @@ int main(int argc, char **argv)
case 'Y':
dp->drop_sack = 1;
break;

case 'w': //
params.sfdelay = strtol(optarg, &end, 0);
if (params.sfdelay < 0 || optarg == end
|| params.sfdelay >= 1000 || *end)
invalid = 1;
break;

case 'W':
params.wait_send = 0;
Expand Down
1 change: 0 additions & 1 deletion params.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ struct desync_params {
struct params {
int dp_count;
struct desync_params *dp;
long sfdelay;
bool wait_send;
int def_ttl;
bool custom_ttl;
Expand Down

0 comments on commit 649ec06

Please sign in to comment.