|
@@ -64,14 +64,14 @@ class VanillaCreatedExtendedHandler:
|
|
|
circhandler.send_cell(circextendmsg)
|
|
|
|
|
|
class TelescopingCreatedHandler:
|
|
|
- """A handler for TelescopingCreatedCircuitCell cells."""
|
|
|
+ """A handler for TelescopingCreatedCircuitCell cells; this will only always
|
|
|
+ communicate with the client's guard."""
|
|
|
|
|
|
- def __init__(self, channelmgr, ntor, guarddesc):
|
|
|
+ def __init__(self, channelmgr, ntor):
|
|
|
self.channelmgr = channelmgr
|
|
|
self.ntor = ntor
|
|
|
- self.guarddesc = guarddesc
|
|
|
- self.onionkey = guarddesc.snipdict['onionkey']
|
|
|
- self.idkey = guarddesc.snipdict['idkey']
|
|
|
+ self.onionkey = self.channelmgr.guard.snipdict['onionkey']
|
|
|
+ self.idkey = self.channelmgr.guard.snipdict['idkey']
|
|
|
|
|
|
def received_cell(self, circhandler, cell):
|
|
|
print("LOG: Received cell in TelescopingCreatedHandler")
|
|
@@ -81,13 +81,72 @@ class TelescopingCreatedHandler:
|
|
|
deckey = nacl.hash.sha256(secret + b'downstream')
|
|
|
circhandler.add_crypt_layer(enckey, deckey)
|
|
|
|
|
|
+ nexthopidx = None
|
|
|
+ while nexthopidx is None:
|
|
|
+ nexthopidx = self.channelmgr.relaypicker.pick_weighted_relay_index()
|
|
|
+ print("WARNING: Unimplemented! Need to check if this idx is in the list of circhandlers idxs")
|
|
|
+
|
|
|
+ # Construct the VanillaExtendCircuitCell
|
|
|
+ ntor = relay.NTor(self.channelmgr.perfstats)
|
|
|
+ ntor_request = ntor.request()
|
|
|
+ circextendmsg = relay.TelescopingExtendCircuitCell(
|
|
|
+ nexthopidx, ntor_request)
|
|
|
+
|
|
|
+ # Set up the reply handler
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
+ relay.TelescopingExtendedCircuitCell,
|
|
|
+ TelescopingExtendedHandler(self.channelmgr, ntor))
|
|
|
+
|
|
|
+ # Send the cell
|
|
|
+ circhandler.send_cell(circextendmsg)
|
|
|
+
|
|
|
+
|
|
|
+class TelescopingExtendedHandler:
|
|
|
+ """A handler for TelescopingExtendedCircuitCell cells."""
|
|
|
+
|
|
|
+ def __init__(self, channelmgr, ntor):
|
|
|
+ self.channelmgr = channelmgr
|
|
|
+ self.ntor = ntor
|
|
|
+
|
|
|
+ def received_cell(self, circhandler, cell):
|
|
|
+ print("LOG: Received cell in TelescopingExtendedHandler")
|
|
|
+
|
|
|
+ #TODO verify the SNIP that was received
|
|
|
+ # Bail if it is invalid
|
|
|
+
|
|
|
+ onionkey = cell.snip.snipdict['onionkey']
|
|
|
+ idkey = cell.snip.snipdict['idkey']
|
|
|
+
|
|
|
+ secret = self.ntor.verify(cell.ntor_reply, onionkey, idkey)
|
|
|
+ enckey = nacl.hash.sha256(secret + b'upstream')
|
|
|
+ deckey = nacl.hash.sha256(secret + b'downstream')
|
|
|
+ circhandler.add_crypt_layer(enckey, deckey)
|
|
|
+
|
|
|
+
|
|
|
# Are we done building the circuit?
|
|
|
+ print("WARNING: we may need another circhandler structure for snips")
|
|
|
if len(circhandler.circuit_descs) == 3:
|
|
|
# Yes!
|
|
|
return
|
|
|
|
|
|
- sys.exit("Err: Unimplemented! Need to implement circuit extension for telescoping.")
|
|
|
+ nexthopidx = None
|
|
|
+ while nexthopidx is None:
|
|
|
+ nexthopidx = self.channelmgr.relaypicker.pick_weighted_relay_index()
|
|
|
+ print("WARNING: Unimplemented! Need to check if this idx is in the list of circhandlers idxs")
|
|
|
|
|
|
+ # Construct the VanillaExtendCircuitCell
|
|
|
+ ntor = relay.NTor(self.channelmgr.perfstats)
|
|
|
+ ntor_request = ntor.request()
|
|
|
+ circextendmsg = relay.TelescopingExtendCircuitCell(
|
|
|
+ nexthopidx, ntor_request)
|
|
|
+
|
|
|
+ # Set up the reply handler
|
|
|
+ circhandler.replace_celltype_handler(
|
|
|
+ relay.TelescopingExtendedCircuitCell,
|
|
|
+ TelescopingExtendedHandler(self.channelmgr, ntor))
|
|
|
+
|
|
|
+ # Send the cell
|
|
|
+ circhandler.send_cell(circextendmsg)
|
|
|
|
|
|
class ClientChannelManager(relay.ChannelManager):
|
|
|
"""The subclass of ChannelManager for clients."""
|
|
@@ -209,7 +268,7 @@ class ClientChannelManager(relay.ChannelManager):
|
|
|
# Set up the reply handler
|
|
|
circhandler.replace_celltype_handler(
|
|
|
relay.TelescopingCreatedCircuitCell,
|
|
|
- TelescopingCreatedHandler(self, ntor, self.guard))
|
|
|
+ TelescopingCreatedHandler(self, ntor))
|
|
|
|
|
|
# Send the message
|
|
|
guardchannel.send_msg(circcreatemsg)
|