From 256f33f2b395502b0b3a66a821af07dc27c7252a Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Thu, 2 Apr 2020 12:20:42 -0400 Subject: [PATCH 1/2] Move proxy datachannel timeout value to config --- proxy/config.js | 3 +++ proxy/snowflake.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy/config.js b/proxy/config.js index 39c2b15..5b8963a 100644 --- a/proxy/config.js +++ b/proxy/config.js @@ -26,6 +26,9 @@ Config.prototype.rateLimitHistory = 5.0; Config.prototype.defaultBrokerPollInterval = 300.0 * 1000; +// Timeout after sending answer before datachannel is opened +Config.prototype.datachannelTimeout = 20 * 1000; + Config.prototype.maxNumClients = 1; Config.prototype.proxyType = ""; diff --git a/proxy/snowflake.js b/proxy/snowflake.js index 0e9730e..3baddbe 100644 --- a/proxy/snowflake.js +++ b/proxy/snowflake.js @@ -76,7 +76,7 @@ class Snowflake { log('proxypair datachannel timed out waiting for open'); return pair.close(); } - }), 20000); // 20 second timeout + }), this.config.datachannelTimeout); }, function() { //on error, close proxy pair return pair.close(); From 3d8e04966523f373bd9d7bc09c5712c4c99f36c6 Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Thu, 2 Apr 2020 12:53:10 -0400 Subject: [PATCH 2/2] Dynamically adjust proxy poll interval If the proxy succeeds in opening a datachannel to the client, decrease the poll interval. If they fail, increase the poll interval. This will cause less reliable/more restrictive proxies to poll less frequently. --- proxy/config.js | 4 +++- proxy/snowflake.js | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/proxy/config.js b/proxy/config.js index 5b8963a..3f632ca 100644 --- a/proxy/config.js +++ b/proxy/config.js @@ -24,7 +24,9 @@ Config.prototype.minRateLimit = 10 * 1024; Config.prototype.rateLimitHistory = 5.0; -Config.prototype.defaultBrokerPollInterval = 300.0 * 1000; +Config.prototype.defaultBrokerPollInterval = 300.0 * 1000; //1 poll every 5 minutes +Config.prototype.slowestBrokerPollInterval = 6 * 60 * 60.0 * 1000; //1 poll every 6 hours +Config.prototype.pollAdjustment = 300.0 * 1000; // Timeout after sending answer before datachannel is opened Config.prototype.datachannelTimeout = 20 * 1000; diff --git a/proxy/snowflake.js b/proxy/snowflake.js index 3baddbe..ba96d99 100644 --- a/proxy/snowflake.js +++ b/proxy/snowflake.js @@ -22,6 +22,8 @@ class Snowflake { this.ui = ui; this.broker = broker; this.proxyPairs = []; + this.failures = 0; + this.pollInterval = this.config.defaultBrokerPollInterval; if (void 0 === this.config.rateLimitBytes) { this.rateLimit = new DummyRateLimit(); } else { @@ -43,9 +45,9 @@ class Snowflake { // process. |pollBroker| automatically arranges signalling. beginWebRTC() { this.pollBroker(); - return this.pollInterval = setInterval((() => { - return this.pollBroker(); - }), this.config.defaultBrokerPollInterval); + return this.pollTimeout = setTimeout((() => { + return this.beginWebRTC() + }), this.pollInterval); } // Regularly poll Broker for clients to serve until this snowflake is @@ -74,8 +76,18 @@ class Snowflake { return setTimeout((() => { if (!pair.webrtcIsReady()) { log('proxypair datachannel timed out waiting for open'); - return pair.close(); + pair.close(); + // increase poll interval + this.pollInterval = + Math.min(this.pollInterval + this.config.pollAdjustment, + this.config.slowestBrokerPollInterval); + } else { + // decrease poll interval + this.pollInterval = + Math.max(this.pollInterval - this.config.pollAdjustment, + this.config.defaultBrokerPollInterval); } + return; }), this.config.datachannelTimeout); }, function() { //on error, close proxy pair @@ -146,7 +158,7 @@ class Snowflake { disable() { var results; log('Disabling Snowflake.'); - clearInterval(this.pollInterval); + clearTimeout(this.pollTimeout); results = []; while (this.proxyPairs.length > 0) { results.push(this.proxyPairs.pop().close()); @@ -158,7 +170,6 @@ class Snowflake { Snowflake.prototype.relayAddr = null; Snowflake.prototype.rateLimit = null; -Snowflake.prototype.pollInterval = null; Snowflake.MESSAGE = { CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'