Browse Source

Relays download a consensus from a random dirauth every epoch

Ian Goldberg 4 years ago
parent
commit
c29ef0df37
3 changed files with 16 additions and 3 deletions
  1. 2 3
      dirauth.py
  2. 4 0
      network.py
  3. 10 0
      relay.py

+ 2 - 3
dirauth.py

@@ -204,7 +204,6 @@ class DirAuth(network.Server):
             self.generate_consensus(epoch+1)
             del DirAuth.uploadeddescs[epoch+1]
         DirAuth.consensus.sign(self.sigkey, self.me)
-        print(DirAuth.consensus)
 
     def received(self, client, msg):
         if isinstance(msg, DirAuthUploadDescMsg):
@@ -223,9 +222,9 @@ class DirAuth(network.Server):
                     (DirAuth.uploadeddescs[epoch][descstr][0]+1,
                      DirAuth.uploadeddescs[epoch][descstr][1])
         elif isinstance(msg, DirAuthGetConsensusMsg):
-            client.sendmsg(DirAuthConsensusMsg(DirAuth.consensus))
+            client.reply(DirAuthConsensusMsg(DirAuth.consensus))
         elif isinstance(msg, DirAuthGetENDIVEMsg):
-            client.sendmsg(DirAuthENDIVEMsg(DirAuth.endive))
+            client.reply(DirAuthENDIVEMsg(DirAuth.endive))
         else:
             raise TypeError('Not a client-originating DirAuthNetMsg', msg)
 

+ 4 - 0
network.py

@@ -142,6 +142,10 @@ class ClientConnection(Connection):
         assert(isinstance(netmsg, NetMsg))
         self.peer.received(self, netmsg)
 
+    def reply(self, netmsg):
+        assert(isinstance(netmsg, NetMsg))
+        self.receivedfromserver(netmsg)
+
     def received(self, netmsg):
         print("received", netmsg, "from server")
 

+ 10 - 0
relay.py

@@ -30,10 +30,20 @@ class Relay(network.Server):
         self.flags = flags
 
         # Register for epoch change notification
+        network.thenetwork.wantepochticks(self, True, end=True)
         network.thenetwork.wantepochticks(self, True)
 
         self.uploaddesc()
 
+    def epoch_ending(self, epoch):
+        # Download the new consensus, which will have been created
+        # already since the dirauths' epoch_ending callbacks happened
+        # before the relays'.
+        a = random.choice(self.dirauthaddrs)
+        c = network.thenetwork.connect(self, a)
+        self.consensus = c.getconsensus()
+        c.close()
+
     def newepoch(self, epoch):
         self.uploaddesc()