| 
														
															@@ -789,13 +789,17 @@ class ChannelManager: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 class RelayChannelManager(ChannelManager): 
														 | 
														
														 | 
														
															 class RelayChannelManager(ChannelManager): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     """The subclass of ChannelManager for relays.""" 
														 | 
														
														 | 
														
															     """The subclass of ChannelManager for relays.""" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    def __init__(self, myaddr, dirauthaddrs, onionprivkey, idpubkey, perfstats): 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    def __init__(self, myaddr, dirauthaddrs, onionprivkey, idpubkey, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            path_selection_key, perfstats): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         super().__init__(myaddr, dirauthaddrs, perfstats) 
														 | 
														
														 | 
														
															         super().__init__(myaddr, dirauthaddrs, perfstats) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         self.onionkey = onionprivkey 
														 | 
														
														 | 
														
															         self.onionkey = onionprivkey 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         self.idpubkey = idpubkey 
														 | 
														
														 | 
														
															         self.idpubkey = idpubkey 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         if network.thenetwork.womode != network.WOMode.VANILLA: 
														 | 
														
														 | 
														
															         if network.thenetwork.womode != network.WOMode.VANILLA: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             self.endive = None 
														 | 
														
														 | 
														
															             self.endive = None 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if network.thenetwork.womode == network.WOMode.SINGLEPASS: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            self.path_selection_key = path_selection_key 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     def get_consensus(self): 
														 | 
														
														 | 
														
															     def get_consensus(self): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         """Download a fresh consensus (and ENDIVE if using Walking 
														 | 
														
														 | 
														
															         """Download a fresh consensus (and ENDIVE if using Walking 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         Onions) from a random dirauth.""" 
														 | 
														
														 | 
														
															         Onions) from a random dirauth.""" 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -879,7 +883,7 @@ class RelayChannelManager(ChannelManager): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # A new circuit has arrived 
														 | 
														
														 | 
														
															             # A new circuit has arrived 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             circhandler = channel.new_circuit_with_circid(msg.circid) 
														 | 
														
														 | 
														
															             circhandler = channel.new_circuit_with_circid(msg.circid) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # Create the ntor reply for the circuit-extension key 
														 | 
														
														 | 
														
															             # Create the ntor reply for the circuit-extension key 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            reply, secret = NTor.reply(self.onionkey, self.idpubkey, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            (reply, secret), blinded_client_pubkey = NTor.reply(self.onionkey, self.idpubkey, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     msg.ntor_request, self.perfstats,  b'circuit') 
														 | 
														
														 | 
														
															                     msg.ntor_request, self.perfstats,  b'circuit') 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # Set up the circuit to use the shared secret established from the 
														 | 
														
														 | 
														
															             # Set up the circuit to use the shared secret established from the 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -892,22 +896,38 @@ class RelayChannelManager(ChannelManager): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # the following: 
														 | 
														
														 | 
														
															             # the following: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # 1. determining the next relay using the client's path selection 
														 | 
														
														 | 
														
															             # 1. determining the next relay using the client's path selection 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             #    key in conjunction with our own 
														 | 
														
														 | 
														
															             #    key in conjunction with our own 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            print("server path selection key: " + str(self.path_selection_key)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            print("client path selection key: " + 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    str(msg.client_path_selection_key)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            idx = nacl.public.Box(self.path_selection_key, msg.client_path_selection_key).shared_key() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            sys.exit("TODO convert shared secret into integer type modulo alpha") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            nexthop = self.relaypicker.pick_relay_by_uniform_index(idx) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if nexthop == None: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                print("WARNING: Unimplemented! Need to validate next hop is not null, if it is, we should send a CLOSE cell.") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # 2. blinding each of the client's public keys to send to the next 
														 | 
														
														 | 
														
															             # 2. blinding each of the client's public keys to send to the next 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             #    hop. 
														 | 
														
														 | 
														
															             #    hop. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # Add a handler for once the next relay replies to say that the 
														 | 
														
														 | 
														
															             # Add a handler for once the next relay replies to say that the 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # circuit has been created 
														 | 
														
														 | 
														
															             # circuit has been created 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             # be at most one on this circuit). 
														 | 
														
														 | 
														
															             # be at most one on this circuit). 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            # TODO add the proper interface for the handler 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            circhandler.replace_celltype_handler( 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    SinglePassCreatedCircuitCell, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    SinglePassCreatedCircuitHandler()) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            # Send the next create message to the next hop 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            # TODO add the correct interface here 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            self.send_msg(CircuitCellMsg(msg.circid, 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    SinglePassCreateCircuitCell()), peeraddr) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            circhandler.replace_celltype_handler( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#                    SinglePassCreatedCircuitCell, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#                    SinglePassCreatedCircuitHandler(ntorreply, next_snip)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+# 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            # Allocate a new circuit id to the requested next hop 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            channelmgr = circhandler.channel.channelmgr 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            nexthopchannel = channelmgr.get_channel_to(next_snip.snipdict["addr"]) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            newcircid, newcirchandler = nexthopchannel.new_circuit() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+# 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            # Send the next create message to the next hop 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            # TODO add the correct interface here 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#            self.send_msg(CircuitCellMsg(msg.circid, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#                    SinglePassCreateCircuitCell(newcircid, ntorrequest, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+#                        next_client_path_selection_key)), peeraddr) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+# 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             sys.exit("have not yet implemented circuit handling for single-pass in relays") 
														 | 
														
														 | 
														
															             sys.exit("have not yet implemented circuit handling for single-pass in relays") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         else: 
														 | 
														
														 | 
														
															         else: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             return super().received_msg(msg, peeraddr, channel) 
														 | 
														
														 | 
														
															             return super().received_msg(msg, peeraddr, channel) 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -944,18 +964,18 @@ class Relay(network.Server): 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         network.thenetwork.wantepochticks(self, True, end=True) 
														 | 
														
														 | 
														
															         network.thenetwork.wantepochticks(self, True, end=True) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         network.thenetwork.wantepochticks(self, True) 
														 | 
														
														 | 
														
															         network.thenetwork.wantepochticks(self, True) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if network.thenetwork.womode == network.WOMode.SINGLEPASS: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            self.path_selection_key = nacl.public.PrivateKey.generate() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        else: 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            self.path_selection_key = None 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         # Create the RelayChannelManager connection manager 
														 | 
														
														 | 
														
															         # Create the RelayChannelManager connection manager 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         self.channelmgr = RelayChannelManager(self.netaddr, dirauthaddrs, 
														 | 
														
														 | 
														
															         self.channelmgr = RelayChannelManager(self.netaddr, dirauthaddrs, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                self.onionkey, self.idkey.verify_key, self.perfstats) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                self.onionkey, self.idkey.verify_key, self.path_selection_key, self.perfstats) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															         # Initially, we're not a fallback relay 
														 | 
														
														 | 
														
															         # Initially, we're not a fallback relay 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         self.is_fallbackrelay = False 
														 | 
														
														 | 
														
															         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() 
														 | 
														
														 | 
														
															         self.uploaddesc() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     def terminate(self): 
														 | 
														
														 | 
														
															     def terminate(self): 
														 |