commit c283c35a7e128d72763b7f4a925103bd0b062227 Author: Cecylia Bocovich cohosh@torproject.org Date: Thu Apr 2 12:53:10 2020 -0400
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. --- config.js | 4 +++- snowflake.js | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/config.js b/config.js index 5b8963a..3f632ca 100644 --- a/config.js +++ b/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/snowflake.js b/snowflake.js index 3baddbe..11a7801 100644 --- a/snowflake.js +++ b/snowflake.js @@ -22,6 +22,7 @@ class Snowflake { this.ui = ui; this.broker = broker; this.proxyPairs = []; + this.pollInterval = this.config.defaultBrokerPollInterval; if (void 0 === this.config.rateLimitBytes) { this.rateLimit = new DummyRateLimit(); } else { @@ -43,9 +44,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 +75,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 +157,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 +169,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.'