Selaa lähdekoodia

close circuit in case of error or repeated relays for single-pass

Chelsea H. Komlo 4 vuotta sitten
vanhempi
commit
07ddcd9e09
1 muutettua tiedostoa jossa 12 lisäystä ja 11 poistoa
  1. 12 11
      relay.py

+ 12 - 11
relay.py

@@ -536,7 +536,7 @@ class SinglePassCreatedRelayHandler:
         self.ttl = ttl
 
     def received_cell(self, circhandler, cell):
-        logging.debug("Handle a SinglePassCreatedCircuitCell received by a relay")
+        logging.debug("Handle a SinglePassCreatedCircuitCell received by a relay, my ttl is %s", str(self.ttl))
         # Remove ourselves from handling a second
         # SinglePassCreatedCircuitCell on this circuit
         circhandler.replace_celltype_handler(SinglePassCreatedCircuitCell, None)
@@ -944,15 +944,13 @@ class RelayChannelManager(ChannelManager):
                 SinglePassCreatedCircuitCell(reply, None, None, 0)), peeraddr)
 
         elif isinstance(msg, SinglePassCreateCircuitMsg) and msg.ttl > 0:
+            logging.debug("RelayChannelManager: Single-Pass TTL is greater than 0; extending")
+
             # A new circuit has arrived
             circhandler = channel.new_circuit_with_circid(msg.circid)
 
-            # because the ttl is greater than 0, we need to extend the circuit. To do this, we
-            # need to derive the client's blinded keys, deterministically
-            # select the next relay in the circuit, etc.
-            logging.debug("RelayChannelManager: Single-Pass TTL is greater than 0; extending")
-
-            # Create the ntor reply for the circuit-extension key
+            # Create the ntor reply for the circuit-extension key, and derive
+            # the client's next blinded key
             (ntorreply, secret), blinded_client_encr_key = NTor.reply(self.onionkey, self.idpubkey,
                     msg.ntor_request, self.perfstats,  b'circuit')
 
@@ -972,14 +970,17 @@ class RelayChannelManager(ChannelManager):
             logging.debug("RelayChannelManager: Unimplemented! need to pick the next relay using the shared secret between the client and the relay.")
 
             # simpulate the VRF output for now
-            vrf_output = VRF(self.onionkey,
+            vrf_output = VRF(self.path_selection_key,
                     self.relaypicker).get_output(idx_as_hex)
 
             next_hop = self.relaypicker.pick_relay_by_uniform_index(vrf_output.output)
             logging.debug("WARNING: Unimplemented! Need to validate next hop is not null or ourselves, if it is, we should send a CLOSE cell.")
-            while next_hop == None or next_hop.snipdict["idkey"] == self.idpubkey or next_hop.snipdict["addr"] == peeraddr:
-                idx = self.relaypicker.pick_weighted_relay_index()
-                next_hop = self.relaypicker.pick_relay_by_uniform_index(idx)
+            if next_hop == None:
+                logging.debug("Client requested extending the circuit to a relay index that results in None, aborting. my circid: %s", str(circhandler.circid))
+                circhandler.close()
+            elif next_hop.snipdict["idkey"] == self.idpubkey or next_hop.snipdict["addr"] == peeraddr:
+                logging.debug("Client requested extending the circuit to a relay already in the path; aborting. my circid: %s", str(circhandler.circid))
+                circhandler.close()
 
             # Allocate a new circuit id to the requested next hop
             channelmgr = circhandler.channel.channelmgr