|
@@ -101,6 +101,7 @@ class CloseCell(RelayCell):
|
|
|
the circuit it was received on and the adjacent one."""
|
|
|
|
|
|
|
|
|
+
|
|
|
# It is intentional that VanillaCreateCircuitMsg is a RelayNetMsg and
|
|
|
# not a RelayCell. This is the message that _creates_ the circuit, so
|
|
|
# it can't be sent as a cell _within_ the circuit.
|
|
@@ -290,8 +291,9 @@ class TelescopingExtendCircuitHandler:
|
|
|
existing and new circuits together, and forwards a
|
|
|
TelescopingCreateCircuitMsg to the next hop."""
|
|
|
|
|
|
- def __init__(self, relaypicker):
|
|
|
+ def __init__(self, relaypicker, current_relay_idkey):
|
|
|
self.relaypicker = relaypicker
|
|
|
+ self.current_relay_idkey = current_relay_idkey
|
|
|
|
|
|
def received_cell(self, circhandler, cell):
|
|
|
# Remove ourselves from handling a second
|
|
@@ -302,6 +304,14 @@ class TelescopingExtendCircuitHandler:
|
|
|
# Find the SNIP corresponding to the index sent by the client
|
|
|
next_snip = self.relaypicker.pick_relay_by_uniform_index(cell.idx)
|
|
|
|
|
|
+ # Check to make sure that we aren't extending to ourselves. If we are,
|
|
|
+ # close the circuit.
|
|
|
+ if next_snip.snipdict["idkey"] == self.current_relay_idkey:
|
|
|
+ print("ERR: Client requested extending the circuit to a relay already in the path; aborting.")
|
|
|
+ circhandler.close()
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
# Allocate a new circuit id to the requested next hop
|
|
|
channelmgr = circhandler.channel.channelmgr
|
|
|
nexthopchannel = channelmgr.get_channel_to(next_snip.snipdict["addr"])
|
|
@@ -396,12 +406,15 @@ class CircuitHandler:
|
|
|
self.adjacent_circuit_handler = None
|
|
|
# The function to call when this circuit closes
|
|
|
self.closer = lambda: self.channel.circuithandlers.pop(circid)
|
|
|
+ self.is_closed = False
|
|
|
|
|
|
def close(self):
|
|
|
"""Close the circuit. Sends a CloseCell on the circuit (and its
|
|
|
adjacent circuit, if present) and closes both."""
|
|
|
adjcirchandler = self.adjacent_circuit_handler
|
|
|
self.adjacent_circuit_handler = None
|
|
|
+ self.is_closed = True
|
|
|
+ print("CLOSED CIRCUIT!!!!!!")
|
|
|
if adjcirchandler is not None:
|
|
|
adjcirchandler.adjacent_circuit_handler = None
|
|
|
self.closer()
|
|
@@ -700,7 +713,6 @@ class RelayChannelManager(ChannelManager):
|
|
|
self.send_msg(CircuitCellMsg(msg.circid,
|
|
|
VanillaCreatedCircuitCell(reply)), peeraddr)
|
|
|
elif isinstance(msg, TelescopingCreateCircuitMsg):
|
|
|
- print("LOG: Received TelescopingCreateCircuitMsg circuit message, handling.")
|
|
|
# A new circuit has arrived
|
|
|
circhandler = channel.new_circuit_with_circid(msg.circid)
|
|
|
# Create the ntor reply
|
|
@@ -714,8 +726,15 @@ class RelayChannelManager(ChannelManager):
|
|
|
# be at most one on this circuit).
|
|
|
circhandler.replace_celltype_handler(
|
|
|
TelescopingExtendCircuitCell,
|
|
|
- TelescopingExtendCircuitHandler(self.relaypicker))
|
|
|
- print("LOG: Sending TelescopingCreatedCircuitMsg circuit message")
|
|
|
+ TelescopingExtendCircuitHandler(self.relaypicker,
|
|
|
+ self.idpubkey))
|
|
|
+
|
|
|
+ # first check to make sure the circuit is still open, in case there
|
|
|
+ # were any errors when creating it
|
|
|
+ if circhandler.is_closed:
|
|
|
+ print("CIRCUIT IS CLOSED")
|
|
|
+ self.channel_send_cell(CloseCell())
|
|
|
+
|
|
|
# Send the ntor reply
|
|
|
self.send_msg(CircuitCellMsg(msg.circid,
|
|
|
TelescopingCreatedCircuitCell(reply)), peeraddr)
|