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

Update proxy NAT type based on client's NAT type

parent 60beedf8
......@@ -52,7 +52,7 @@ class Broker {
case Broker.CODE.OK:
var response = JSON.parse(xhr.responseText);
if (response.Status == Broker.STATUS.MATCH) {
return fulfill(response.Offer); // Should contain offer.
return fulfill(response); // Should contain offer.
} else if (response.Status == Broker.STATUS.TIMEOUT) {
return reject(Broker.MESSAGE.TIMEOUT);
} else {
......@@ -66,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, "NAT": this.natType};
var data = {"Version": "1.2", "Sid": id, "Type": this.config.proxyType, "NAT": this.natType};
return this._postRequest(xhr, 'proxy', JSON.stringify(data));
});
}
......
......@@ -68,8 +68,9 @@ class Snowflake {
}
this.ui.setStatus(msg);
recv = this.broker.getClientOffer(pair.id);
recv.then((desc) => {
if (!this.receiveOffer(pair, desc)) {
recv.then((resp) => {
var clientNAT = resp.NAT;
if (!this.receiveOffer(pair, resp.Offer)) {
return pair.close();
}
//set a timeout for channel creation
......@@ -81,8 +82,11 @@ class Snowflake {
this.pollInterval =
Math.min(this.pollInterval + this.config.pollAdjustment,
this.config.slowestBrokerPollInterval);
// assume restricted NAT
this.ui.natType = "restricted";
// if we fail to connect to a restricted client, assume restricted NAT
if (clientNAT == "restricted"){
this.ui.natType = "restricted";
console.log("Learned NAT type: restricted");
}
this.broker.setNATType(this.ui.natType);
} else {
// decrease poll interval
......
......@@ -40,14 +40,14 @@ describe('Broker', function() {
spyOn(b, '_postRequest').and.callFake(function() {
b._xhr.readyState = b._xhr.DONE;
b._xhr.status = Broker.CODE.OK;
b._xhr.responseText = '{"Status":"client match","Offer":"fake offer"}';
b._xhr.responseText = '{"Status":"client match","Offer":"fake offer","NAT":"unknown"}';
return b._xhr.onreadystatechange();
});
poll = b.getClientOffer();
expect(poll).not.toBeNull();
expect(b._postRequest).toHaveBeenCalled();
return poll.then(function(desc) {
expect(desc).toEqual('fake offer');
return poll.then(function(resp) {
expect(resp.Offer).toEqual('fake offer');
return done();
}).catch(function() {
fail('should not reject on Broker.CODE.OK');
......
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