|
|
@@ -190,8 +190,8 @@ class VanillaExtendCircuitHandler:
|
|
|
circhandler.replace_celltype_handler(VanillaExtendCircuitCell, None)
|
|
|
|
|
|
# Allocate a new circuit id to the requested next hop
|
|
|
- cellhandler = circhandler.channel.cellhandler
|
|
|
- nexthopchannel = cellhandler.get_channel_to(cell.hopaddr)
|
|
|
+ channelmgr = circhandler.channel.channelmgr
|
|
|
+ nexthopchannel = channelmgr.get_channel_to(cell.hopaddr)
|
|
|
newcircid, newcirchandler = nexthopchannel.new_circuit()
|
|
|
|
|
|
# Connect the existing and new circuits together
|
|
|
@@ -279,7 +279,7 @@ class CircuitHandler:
|
|
|
if isinstance(cell, EncryptedCell):
|
|
|
cell = self.crypt_layer.decrypt_msg(cell)
|
|
|
|
|
|
- print("CircuitHandler: %s received cell %s on circuit %d from %s" % (self.channel.cellhandler.myaddr, cell, self.circid, self.channel.peer.cellhandler.myaddr))
|
|
|
+ print("CircuitHandler: %s received cell %s on circuit %d from %s" % (self.channel.channelmgr.myaddr, cell, self.circid, self.channel.peer.channelmgr.myaddr))
|
|
|
|
|
|
# If it's still encrypted, it's for sure meant for forwarding to
|
|
|
# our adjacent hop, which had better exist.
|
|
|
@@ -294,13 +294,13 @@ class CircuitHandler:
|
|
|
elif isinstance(cell, StringCell):
|
|
|
# Default handler; just print the message in the cell
|
|
|
print("CircuitHandler: %s received '%s' on circuit %d from %s" \
|
|
|
- % (self.channel.cellhandler.myaddr, cell,
|
|
|
- self.circid, self.channel.peer.cellhandler.myaddr))
|
|
|
+ % (self.channel.channelmgr.myaddr, cell,
|
|
|
+ self.circid, self.channel.peer.channelmgr.myaddr))
|
|
|
else:
|
|
|
# I don't know how to handle this cell?
|
|
|
raise ValueError("CircuitHandler: %s received unknown cell type %s on circuit %d from %s" \
|
|
|
- % (self.channel.cellhandler.myaddr, cell,
|
|
|
- self.circid, self.channel.peer.cellhandler.myaddr))
|
|
|
+ % (self.channel.channelmgr.myaddr, cell,
|
|
|
+ self.circid, self.channel.peer.channelmgr.myaddr))
|
|
|
|
|
|
def replace_celltype_handler(self, celltype, handler):
|
|
|
"""Add an object with a received_cell(circhandler, cell) method
|
|
|
@@ -325,8 +325,8 @@ class Channel(network.Connection):
|
|
|
client or a relay, transporting cells from various circuits."""
|
|
|
def __init__(self):
|
|
|
super().__init__()
|
|
|
- # The CellRelay managing this Channel
|
|
|
- self.cellhandler = None
|
|
|
+ # The RelayChannelManager managing this Channel
|
|
|
+ self.channelmgr = None
|
|
|
# The Channel at the other end
|
|
|
self.peer = None
|
|
|
# The function to call when the connection closes
|
|
|
@@ -376,21 +376,21 @@ class Channel(network.Connection):
|
|
|
|
|
|
def send_msg(self, msg):
|
|
|
"""Send the given NetMsg on the channel."""
|
|
|
- self.cellhandler.perfstats.bytes_sent += msg.size()
|
|
|
- self.peer.received(self.cellhandler.myaddr, msg)
|
|
|
+ self.channelmgr.perfstats.bytes_sent += msg.size()
|
|
|
+ self.peer.received(self.channelmgr.myaddr, msg)
|
|
|
|
|
|
def received(self, peeraddr, msg):
|
|
|
"""Callback when a message is received from the network."""
|
|
|
- print('Channel: %s received %s from %s' % (self.cellhandler.myaddr, msg, peeraddr))
|
|
|
- self.cellhandler.perfstats.bytes_received += msg.size()
|
|
|
+ print('Channel: %s received %s from %s' % (self.channelmgr.myaddr, msg, peeraddr))
|
|
|
+ self.channelmgr.perfstats.bytes_received += msg.size()
|
|
|
if isinstance(msg, CircuitCellMsg):
|
|
|
circid, cell = msg.circid, msg.cell
|
|
|
self.circuithandlers[circid].received_cell(cell)
|
|
|
else:
|
|
|
- self.cellhandler.received_msg(msg, peeraddr, self)
|
|
|
+ self.channelmgr.received_msg(msg, peeraddr, self)
|
|
|
|
|
|
|
|
|
-class CellHandler:
|
|
|
+class ChannelManager:
|
|
|
"""The class that manages the channels to other relays and clients.
|
|
|
Relays and clients both use subclasses of this class to both create
|
|
|
on-demand channels to relays, to gracefully handle the closing of
|
|
|
@@ -419,7 +419,7 @@ class CellHandler:
|
|
|
if peeraddr in self.channels:
|
|
|
self.channels[peeraddr].close()
|
|
|
|
|
|
- channel.cellhandler = self
|
|
|
+ channel.channelmgr = self
|
|
|
self.channels[peeraddr] = channel
|
|
|
channel.closer = lambda: self.channels.pop(peeraddr)
|
|
|
|
|
|
@@ -434,18 +434,18 @@ class CellHandler:
|
|
|
self.perfstats)
|
|
|
self.channels[addr] = newchannel
|
|
|
newchannel.closer = lambda: self.channels.pop(addr)
|
|
|
- newchannel.cellhandler = self
|
|
|
+ newchannel.channelmgr = self
|
|
|
|
|
|
return newchannel
|
|
|
|
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
|
received."""
|
|
|
- print("CellHandler: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
+ print("ChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
|
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
|
"""Callback with a circuit-specific cell is received."""
|
|
|
- print("CellHandler: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
+ print("ChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
|
|
|
def send_msg(self, msg, peeraddr):
|
|
|
"""Send a message to the peer with the given address."""
|
|
|
@@ -459,8 +459,8 @@ class CellHandler:
|
|
|
channel.send_cell(circid, cell)
|
|
|
|
|
|
|
|
|
-class CellRelay(CellHandler):
|
|
|
- """The subclass of CellHandler for relays."""
|
|
|
+class RelayChannelManager(ChannelManager):
|
|
|
+ """The subclass of ChannelManager for relays."""
|
|
|
|
|
|
def __init__(self, myaddr, dirauthaddrs, onionprivkey, idpubkey, perfstats):
|
|
|
super().__init__(myaddr, dirauthaddrs, perfstats)
|
|
|
@@ -479,7 +479,7 @@ class CellRelay(CellHandler):
|
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
|
received."""
|
|
|
- print("CellRelay: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
+ print("RelayChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
if isinstance(msg, RelayRandomHopMsg):
|
|
|
if msg.ttl > 0:
|
|
|
# Pick a random next hop from the consensus
|
|
|
@@ -510,7 +510,7 @@ class CellRelay(CellHandler):
|
|
|
|
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
|
"""Callback with a circuit-specific cell is received."""
|
|
|
- print("CellRelay: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
+ print("RelayChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
return super().received_cell(circid, cell, peeraddr, channel)
|
|
|
|
|
|
|
|
|
@@ -540,8 +540,8 @@ class Relay(network.Server):
|
|
|
network.thenetwork.wantepochticks(self, True, end=True)
|
|
|
network.thenetwork.wantepochticks(self, True)
|
|
|
|
|
|
- # Create the CellRelay connection manager
|
|
|
- self.cellhandler = CellRelay(self.netaddr, dirauthaddrs,
|
|
|
+ # Create the RelayChannelManager connection manager
|
|
|
+ self.channelmgr = RelayChannelManager(self.netaddr, dirauthaddrs,
|
|
|
self.onionkey, self.idkey.verify_key, self.perfstats)
|
|
|
|
|
|
# Initially, we're not a fallback relay
|
|
|
@@ -564,7 +564,7 @@ class Relay(network.Server):
|
|
|
self.uploaddesc(False)
|
|
|
|
|
|
# Close connections to other relays
|
|
|
- self.cellhandler.terminate()
|
|
|
+ self.channelmgr.terminate()
|
|
|
|
|
|
# Stop listening to our own bound port
|
|
|
self.close()
|
|
|
@@ -578,7 +578,7 @@ class Relay(network.Server):
|
|
|
# Download the new consensus, which will have been created
|
|
|
# already since the dirauths' epoch_ending callbacks happened
|
|
|
# before the relays'.
|
|
|
- self.cellhandler.get_consensus()
|
|
|
+ self.channelmgr.get_consensus()
|
|
|
|
|
|
def newepoch(self, epoch):
|
|
|
self.uploaddesc()
|
|
|
@@ -607,7 +607,7 @@ class Relay(network.Server):
|
|
|
descmsg = dirauth.DirAuthDelDescMsg(desc)
|
|
|
|
|
|
# Upload them
|
|
|
- for a in self.cellhandler.dirauthaddrs:
|
|
|
+ for a in self.channelmgr.dirauthaddrs:
|
|
|
c = network.thenetwork.connect(self, a, self.perfstats)
|
|
|
c.sendmsg(descmsg)
|
|
|
c.close()
|
|
|
@@ -632,8 +632,8 @@ class Relay(network.Server):
|
|
|
ourchannel.peer = peerchannel
|
|
|
ourchannel.next_circid = 1
|
|
|
|
|
|
- # Add our channel to the CellRelay
|
|
|
- self.cellhandler.add_channel(ourchannel, peer)
|
|
|
+ # Add our channel to the RelayChannelManager
|
|
|
+ self.channelmgr.add_channel(ourchannel, peer)
|
|
|
|
|
|
return peerchannel
|
|
|
|
|
|
@@ -675,18 +675,18 @@ if __name__ == '__main__':
|
|
|
|
|
|
print('ticked; epoch=', network.thenetwork.getepoch())
|
|
|
|
|
|
- relays[3].cellhandler.send_msg(RelayRandomHopMsg(30), relays[5].netaddr)
|
|
|
+ relays[3].channelmgr.send_msg(RelayRandomHopMsg(30), relays[5].netaddr)
|
|
|
|
|
|
# See what channels exist and do a consistency check
|
|
|
for r in relays:
|
|
|
- print("%s: %s" % (r.netaddr, [ str(k) for k in r.cellhandler.channels.keys()]))
|
|
|
+ print("%s: %s" % (r.netaddr, [ str(k) for k in r.channelmgr.channels.keys()]))
|
|
|
raddr = r.netaddr
|
|
|
- for ad, ch in r.cellhandler.channels.items():
|
|
|
- if ch.peer.cellhandler.myaddr != ad:
|
|
|
- print('address mismatch:', raddr, ad, ch.peer.cellhandler.myaddr)
|
|
|
+ for ad, ch in r.channelmgr.channels.items():
|
|
|
+ if ch.peer.channelmgr.myaddr != ad:
|
|
|
+ print('address mismatch:', raddr, ad, ch.peer.channelmgr.myaddr)
|
|
|
|
|
|
- if ch.peer.cellhandler.channels[raddr].peer is not ch:
|
|
|
- print('asymmetry:', raddr, ad, ch, ch.peer.cellhandler.channels[raddr].peer)
|
|
|
+ if ch.peer.channelmgr.channels[raddr].peer is not ch:
|
|
|
+ print('asymmetry:', raddr, ad, ch, ch.peer.channelmgr.channels[raddr].peer)
|
|
|
|
|
|
# Stop some relays
|
|
|
relays[3].terminate()
|
|
|
@@ -703,20 +703,20 @@ if __name__ == '__main__':
|
|
|
|
|
|
# See what channels exist and do a consistency check
|
|
|
for r in relays:
|
|
|
- print("%s: %s" % (r.netaddr, [ str(k) for k in r.cellhandler.channels.keys()]))
|
|
|
+ print("%s: %s" % (r.netaddr, [ str(k) for k in r.channelmgr.channels.keys()]))
|
|
|
raddr = r.netaddr
|
|
|
- for ad, ch in r.cellhandler.channels.items():
|
|
|
- if ch.peer.cellhandler.myaddr != ad:
|
|
|
- print('address mismatch:', raddr, ad, ch.peer.cellhandler.myaddr)
|
|
|
+ for ad, ch in r.channelmgr.channels.items():
|
|
|
+ if ch.peer.channelmgr.myaddr != ad:
|
|
|
+ print('address mismatch:', raddr, ad, ch.peer.channelmgr.myaddr)
|
|
|
|
|
|
- if ch.peer.cellhandler.channels[raddr].peer is not ch:
|
|
|
- print('asymmetry:', raddr, ad, ch, ch.peer.cellhandler.channels[raddr].peer)
|
|
|
+ if ch.peer.channelmgr.channels[raddr].peer is not ch:
|
|
|
+ print('asymmetry:', raddr, ad, ch, ch.peer.channelmgr.channels[raddr].peer)
|
|
|
|
|
|
- channel = relays[3].cellhandler.get_channel_to(relays[5].netaddr)
|
|
|
+ channel = relays[3].channelmgr.get_channel_to(relays[5].netaddr)
|
|
|
circid, circhandler = channel.new_circuit()
|
|
|
- peerchannel = relays[5].cellhandler.get_channel_to(relays[3].netaddr)
|
|
|
+ peerchannel = relays[5].channelmgr.get_channel_to(relays[3].netaddr)
|
|
|
peerchannel.new_circuit_with_circid(circid)
|
|
|
- relays[3].cellhandler.send_cell(circid, StringCell("test"), relays[5].netaddr)
|
|
|
+ relays[3].channelmgr.send_cell(circid, StringCell("test"), relays[5].netaddr)
|
|
|
|
|
|
idpubkey = dirauth.DirAuth.consensus.consdict["relays"][1].descdict["idkey"]
|
|
|
onionpubkey = dirauth.DirAuth.consensus.consdict["relays"][1].descdict["onionkey"]
|