Browse Source

re-try building circuits if an error occured, until we get a good one

Chelsea H. Komlo 4 years ago
parent
commit
127308c2b4
1 changed files with 13 additions and 6 deletions
  1. 13 6
      client.py

+ 13 - 6
client.py

@@ -291,12 +291,19 @@ class ClientChannelManager(relay.ChannelManager):
 
     def new_circuit(self):
         """Create a new circuit from this client."""
-        if network.thenetwork.womode == network.WOMode.VANILLA:
-            return self.new_circuit_vanilla()
-        elif network.thenetwork.womode == network.WOMode.TELESCOPING:
-            return self.new_circuit_telescoping()
-        elif network.thenetwork.womode == network.WOMode.SINGLEPASS:
-            sys.exit("NOT YET IMPLEMENTED")
+        circhandler = None
+
+        # If an error occured, circhandler will still be None, so we should
+        # try again.
+        while circhandler is None:
+            if network.thenetwork.womode == network.WOMode.VANILLA:
+                circhandler = self.new_circuit_vanilla()
+            elif network.thenetwork.womode == network.WOMode.TELESCOPING:
+                circhandler = self.new_circuit_telescoping()
+            elif network.thenetwork.womode == network.WOMode.SINGLEPASS:
+                sys.exit("NOT YET IMPLEMENTED")
+
+        return circhandler
 
     def received_msg(self, msg, peeraddr, channel):
         """Callback when a NetMsg not specific to a circuit is