|
@@ -37,6 +37,24 @@ class RelayRandomHopMsg(RelayNetMsg):
|
|
|
return "RandomHop TTL=%d" % self.ttl
|
|
|
|
|
|
|
|
|
+class VanillaCreateCircuitMsg(RelayNetMsg):
|
|
|
+ """The message for requesting circuit creation in Vanilla Onion
|
|
|
+ Routing."""
|
|
|
+
|
|
|
+ def __init__(self, circid, ntor_request):
|
|
|
+ self.circid = circid
|
|
|
+ self.ntor_request = ntor_request
|
|
|
+
|
|
|
+
|
|
|
+class VanillaCreatedCircuitMsg(RelayNetMsg):
|
|
|
+ """The message for responding to circuit creation in Vanilla Onion
|
|
|
+ Routing."""
|
|
|
+
|
|
|
+ def __init__(self, circid, ntor_response):
|
|
|
+ self.circid = circid
|
|
|
+ self.ntor_response = ntor_response
|
|
|
+
|
|
|
+
|
|
|
class CircuitCellMsg(RelayNetMsg):
|
|
|
"""Send a message tagged with a circuit id."""
|
|
|
def __init__(self, circuitid, cell):
|
|
@@ -142,12 +160,13 @@ class CellHandler:
|
|
|
on-demand channels to relays, to gracefully handle the closing of
|
|
|
channels, and to handle commands received over the channels."""
|
|
|
|
|
|
- def __init__(self, myaddr, dirauthaddrs):
|
|
|
+ def __init__(self, myaddr, dirauthaddrs, perfstats):
|
|
|
# A dictionary of Channels to other hosts, indexed by NetAddr
|
|
|
self.channels = dict()
|
|
|
self.myaddr = myaddr
|
|
|
self.dirauthaddrs = dirauthaddrs
|
|
|
self.consensus = None
|
|
|
+ self.perfstats = perfstats
|
|
|
|
|
|
def terminate(self):
|
|
|
"""Close all connections we're managing."""
|
|
@@ -206,15 +225,16 @@ class CellHandler:
|
|
|
class CellRelay(CellHandler):
|
|
|
"""The subclass of CellHandler for relays."""
|
|
|
|
|
|
- def __init__(self, myaddr, dirauthaddrs):
|
|
|
- super().__init__(myaddr, dirauthaddrs)
|
|
|
+ def __init__(self, myaddr, dirauthaddrs, perfstats):
|
|
|
+ super().__init__(myaddr, dirauthaddrs, perfstats)
|
|
|
|
|
|
def get_consensus(self):
|
|
|
"""Download a fresh consensus from a random dirauth."""
|
|
|
a = random.choice(self.dirauthaddrs)
|
|
|
c = network.thenetwork.connect(self, a)
|
|
|
self.consensus = c.getconsensus()
|
|
|
- dirauth.Consensus.verify(self.consensus, network.thenetwork.dirauthkeys())
|
|
|
+ dirauth.Consensus.verify(self.consensus, \
|
|
|
+ network.thenetwork.dirauthkeys(), self.perfstats)
|
|
|
c.close()
|
|
|
|
|
|
def received_msg(self, msg, peeraddr, peer):
|
|
@@ -242,13 +262,19 @@ class Relay(network.Server):
|
|
|
"""The class representing an onion relay."""
|
|
|
|
|
|
def __init__(self, dirauthaddrs, bw, flags):
|
|
|
+ # Gather performance statistics
|
|
|
+ self.perfstats = dirauth.PerfStats(dirauth.EntType.RELAY)
|
|
|
+ self.perfstats.is_bootstrapping = True
|
|
|
+
|
|
|
# Create the identity and onion keys
|
|
|
self.idkey = nacl.signing.SigningKey.generate()
|
|
|
self.onionkey = nacl.public.PrivateKey.generate()
|
|
|
+ self.perfstats.keygens += 2
|
|
|
self.name = self.idkey.verify_key.encode(encoder=nacl.encoding.HexEncoder).decode("ascii")
|
|
|
|
|
|
# Bind to the network to get a network address
|
|
|
self.netaddr = network.thenetwork.bind(self)
|
|
|
+ self.perfstats.name = "Relay at %s" % self.netaddr
|
|
|
|
|
|
# Our bandwidth and flags
|
|
|
self.bw = bw
|
|
@@ -259,7 +285,7 @@ class Relay(network.Server):
|
|
|
network.thenetwork.wantepochticks(self, True)
|
|
|
|
|
|
# Create the CellRelay connection manager
|
|
|
- self.cellhandler = CellRelay(self.netaddr, dirauthaddrs)
|
|
|
+ self.cellhandler = CellRelay(self.netaddr, dirauthaddrs, self.perfstats)
|
|
|
|
|
|
# Initially, we're not a fallback relay
|
|
|
self.is_fallbackrelay = False
|
|
@@ -311,8 +337,8 @@ class Relay(network.Server):
|
|
|
descdict["bw"] = self.bw
|
|
|
descdict["flags"] = self.flags
|
|
|
desc = dirauth.RelayDescriptor(descdict)
|
|
|
- desc.sign(self.idkey)
|
|
|
- dirauth.RelayDescriptor.verify(desc)
|
|
|
+ desc.sign(self.idkey, self.perfstats)
|
|
|
+ dirauth.RelayDescriptor.verify(desc, self.perfstats)
|
|
|
|
|
|
if upload:
|
|
|
descmsg = dirauth.DirAuthUploadDescMsg(desc)
|
|
@@ -355,6 +381,8 @@ class Relay(network.Server):
|
|
|
return peerchannel
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
+ perfstats = dirauth.PerfStats(dirauth.EntType.NONE)
|
|
|
+
|
|
|
# Start some dirauths
|
|
|
numdirauths = 9
|
|
|
dirauthaddrs = []
|
|
@@ -385,7 +413,8 @@ if __name__ == '__main__':
|
|
|
# Tick the epoch
|
|
|
network.thenetwork.nextepoch()
|
|
|
|
|
|
- dirauth.Consensus.verify(dirauth.DirAuth.consensus, network.thenetwork.dirauthkeys())
|
|
|
+ dirauth.Consensus.verify(dirauth.DirAuth.consensus, \
|
|
|
+ network.thenetwork.dirauthkeys(), perfstats)
|
|
|
|
|
|
print('ticked; epoch=', network.thenetwork.getepoch())
|
|
|
|