Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion proxy/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ 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;

Config.prototype.maxNumClients = 1;

Expand Down
25 changes: 18 additions & 7 deletions proxy/snowflake.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Snowflake {
this.ui = ui;
this.broker = broker;
this.proxyPairs = [];
this.failures = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this variable anywhere?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks. Looks like I forgot to remove that.

this.pollInterval = this.config.defaultBrokerPollInterval;
if (void 0 === this.config.rateLimitBytes) {
this.rateLimit = new DummyRateLimit();
} else {
Expand All @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should this really be beginWebRTC() and not pollBroker()?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be beginWebRTC() since we want to call setTimeout() recusively.

}), this.pollInterval);
}

// Regularly poll Broker for clients to serve until this snowflake is
Expand Down Expand Up @@ -74,9 +76,19 @@ 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);
}
}), 20000); // 20 second timeout
return;
}), this.config.datachannelTimeout);
}, function() {
//on error, close proxy pair
return pair.close();
Expand Down Expand Up @@ -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());
Expand All @@ -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.'
Expand Down