Browse Source

Better API for setting the Walking Onions modes

Ian Goldberg 4 years ago
parent
commit
d85ce6df88
1 changed files with 19 additions and 4 deletions
  1. 19 4
      network.py

+ 19 - 4
network.py

@@ -36,20 +36,21 @@ class NetAddr:
     def __str__(self):
         return self.addr.__str__()
 
+
 class Network:
     """A class representing a simulated network.  Servers can bind()
     to the network, yielding a NetAddr (network address), and clients
     can connect() to a NetAddr yielding a Connection."""
 
-    def __init__(self, womode, snipauthmode):
+    def __init__(self):
         self.servers = dict()
         self.epoch = 1
         self.epochcallbacks = []
         self.epochendingcallbacks = []
         self.dirauthkeylist = []
         self.fallbackrelays = []
-        self.womode = womode
-        self.snipauthmode = snipauthmode
+        self.womode = WOMode.VANILLA
+        self.snipauthmode = SNIPAuthMode.NONE
 
     def printservers(self):
         """Print the list of NetAddrs bound to something."""
@@ -124,8 +125,22 @@ class Network:
         these to bootstrap when they know no other relays."""
         return self.fallbackrelays
 
+    def set_wo_style(self, womode, snipauthmode):
+        """Set the Walking Onions mode and the SNIP authenticate mode
+        for the network."""
+        if ((womode == WOMode.VANILLA) \
+                and (snipauthmode != SNIPAuthMode.NONE)) or \
+                ((womode != WOMode.VANILLA) and  \
+                (snipauthmode == SNIPAuthMode.NONE)):
+            # Incompatible settings
+            raise ValueError("Bad argument combination")
+
+        self.womode = womode
+        self.snipauthmode = snipauthmode
+
+
 # The singleton instance of Network
-thenetwork = Network(WOMode.VANILLA, SNIPAuthMode.NONE)
+thenetwork = Network()
 
 # Initialize the (non-cryptographic) random seed
 random.seed(1)