GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit c283c35a authored by Cecylia Bocovich's avatar Cecylia Bocovich

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.
parent 4c28d98f
......@@ -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;
......
......@@ -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.'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment