Просмотр исходного кода

add guard selection mechanism for walking onions; just get random relay for the time being

Chelsea H. Komlo 4 лет назад
Родитель
Сommit
661becb8c0
1 измененных файлов с 30 добавлено и 0 удалено
  1. 30 0
      client.py

+ 30 - 0
client.py

@@ -93,6 +93,14 @@ class ClientChannelManager(relay.ChannelManager):
                 self.guard = self.relaypicker.pick_weighted_relay()
                 self.guardaddr = self.guard.descdict['addr']
 
+            self.test_guard_connection()
+
+            if self.guardaddr is not None:
+                break
+
+        print('chose guard=', self.guardaddr)
+
+    def test_guard_connection(self):
             # Connect to the guard
             try:
                 self.get_channel_to(self.guardaddr)
@@ -101,6 +109,24 @@ class ClientChannelManager(relay.ChannelManager):
                 self.guardaddr = None
                 self.guard = None
 
+    def ensure_guard_walking_onions(self):
+        """Ensure we have a channel to a guard (Walking Onions version).
+
+        For the first implementation, we assume an out-of-band mechanism
+        that just simply hands us a guard; we don't count the number of
+        operations or bandwidth as this operation in practice occurs
+        infrequently."""
+
+        while True:
+            if self.guardaddr is None:
+                #randomly-sample a guard
+                print("DANGER: Unimplemented- guard should be selected from any relays.")
+                self.guard = self.relaypicker.pick_weighted_relay()
+                # here, we have a SNIP instead of a relay descriptor
+                self.guardaddr = self.guard.snipdict['addr']
+
+            self.test_guard_connection()
+
             if self.guardaddr is not None:
                 break
 
@@ -110,6 +136,10 @@ class ClientChannelManager(relay.ChannelManager):
         """Ensure that we have a channel to a guard."""
         if network.thenetwork.womode == network.WOMode.VANILLA:
             self.ensure_guard_vanilla()
+            return
+        # At this point, we are either in Telescoping or Single-Pass mode
+
+        self.ensure_guard_walking_onions()
 
     def new_circuit_vanilla(self):
         """Create a new circuit from this client. (Vanilla Onion Routing