Browse Source

Store uploaded relay descriptors

Ian Goldberg 4 years ago
parent
commit
1765d6084f
1 changed files with 12 additions and 1 deletions
  1. 12 1
      dirauth.py

+ 12 - 1
dirauth.py

@@ -102,6 +102,10 @@ class DirAuthConnection(network.ClientConnection):
 class DirAuth(network.Server):
     """The class representing directory authorities."""
 
+    # We simulate the act of computing the consensus by keeping a
+    # class-static dict that's accessible to all of the dirauths
+    uploadeddescs = dict()
+
     def __init__(self, me, tot):
         """Create a new directory authority. me is the index of which
         dirauth this one is (starting from 0), and tot is the total
@@ -128,7 +132,14 @@ class DirAuth(network.Server):
 
     def received(self, client, msg):
         if isinstance(msg, DirAuthUploadDescMsg):
-            print(self.name, 'received descriptor from', client, ":", msg.desc)
+            # Check the uploaded descriptor for sanity
+            if msg.desc.descdict['epoch'] != network.thenetwork.getepoch() + 1:
+                return
+            descstr = str(msg.desc)
+            if descstr not in DirAuth.uploadeddescs:
+                DirAuth.uploadeddescs[descstr] = 1
+            else:
+                DirAuth.uploadeddescs[descstr] += 1
         elif isinstance(msg, DirAuthGetConsensusMsg):
             client.sendmsg(DirAuthConsensusMsg(self.consensus))
         elif isinstance(msg, DirAuthGetENDIVEMsg):