[tor-commits] [snowflake/master] Added check for active pair in onopen

cohosh at torproject.org cohosh at torproject.org
Mon Aug 26 13:15:52 UTC 2019


commit 16a1b69823fd1b699a273c54dfe359d794d60220
Author: Cecylia Bocovich <cohosh at torproject.org>
Date:   Sat Aug 24 19:02:54 2019 -0400

    Added check for active pair in onopen
    
    Because the timeout makes the pair inactive, we should check for this
    state in onopen before connecting to the client. Updated tests to set
    the proxy pair to active before testing onopen. Also removed a
    redundant statement.
---
 proxy/proxypair.js           | 3 +++
 proxy/snowflake.js           | 2 --
 proxy/spec/proxypair.spec.js | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/proxy/proxypair.js b/proxy/proxypair.js
index 703ac27..fd5a39a 100644
--- a/proxy/proxypair.js
+++ b/proxy/proxypair.js
@@ -85,6 +85,9 @@ class ProxyPair {
   prepareDataChannel(channel) {
     channel.onopen = () => {
       log('WebRTC DataChannel opened!');
+      if (!this.active) {
+          return
+      }
       this.running = true;
       snowflake.state = Snowflake.MODE.WEBRTC_READY;
       snowflake.ui.setActive(true);
diff --git a/proxy/snowflake.js b/proxy/snowflake.js
index 0edb42c..cdc59fb 100644
--- a/proxy/snowflake.js
+++ b/proxy/snowflake.js
@@ -86,8 +86,6 @@ class Snowflake {
             return pair.active = false;
           }
         }), 20000); // 20 second timeout
-      } else {
-        return pair.active = false;
       }
     }, function() {
       return pair.active = false;
diff --git a/proxy/spec/proxypair.spec.js b/proxy/spec/proxypair.spec.js
index 3716f2d..f15d6d2 100644
--- a/proxy/spec/proxypair.spec.js
+++ b/proxy/spec/proxypair.spec.js
@@ -100,6 +100,7 @@ describe('ProxyPair', function() {
 
   it('connects to the relay once datachannel opens', function() {
     spyOn(pp, 'connectRelay');
+    pp.active = true;
     pp.client.onopen();
     expect(pp.connectRelay).toHaveBeenCalled();
   });



More information about the tor-commits mailing list