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 60beedf8 authored by Cecylia Bocovich's avatar Cecylia Bocovich

Advertise suspected NAT type to broker

This compliments the poll the rate adjustment on proxy failures to
address proxy matching issues. Since we cannot determine our NAT type
directly for browser-based proxies, we assume a restricted NAT type if
the datachannel fails to open.
parent 37f16888
......@@ -17,10 +17,12 @@ class Broker {
constructor(config) {
this.getClientOffer = this.getClientOffer.bind(this);
this._postRequest = this._postRequest.bind(this);
this.setNATType = this.setNATType.bind(this);
this.config = config;
this.url = config.brokerUrl;
this.clients = 0;
this.natType = "unknown";
if (0 === this.url.indexOf('localhost', 0)) {
// Ensure url has the right protocol + trailing slash.
this.url = 'http://' + this.url;
......@@ -64,7 +66,7 @@ class Broker {
}
};
this._xhr = xhr; // Used by spec to fake async Broker interaction
var data = {"Version": "1.1", "Sid": id, "Type": this.config.proxyType};
var data = {"Version": "1.1", "Sid": id, "Type": this.config.proxyType, "NAT": this.natType};
return this._postRequest(xhr, 'proxy', JSON.stringify(data));
});
}
......@@ -93,6 +95,10 @@ class Broker {
return this._postRequest(xhr, 'answer', JSON.stringify(data));
}
setNATType(natType) {
this.natType = natType;
}
// urlSuffix for the broker is different depending on what action
// is desired.
_postRequest(xhr, urlSuffix, payload) {
......
......@@ -13,6 +13,7 @@ class WebExtUI extends UI {
this.onMessage = this.onMessage.bind(this);
this.onDisconnect = this.onDisconnect.bind(this);
this.initStats();
this.initNATType();
chrome.runtime.onConnect.addListener(this.onConnect);
}
......@@ -25,6 +26,14 @@ class WebExtUI extends UI {
}), 60 * 60 * 1000);
}
initNATType() {
this.natType = "unknown";
// reset NAT type every 24 hours in case proxy location changed
setInterval((() => {
this.natType = "unknown";
}), 24 * 60 * 60 * 1000);
}
tryProbe() {
WS.probeWebsocket(config.relayAddr)
.then(
......
......@@ -32,4 +32,4 @@
"ws": "^3.3.1",
"xmlhttprequest": "^1.8.0"
}
}
\ No newline at end of file
}
......@@ -21,6 +21,7 @@ class Snowflake {
this.config = config;
this.ui = ui;
this.broker = broker;
this.broker.setNATType(ui.natType);
this.proxyPairs = [];
this.pollInterval = this.config.defaultBrokerPollInterval;
if (void 0 === this.config.rateLimitBytes) {
......@@ -80,6 +81,9 @@ class Snowflake {
this.pollInterval =
Math.min(this.pollInterval + this.config.pollAdjustment,
this.config.slowestBrokerPollInterval);
// assume restricted NAT
this.ui.natType = "restricted";
this.broker.setNATType(this.ui.natType);
} else {
// decrease poll interval
this.pollInterval =
......
......@@ -36,26 +36,24 @@ class FakeBroker {
return {};
});
}
setNATType(natType) {
}
}
describe('Snowflake', function() {
it('constructs correctly', function() {
var s;
s = new Snowflake(config, ui, {
fake: 'broker'
});
s = new Snowflake(config, ui, new FakeBroker());
expect(s.rateLimit).not.toBeNull();
expect(s.broker).toEqual({
fake: 'broker'
});
expect(s.broker).toEqual(new FakeBroker());
expect(s.ui).not.toBeNull();
expect(s.retries).toBe(0);
});
it('sets relay address correctly', function() {
var s;
s = new Snowflake(config, ui, null);
s = new Snowflake(config, ui, new FakeBroker());
s.setRelayAddr('foo');
expect(s.relayAddr).toEqual('foo');
});
......
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