Browse Source

add start to being able to set mode from command line (or just elsewhere)

Chelsea H. Komlo 4 years ago
parent
commit
aeae0eac48
2 changed files with 26 additions and 4 deletions
  1. 16 3
      client.py
  2. 10 1
      network.py

+ 16 - 3
client.py

@@ -2,6 +2,7 @@
 
 import random # For simulation, not cryptography!
 import math
+import sys
 
 import network
 import dirauth
@@ -219,8 +220,6 @@ class Client:
         # If we don't have a guard, pick one and make a channel to it
         self.channelmgr.ensure_guard()
 
-
-
 if __name__ == '__main__':
     perfstats = network.PerfStats(network.EntType.NONE)
     totsent = 0
@@ -232,8 +231,22 @@ if __name__ == '__main__':
     clisent = 0
     clirecv = 0
 
-    network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
+    if len(sys.argv) < 2:
+        print("must pass in network mode: options are vanilla, telescoping, or single-pass.")
+        sys.exit(0)
+
+    network_mode = network.WOMode.string_to_type(sys.argv[1])
+    if network_mode == -1:
+        print("Not a valid network mode: " + network_mode)
+        sys.exit(0)
+
+    if network_mode == network.WOMode.VANILLA:
+        network.thenetwork.set_wo_style(network.WOMode.VANILLA,
+            network.SNIPAuthMode.THRESHSIG)
+    elif network_mode == network.WOMode.TELESCOPING:
+        network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
             network.SNIPAuthMode.THRESHSIG)
+    # TODO set single-pass
 
     # Start some dirauths
     numdirauths = 9

+ 10 - 1
network.py

@@ -24,6 +24,15 @@ class WOMode(Enum):
     TELESCOPING = 1  # Telescoping Walking Onions
     SINGLEPASS  = 2  # Single-Pass Walking Onions
 
+    def string_to_type(type_input):
+        reprs = {'vanilla': WOMode.VANILLA, 'telescoping': WOMode.TELESCOPING,
+                'single-pass': WOMode.SINGLEPASS }
+
+        if type_input in reprs.keys():
+            return reprs[type_input]
+
+        return -1
+
 
 class SNIPAuthMode(Enum):
     """The different styles of SNIP authentication"""
@@ -264,7 +273,7 @@ class ClientConnection(Connection):
     NetMsgs, which then get ignored.  Use subclasses of this class when
     the server required no per-connection state, such as just fetching
     consensus documents."""
-    
+
     def __init__(self, peer):
         """Create a ClientConnection object with the given peer.  The
         peer must have a received(client, msg) method."""