[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-webext/master] Update proxy NAT type based on client's NAT type



commit 12478006b99805c30a2d278c969937563ce507e1
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Mon Jun 22 14:29:09 2020 -0400

    Update proxy NAT type based on client's NAT type
---
 broker.js           |  4 ++--
 snowflake.js        | 12 ++++++++----
 spec/broker.spec.js |  6 +++---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/broker.js b/broker.js
index e1aab0f..9d8b8b6 100644
--- a/broker.js
+++ b/broker.js
@@ -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));
     });
   }
diff --git a/snowflake.js b/snowflake.js
index 91a8d87..1937fdb 100644
--- a/snowflake.js
+++ b/snowflake.js
@@ -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
diff --git a/spec/broker.spec.js b/spec/broker.spec.js
index 28a66c4..cedf5f9 100644
--- a/spec/broker.spec.js
+++ b/spec/broker.spec.js
@@ -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');

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits