Browse Source

More carefully store the uploaded descriptors, sorted by epoch

Ian Goldberg 4 years ago
parent
commit
a96f372232
2 changed files with 16 additions and 4 deletions
  1. 11 4
      dirauth.py
  2. 5 0
      relay.py

+ 11 - 4
dirauth.py

@@ -104,6 +104,9 @@ class DirAuth(network.Server):
 
     # We simulate the act of computing the consensus by keeping a
     # class-static dict that's accessible to all of the dirauths
+    # This dict is indexed by epoch, and the value is itself a dict
+    # indexed by the stringified descriptor, with value of the number of
+    # dirauths that saw that descriptor.
     uploadeddescs = dict()
 
     def __init__(self, me, tot):
@@ -133,13 +136,17 @@ class DirAuth(network.Server):
     def received(self, client, msg):
         if isinstance(msg, DirAuthUploadDescMsg):
             # Check the uploaded descriptor for sanity
-            if msg.desc.descdict['epoch'] != network.thenetwork.getepoch() + 1:
+            epoch = msg.desc.descdict['epoch']
+            if epoch != network.thenetwork.getepoch() + 1:
                 return
+            # Store it in the class-static dict
+            if epoch not in DirAuth.uploadeddescs:
+                DirAuth.uploadeddescs[epoch] = dict()
             descstr = str(msg.desc)
-            if descstr not in DirAuth.uploadeddescs:
-                DirAuth.uploadeddescs[descstr] = 1
+            if descstr not in DirAuth.uploadeddescs[epoch]:
+                DirAuth.uploadeddescs[epoch][descstr] = 1
             else:
-                DirAuth.uploadeddescs[descstr] += 1
+                DirAuth.uploadeddescs[epoch][descstr] += 1
         elif isinstance(msg, DirAuthGetConsensusMsg):
             client.sendmsg(DirAuthConsensusMsg(self.consensus))
         elif isinstance(msg, DirAuthGetENDIVEMsg):

+ 5 - 0
relay.py

@@ -17,6 +17,7 @@ class Relay(network.Server):
         # Create the identity and onion keys
         self.idkey = nacl.signing.SigningKey.generate()
         self.onionkey = nacl.public.PrivateKey.generate()
+        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)
@@ -66,3 +67,7 @@ if __name__ == '__main__':
     numrelays = 10
     for i in range(numrelays):
         Relay(dirauthaddrs, 500, 0)
+
+    # Tick the epoch
+    network.thenetwork.nextepoch()
+    print('ticked; epoch=', network.thenetwork.getepoch())