Browse Source

Relays can fetch ENDIVEs and ENDIVE diffs from DirAuths

Ian Goldberg 4 years ago
parent
commit
7e35deb381
2 changed files with 24 additions and 2 deletions
  1. 13 1
      dirauth.py
  2. 11 1
      relay.py

+ 13 - 1
dirauth.py

@@ -404,11 +404,16 @@ class DirAuthConnection(network.ClientConnection):
         self.sendmsg(DirAuthGetConsensusDiffMsg())
         return self.consensus
 
-    def getENDIVE(self):
+    def getendive(self):
         self.endive = None
         self.sendmsg(DirAuthGetENDIVEMsg())
         return self.endive
 
+    def getendivediff(self):
+        self.endive = None
+        self.sendmsg(DirAuthGetENDIVEDiffMsg())
+        return self.endive
+
     def receivedfromserver(self, msg):
         if isinstance(msg, DirAuthConsensusMsg):
             self.consensus = msg.consensus
@@ -416,6 +421,8 @@ class DirAuthConnection(network.ClientConnection):
             self.consensus = msg.consensus
         elif isinstance(msg, DirAuthENDIVEMsg):
             self.endive = msg.endive
+        elif isinstance(msg, DirAuthENDIVEDiffMsg):
+            self.endive = msg.endive
         else:
             raise TypeError('Not a server-originating DirAuthNetMsg', msg)
     
@@ -565,6 +572,11 @@ class DirAuth(network.Server):
             msgsize = replymsg.size()
             self.perfstats.bytes_sent += msgsize
             client.reply(replymsg)
+        elif isinstance(msg, DirAuthGetENDIVEDiffMsg):
+            replymsg = DirAuthENDIVEDiffMsg(DirAuth.endive)
+            msgsize = replymsg.size()
+            self.perfstats.bytes_sent += msgsize
+            client.reply(replymsg)
         else:
             raise TypeError('Not a client-originating DirAuthNetMsg', msg)
 

+ 11 - 1
relay.py

@@ -541,6 +541,8 @@ class RelayChannelManager(ChannelManager):
         super().__init__(myaddr, dirauthaddrs, perfstats)
         self.onionkey = onionprivkey
         self.idpubkey = idpubkey
+        if network.thenetwork.womode != network.WOMode.VANILLA:
+            self.endive = None
 
     def get_consensus(self):
         """Download a fresh consensus (and ENDIVE if using Walking
@@ -556,7 +558,15 @@ class RelayChannelManager(ChannelManager):
             self.relaypicker = dirauth.Consensus.verify(self.consensus,
                     network.thenetwork.dirauthkeys(), self.perfstats)
         else:
-            raise NotImplementedError("Walking Onions not yet implemented")
+            self.consensus = c.getconsensus()
+            if self.endive is not None and \
+                    len(self.endive.enddict['snips']) > 0:
+                self.endive = c.getendivediff()
+            else:
+                self.endive = c.getendive()
+            self.relaypicker = dirauth.ENDIVE.verify(self.endive,
+                    self.consensus, network.thenetwork.dirauthkeys(),
+                    self.perfstats)
         c.close()
 
     def received_msg(self, msg, peeraddr, channel):