|
@@ -3,6 +3,7 @@
|
|
import random # For simulation, not cryptography!
|
|
import random # For simulation, not cryptography!
|
|
import math
|
|
import math
|
|
import sys
|
|
import sys
|
|
|
|
+import logging
|
|
|
|
|
|
import nacl.utils
|
|
import nacl.utils
|
|
import nacl.signing
|
|
import nacl.signing
|
|
@@ -446,7 +447,7 @@ class TelescopingExtendCircuitHandler:
|
|
# Check to make sure that we aren't extending to ourselves. If we are,
|
|
# Check to make sure that we aren't extending to ourselves. If we are,
|
|
# close the circuit.
|
|
# close the circuit.
|
|
if next_snip.snipdict["idkey"] == self.current_relay_idkey:
|
|
if next_snip.snipdict["idkey"] == self.current_relay_idkey:
|
|
- print("ERR: Client requested extending the circuit to a relay already in the path; aborting. my circid: " + str(circhandler.circid))
|
|
|
|
|
|
+ logging.debug("Client requested extending the circuit to a relay already in the path; aborting. my circid: %s", str(circhandler.circid))
|
|
circhandler.close()
|
|
circhandler.close()
|
|
return
|
|
return
|
|
|
|
|
|
@@ -495,7 +496,7 @@ class TelescopingCreatedRelayHandler:
|
|
self.next_snip = next_snip
|
|
self.next_snip = next_snip
|
|
|
|
|
|
def received_cell(self, circhandler, cell):
|
|
def received_cell(self, circhandler, cell):
|
|
- print("LOG: Handle a TelescopingCreatedCircui received by a relay")
|
|
|
|
|
|
+ logging.debug("Handle a TelescopingCreatedCircuit received by a relay")
|
|
# Remove ourselves from handling a second
|
|
# Remove ourselves from handling a second
|
|
# VanillaCreatedCircuitCell on this circuit
|
|
# VanillaCreatedCircuitCell on this circuit
|
|
circhandler.replace_celltype_handler(TelescopingCreatedCircuitCell, None)
|
|
circhandler.replace_celltype_handler(TelescopingCreatedCircuitCell, None)
|
|
@@ -551,7 +552,7 @@ class CircuitHandler:
|
|
adjacent circuit, if present) and closes both."""
|
|
adjacent circuit, if present) and closes both."""
|
|
adjcirchandler = self.adjacent_circuit_handler
|
|
adjcirchandler = self.adjacent_circuit_handler
|
|
self.adjacent_circuit_handler = None
|
|
self.adjacent_circuit_handler = None
|
|
- print("Log: CLosing circuit. circid: " + str(self.circid))
|
|
|
|
|
|
+ logging.debug("Closing circuit. circid: %s", str(self.circid))
|
|
if adjcirchandler is not None:
|
|
if adjcirchandler is not None:
|
|
adjcirchandler.adjacent_circuit_handler = None
|
|
adjcirchandler.adjacent_circuit_handler = None
|
|
self.closer()
|
|
self.closer()
|
|
@@ -575,7 +576,7 @@ class CircuitHandler:
|
|
if isinstance(cell, EncryptedCell):
|
|
if isinstance(cell, EncryptedCell):
|
|
cell = self.crypt_layer.decrypt_msg(cell)
|
|
cell = self.crypt_layer.decrypt_msg(cell)
|
|
|
|
|
|
- print("CircuitHandler: %s received cell %s on circuit %d from %s" % (self.channel.channelmgr.myaddr, cell, self.circid, self.channel.peer.channelmgr.myaddr))
|
|
|
|
|
|
+ logging.debug("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
|
|
# If it's still encrypted, it's for sure meant for forwarding to
|
|
# our adjacent hop, which had better exist.
|
|
# our adjacent hop, which had better exist.
|
|
@@ -590,12 +591,12 @@ class CircuitHandler:
|
|
|
|
|
|
elif isinstance(cell, StringCell):
|
|
elif isinstance(cell, StringCell):
|
|
# Default handler; just print the message in the cell
|
|
# Default handler; just print the message in the cell
|
|
- print("CircuitHandler: %s received '%s' on circuit %d from %s" \
|
|
|
|
|
|
+ logging.debug("CircuitHandler: %s received '%s' on circuit %d from %s" \
|
|
% (self.channel.channelmgr.myaddr, cell,
|
|
% (self.channel.channelmgr.myaddr, cell,
|
|
self.circid, self.channel.peer.channelmgr.myaddr))
|
|
self.circid, self.channel.peer.channelmgr.myaddr))
|
|
|
|
|
|
elif isinstance(cell, CloseCell):
|
|
elif isinstance(cell, CloseCell):
|
|
- print("WARNING: Received CloseCell on circuit " + str(self.circid))
|
|
|
|
|
|
+ logging.debug("Received CloseCell on circuit %s", str(self.circid))
|
|
# Forward the CloseCell (without encryption) to the
|
|
# Forward the CloseCell (without encryption) to the
|
|
# adjacent circuit, if any, and close both this and the
|
|
# adjacent circuit, if any, and close both this and the
|
|
# adjacent circuit
|
|
# adjacent circuit
|
|
@@ -656,7 +657,7 @@ class Channel(network.Connection):
|
|
while self.circuithandlers:
|
|
while self.circuithandlers:
|
|
chitems = iter(self.circuithandlers.items())
|
|
chitems = iter(self.circuithandlers.items())
|
|
circid, circhandler = next(chitems)
|
|
circid, circhandler = next(chitems)
|
|
- print('closing circuit', circid)
|
|
|
|
|
|
+ logging.debug('closing circuit %s', circid)
|
|
circhandler.close()
|
|
circhandler.close()
|
|
self.closer()
|
|
self.closer()
|
|
self.peer = None
|
|
self.peer = None
|
|
@@ -704,7 +705,7 @@ class Channel(network.Connection):
|
|
|
|
|
|
def received(self, peeraddr, msg):
|
|
def received(self, peeraddr, msg):
|
|
"""Callback when a message is received from the network."""
|
|
"""Callback when a message is received from the network."""
|
|
- print('Channel: %s received %s from %s' % (self.channelmgr.myaddr, msg, peeraddr))
|
|
|
|
|
|
+ logging.debug('Channel: %s received %s from %s' % (self.channelmgr.myaddr, msg, peeraddr))
|
|
self.channelmgr.perfstats.bytes_received += msg.size()
|
|
self.channelmgr.perfstats.bytes_received += msg.size()
|
|
if isinstance(msg, CircuitCellMsg):
|
|
if isinstance(msg, CircuitCellMsg):
|
|
circid, cell = msg.circid, msg.cell
|
|
circid, cell = msg.circid, msg.cell
|
|
@@ -733,7 +734,7 @@ class ChannelManager:
|
|
while self.channels:
|
|
while self.channels:
|
|
channelitems = iter(self.channels.items())
|
|
channelitems = iter(self.channels.items())
|
|
addr, channel = next(channelitems)
|
|
addr, channel = next(channelitems)
|
|
- print('closing channel', addr, channel)
|
|
|
|
|
|
+ logging.debug('closing channel %s %s', addr, channel)
|
|
channel.close()
|
|
channel.close()
|
|
|
|
|
|
def add_channel(self, channel, peeraddr):
|
|
def add_channel(self, channel, peeraddr):
|
|
@@ -754,10 +755,10 @@ class ChannelManager:
|
|
return self.channels[addr]
|
|
return self.channels[addr]
|
|
|
|
|
|
# Create the new channel
|
|
# Create the new channel
|
|
- print('getting channel from',self.myaddr,'to',addr)
|
|
|
|
|
|
+ logging.debug('getting channel from %s to %s',self.myaddr,addr)
|
|
newchannel = network.thenetwork.connect(self.myaddr, addr,
|
|
newchannel = network.thenetwork.connect(self.myaddr, addr,
|
|
self.perfstats)
|
|
self.perfstats)
|
|
- print('got channel from',self.myaddr,'to',addr)
|
|
|
|
|
|
+ logging.debug('got channel from %s to %s',self.myaddr,addr)
|
|
self.channels[addr] = newchannel
|
|
self.channels[addr] = newchannel
|
|
newchannel.closer = lambda: self.channels.pop(addr)
|
|
newchannel.closer = lambda: self.channels.pop(addr)
|
|
newchannel.channelmgr = self
|
|
newchannel.channelmgr = self
|
|
@@ -767,11 +768,11 @@ class ChannelManager:
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
received."""
|
|
received."""
|
|
- print("ChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
|
|
|
+ logging.debug("ChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
|
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
"""Callback with a circuit-specific cell is received."""
|
|
"""Callback with a circuit-specific cell is received."""
|
|
- print("ChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
|
|
|
+ logging.debug("ChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
|
|
|
def send_msg(self, msg, peeraddr):
|
|
def send_msg(self, msg, peeraddr):
|
|
"""Send a message to the peer with the given address."""
|
|
"""Send a message to the peer with the given address."""
|
|
@@ -823,7 +824,7 @@ class RelayChannelManager(ChannelManager):
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
def received_msg(self, msg, peeraddr, channel):
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
"""Callback when a NetMsg not specific to a circuit is
|
|
received."""
|
|
received."""
|
|
- print("RelayChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
|
|
|
|
+ logging.debug("RelayChannelManager: Node %s received msg %s from %s" % (self.myaddr, msg, peeraddr))
|
|
if isinstance(msg, RelayRandomHopMsg):
|
|
if isinstance(msg, RelayRandomHopMsg):
|
|
if msg.ttl > 0:
|
|
if msg.ttl > 0:
|
|
# Pick a random next hop from the consensus
|
|
# Pick a random next hop from the consensus
|
|
@@ -883,7 +884,7 @@ class RelayChannelManager(ChannelManager):
|
|
|
|
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
def received_cell(self, circid, cell, peeraddr, channel):
|
|
"""Callback with a circuit-specific cell is received."""
|
|
"""Callback with a circuit-specific cell is received."""
|
|
- print("RelayChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
|
|
|
|
+ logging.debug("RelayChannelManager: Node %s received cell on circ %d: %s from %s" % (self.myaddr, circid, cell, peeraddr))
|
|
return super().received_cell(circid, cell, peeraddr, channel)
|
|
return super().received_cell(circid, cell, peeraddr, channel)
|
|
|
|
|
|
|
|
|
|
@@ -1013,6 +1014,9 @@ class Relay(network.Server):
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
perfstats = network.PerfStats(network.EntType.NONE)
|
|
perfstats = network.PerfStats(network.EntType.NONE)
|
|
|
|
|
|
|
|
+ # Initialize the (non-cryptographic) random seed
|
|
|
|
+ random.seed(1)
|
|
|
|
+
|
|
network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
|
|
network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
|
|
network.SNIPAuthMode.MERKLE)
|
|
network.SNIPAuthMode.MERKLE)
|
|
|
|
|