From d26ddb9a0724091f6e86a230f6010182ba58302f Mon Sep 17 00:00:00 2001 From: Masaq- Date: Sun, 2 Apr 2017 02:42:23 +0000 Subject: [PATCH 1/4] add fine-tuning option -J to set delay variance factor --- src/client.c | 2 +- src/client.h | 1 + src/iodine.c | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/client.c b/src/client.c index 8d0e642..fcda275 100644 --- a/src/client.c +++ b/src/client.c @@ -209,7 +209,7 @@ update_server_timeout(int handshake) } /* update up/down window timeouts to something reasonable */ - this.downstream_timeout_ms = rtt_ms * 2; + this.downstream_timeout_ms = rtt_ms * this.downstream_delay_variance / 100; this.outbuf->timeout = ms_to_timeval(this.downstream_timeout_ms); if (handshake) { diff --git a/src/client.h b/src/client.h index f6750a1..2aea61b 100644 --- a/src/client.h +++ b/src/client.h @@ -88,6 +88,7 @@ struct client_instance { /* Server response timeout in ms and downstream window timeout */ time_t server_timeout_ms; time_t downstream_timeout_ms; + time_t downstream_delay_variance; int autodetect_server_timeout; /* Cumulative Round-Trip-Time in ms */ diff --git a/src/iodine.c b/src/iodine.c index de55af4..646a0ed 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -82,6 +82,7 @@ struct client_instance this; .next_downstream_ack = -1, \ .num_immediate = 1, \ .rtt_total_ms = 200, \ + .downstream_delay_variance = 200, \ .remote_forward_addr = {.ss_family = AF_UNSPEC} static struct client_instance preset_default = { @@ -217,7 +218,7 @@ print_usage() extern char *__progname; fprintf(stderr, "Usage: %s [-v] [-h] [-Y preset] [-V sec] [-X port] [-f] [-r] [-u user] [-t chrootdir] [-d device] " - "[-w downfrags] [-W upfrags] [-i sec -j sec] [-I sec] [-c 0|1] [-C 0|1] [-s ms] " + "[-w downfrags] [-W upfrags] [-i sec -j sec] [-I sec] [-J var] [-c 0|1] [-C 0|1] [-s ms] " "[-P password] [-m maxfragsize] [-M maxlen] [-T type] [-O enc] [-L 0|1] [-R port[,host] ] " "[-z context] [-F pidfile] topdomain [nameserver1 [nameserver2 [...]]]\n", __progname); } @@ -264,6 +265,7 @@ help() fprintf(stderr, " -W upstream fragment window size (default: 8 frags)\n"); fprintf(stderr, " -i server-side request timeout in lazy mode (default: auto)\n"); fprintf(stderr, " -j downstream fragment ACK timeout, implies -i4 (default: 2 sec)\n"); + fprintf(stderr, " -J downstream fragment ACK delay variance factor (default: 2.0)\n"); //fprintf(stderr, " --nodrop disable TCP packet-dropping optimisations\n"); fprintf(stderr, " -c 1: use downstream compression (default), 0: disable\n"); fprintf(stderr, " -C 1: use upstream compression (default), 0: disable\n\n"); @@ -419,7 +421,7 @@ main(int argc, char **argv) * This is so that all options override preset values regardless of order in command line */ int optind_orig = optind, preset_id = -1; - static char *iodine_args_short = "46vfDhrY:s:V:c:C:i:j:u:t:d:R:P:w:W:m:M:F:T:O:L:I:"; + static char *iodine_args_short = "46vfDhrY:s:V:c:C:i:j:J:u:t:d:R:P:w:W:m:M:F:T:O:L:I:"; while ((choice = getopt_long(argc, argv, iodine_args_short, iodine_args, NULL))) { /* Check if preset has been found yet so we don't process any other options */ @@ -573,6 +575,9 @@ main(int argc, char **argv) this.server_timeout_ms = 4000; } break; + case 'J': + this.downstream_delay_variance = strtod(optarg, NULL) * 100; + break; case 's': this.send_interval_ms = atoi(optarg); if (this.send_interval_ms < 0) @@ -691,6 +696,11 @@ main(int argc, char **argv) usage(); } + if (this.downstream_delay_variance < 10) { + warnx("Delay variance factor must be more than 0.1 to prevent excessive retransmits."); + usage(); + } + if (!this.lazymode && this.max_timeout_ms > 1000) { fprintf(stderr, "Warning: Target interval of >1 second in immediate mode will cause high latency.\n"); } From d10bea1607dfb7906849ea2ef5fea8d92705122c Mon Sep 17 00:00:00 2001 From: Masaq- Date: Sun, 2 Apr 2017 16:29:19 +0000 Subject: [PATCH 2/4] store the delay variance factor in a double --- src/client.c | 2 +- src/client.h | 2 +- src/iodine.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client.c b/src/client.c index fcda275..29b2bb1 100644 --- a/src/client.c +++ b/src/client.c @@ -209,7 +209,7 @@ update_server_timeout(int handshake) } /* update up/down window timeouts to something reasonable */ - this.downstream_timeout_ms = rtt_ms * this.downstream_delay_variance / 100; + this.downstream_timeout_ms = rtt_ms * this.downstream_delay_variance; this.outbuf->timeout = ms_to_timeval(this.downstream_timeout_ms); if (handshake) { diff --git a/src/client.h b/src/client.h index 2aea61b..6d1f013 100644 --- a/src/client.h +++ b/src/client.h @@ -88,7 +88,7 @@ struct client_instance { /* Server response timeout in ms and downstream window timeout */ time_t server_timeout_ms; time_t downstream_timeout_ms; - time_t downstream_delay_variance; + double downstream_delay_variance; int autodetect_server_timeout; /* Cumulative Round-Trip-Time in ms */ diff --git a/src/iodine.c b/src/iodine.c index 646a0ed..ab389d9 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -82,7 +82,7 @@ struct client_instance this; .next_downstream_ack = -1, \ .num_immediate = 1, \ .rtt_total_ms = 200, \ - .downstream_delay_variance = 200, \ + .downstream_delay_variance = 2.0, \ .remote_forward_addr = {.ss_family = AF_UNSPEC} static struct client_instance preset_default = { @@ -576,7 +576,7 @@ main(int argc, char **argv) } break; case 'J': - this.downstream_delay_variance = strtod(optarg, NULL) * 100; + this.downstream_delay_variance = strtod(optarg, NULL); break; case 's': this.send_interval_ms = atoi(optarg); @@ -696,7 +696,7 @@ main(int argc, char **argv) usage(); } - if (this.downstream_delay_variance < 10) { + if (this.downstream_delay_variance < 0.1) { warnx("Delay variance factor must be more than 0.1 to prevent excessive retransmits."); usage(); } From 1cbe94667660acbe4244b8014ea45789a422e895 Mon Sep 17 00:00:00 2001 From: Masaq- Date: Mon, 3 Apr 2017 20:22:34 +0000 Subject: [PATCH 3/4] recalculate timeout in immediate mode also --- src/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.c b/src/client.c index 29b2bb1..6730a46 100644 --- a/src/client.c +++ b/src/client.c @@ -322,7 +322,7 @@ got_response(int id, int immediate, int fail) this.rtt_total_ms += rtt_ms; this.num_immediate++; - if (this.autodetect_server_timeout && this.lazymode) + if (this.autodetect_server_timeout) update_server_timeout(0); } From 0d937847154b13725ae718abf4b9b07d9b924242 Mon Sep 17 00:00:00 2001 From: Masaq- Date: Fri, 9 Jun 2017 03:50:46 +0000 Subject: [PATCH 4/4] option (-J0) to autodetect delay variance factor --- src/client.c | 11 ++++++++++- src/client.h | 1 + src/iodine.c | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/client.c b/src/client.c index 6730a46..343d2fb 100644 --- a/src/client.c +++ b/src/client.c @@ -285,6 +285,7 @@ got_response(int id, int immediate, int fail) { struct timeval now, rtt; time_t rtt_ms; + static time_t rtt_min_ms = 1; gettimeofday(&now, NULL); QTRACK_DEBUG(4, "Got answer id %d (%s)%s", id, immediate ? "immediate" : "lazy", @@ -322,8 +323,16 @@ got_response(int id, int immediate, int fail) this.rtt_total_ms += rtt_ms; this.num_immediate++; - if (this.autodetect_server_timeout) + if (this.autodetect_server_timeout) { + if (this.autodetect_delay_variance) { + if (rtt_ms > 0 && (rtt_ms < rtt_min_ms || 1 == rtt_min_ms)) { + rtt_min_ms = rtt_ms; + } + this.downstream_delay_variance = (double) (this.rtt_total_ms / + this.num_immediate) / rtt_min_ms; + } update_server_timeout(0); + } } /* Remove query info from buffer to mark it as answered */ diff --git a/src/client.h b/src/client.h index 6d1f013..6a3645e 100644 --- a/src/client.h +++ b/src/client.h @@ -90,6 +90,7 @@ struct client_instance { time_t downstream_timeout_ms; double downstream_delay_variance; int autodetect_server_timeout; + int autodetect_delay_variance; /* Cumulative Round-Trip-Time in ms */ time_t rtt_total_ms; diff --git a/src/iodine.c b/src/iodine.c index ab389d9..0de74a2 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -83,6 +83,7 @@ struct client_instance this; .num_immediate = 1, \ .rtt_total_ms = 200, \ .downstream_delay_variance = 2.0, \ + .autodetect_delay_variance = 0, \ .remote_forward_addr = {.ss_family = AF_UNSPEC} static struct client_instance preset_default = { @@ -265,7 +266,7 @@ help() fprintf(stderr, " -W upstream fragment window size (default: 8 frags)\n"); fprintf(stderr, " -i server-side request timeout in lazy mode (default: auto)\n"); fprintf(stderr, " -j downstream fragment ACK timeout, implies -i4 (default: 2 sec)\n"); - fprintf(stderr, " -J downstream fragment ACK delay variance factor (default: 2.0)\n"); + fprintf(stderr, " -J downstream fragment ACK delay variance factor (default: 2.0), 0: auto\n"); //fprintf(stderr, " --nodrop disable TCP packet-dropping optimisations\n"); fprintf(stderr, " -c 1: use downstream compression (default), 0: disable\n"); fprintf(stderr, " -C 1: use upstream compression (default), 0: disable\n\n"); @@ -577,6 +578,10 @@ main(int argc, char **argv) break; case 'J': this.downstream_delay_variance = strtod(optarg, NULL); + if (0.0 == this.downstream_delay_variance) { + this.autodetect_delay_variance = 1; + this.downstream_delay_variance = 2.0; + } break; case 's': this.send_interval_ms = atoi(optarg);