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

[tor-commits] [snowflake/master] Remove "active" property of proxyPairs



commit 789285e0dfe69474b2876a79f82784ad2892d8c4
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Fri Oct 18 17:28:53 2019 -0400

    Remove "active" property of proxyPairs
    
    Use their existence in the proxy pair list to indicate they are active.
---
 proxy/proxypair.js |  9 ---------
 proxy/snowflake.js | 58 +++++++++++++++++++++++-------------------------------
 2 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/proxy/proxypair.js b/proxy/proxypair.js
index 64eafdc..52594e9 100644
--- a/proxy/proxypair.js
+++ b/proxy/proxypair.js
@@ -85,9 +85,6 @@ class ProxyPair {
   prepareDataChannel(channel) {
     channel.onopen = () => {
       log('WebRTC DataChannel opened!');
-      if (!this.active) {
-        return;
-      }
       snowflake.ui.setActive(true);
       // This is the point when the WebRTC datachannel is done, so the next step
       // is to establish websocket to the server.
@@ -179,17 +176,13 @@ class ProxyPair {
     if (this.webrtcIsReady()) {
       this.client.close();
     }
-    this.client = null;
     if (this.peerConnOpen()) {
       this.pc.close();
     }
-    this.pc = null;
     if (this.relayIsReady()) {
       this.relay.close();
     }
-    this.relay = null;
     this.onCleanup();
-    this.active = false;
   }
 
   flush() {
@@ -253,8 +246,6 @@ ProxyPair.prototype.relay = null; // websocket
 
 ProxyPair.prototype.timer = 0;
 
-ProxyPair.prototype.active = false; // Whether serving a client.
-
 ProxyPair.prototype.flush_timeout_id = null;
 
 ProxyPair.prototype.onCleanup = null;
diff --git a/proxy/snowflake.js b/proxy/snowflake.js
index c647b4e..c914520 100644
--- a/proxy/snowflake.js
+++ b/proxy/snowflake.js
@@ -43,10 +43,6 @@ class Snowflake {
   // Initialize WebRTC PeerConnection, which requires beginning the signalling
   // process. |pollBroker| automatically arranges signalling.
   beginWebRTC() {
-    log('ProxyPair Slots: ' + this.proxyPairs.length);
-    log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
-      return p.id;
-    })).join(' | '));
     this.pollBroker();
     return this.pollInterval = setInterval((() => {
       return this.pollBroker();
@@ -58,13 +54,13 @@ class Snowflake {
   pollBroker() {
     var msg, pair, recv;
     // Poll broker for clients.
-    pair = this.nextAvailableProxyPair();
+    pair = this.makeProxyPair();
     if (!pair) {
       log('At client capacity.');
       return;
     }
+    log('Polling broker..');
     // Do nothing until a new proxyPair is available.
-    pair.active = true;
     msg = 'Polling for client ... ';
     if (this.retries > 0) {
       msg += '[retries: ' + this.retries + ']';
@@ -72,35 +68,23 @@ class Snowflake {
     this.ui.setStatus(msg);
     recv = this.broker.getClientOffer(pair.id);
     recv.then((desc) => {
-      if (pair.active) {
-        if (!this.receiveOffer(pair, desc)) {
-          return pair.active = false;
-        }
-        //set a timeout for channel creation
-        return setTimeout((() => {
-          if (!pair.webrtcIsReady()) {
-            log('proxypair datachannel timed out waiting for open');
-            pair.close();
-            return pair.active = false;
-          }
-        }), 20000); // 20 second timeout
+      if (!this.receiveOffer(pair, desc)) {
+        return pair.close();
       }
+      //set a timeout for channel creation
+      return setTimeout((() => {
+        if (!pair.webrtcIsReady()) {
+          log('proxypair datachannel timed out waiting for open');
+          return pair.close();
+        }
+      }), 20000); // 20 second timeout
     }, function() {
-      return pair.active = false;
+      //on error, close proxy pair
+      return pair.close();
     });
     return this.retries++;
   }
 
-  // Returns the first ProxyPair that's available to connect.
-  nextAvailableProxyPair() {
-    if (this.proxyPairs.length < this.config.connectionsPerClient) {
-      return this.makeProxyPair(this.relayAddr);
-    }
-    return this.proxyPairs.find(function(pp) {
-      return !pp.active;
-    });
-  }
-
   receiveOffer(pair, desc) {
     var e, offer, sdp;
     try {
@@ -127,19 +111,27 @@ class Snowflake {
       return pair.pc.setLocalDescription(sdp).catch(fail);
     };
     fail = function() {
-      pair.active = false
+      pair.close();
       return dbg('webrtc: Failed to create or set Answer');
     };
     return pair.pc.createAnswer().then(next).catch(fail);
   }
 
-  makeProxyPair(relay) {
+  makeProxyPair() {
+    if (this.proxyPairs.length >= this.config.connectionsPerClient) {
+      return null;
+    }
     var pair;
-    pair = new ProxyPair(relay, this.rateLimit, this.config.pcConfig);
+    pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config.pcConfig);
     this.proxyPairs.push(pair);
+
+    log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
+      return p.id;
+    })).join(' | '));
+
     pair.onCleanup = () => {
       var ind;
-      // Delete from the list of active proxy pairs.
+      // Delete from the list of proxy pairs.
       ind = this.proxyPairs.indexOf(pair);
       if (ind > -1) {
         return this.proxyPairs.splice(ind, 1);



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