Browse Source

add path selection key to relay descriptor and as attribute

Chelsea H. Komlo 4 years ago
parent
commit
e3d35770c9
2 changed files with 19 additions and 0 deletions
  1. 5 0
      client.py
  2. 14 0
      relay.py

+ 5 - 0
client.py

@@ -141,6 +141,11 @@ class TelescopingExtendedHandler:
 
         nexthopidx = None
         while nexthopidx is None:
+            # Relays make sure that when the extend to a relay, they are not
+            # extending to themselves. So here, we just need to make sure that
+            # this ID is not the same as the guard ID, to protect against the
+            # guard and exit being the same relay
+            print("WARNING: Unimplemented! Need to check that sampled ID is not the same as the guard.")
             nexthopidx = self.channelmgr.relaypicker.pick_weighted_relay_index()
             logging.warning("Unimplemented! Need to check if this idx is in the list of circhandlers idxs")
 

+ 14 - 0
relay.py

@@ -878,6 +878,11 @@ class RelayChannelManager(ChannelManager):
         elif isinstance(msg, SinglePassCreateCircuitMsg):
             # A new circuit has arrived
             circhandler = channel.new_circuit_with_circid(msg.circid)
+            # Create the ntor reply using Sphinx
+            #TODO what is the correct domain seperater here to indicate using
+            #Sphinx?
+            reply, secret = NTor.reply(self.onionkey, self.idpubkey,
+                    msg.ntor_request, self.perfstats,  b'data')
             sys.exit("have not yet implemented circuit handling for single-pass in relays")
         else:
             return super().received_msg(msg, peeraddr, channel)
@@ -921,6 +926,11 @@ class Relay(network.Server):
         # Initially, we're not a fallback relay
         self.is_fallbackrelay = False
 
+        if network.thenetwork.womode == network.WOMode.SINGLEPASS:
+            self.path_selection_key = nacl.public.PrivateKey.generate()
+        else:
+            self.path_selection_key = None
+
         self.uploaddesc()
 
     def terminate(self):
@@ -967,6 +977,10 @@ class Relay(network.Server):
         descdict["addr"] = self.netaddr
         descdict["bw"] = self.bw
         descdict["flags"] = self.flags
+
+        if network.thenetwork.womode == network.WOMode.SINGLEPASS:
+            descdict["path_selection_key"] = self.path_selection_key
+
         desc = dirauth.RelayDescriptor(descdict)
         desc.sign(self.idkey, self.perfstats)
         dirauth.RelayDescriptor.verify(desc, self.perfstats)