Browse Source

Simplify command-line API for client.py main program

Ian Goldberg 4 years ago
parent
commit
345b974422
1 changed files with 5 additions and 31 deletions
  1. 5 31
      client.py

+ 5 - 31
client.py

@@ -194,7 +194,7 @@ class SinglePassCreatedHandler:
                 circhandler.add_crypt_layer(enckey, deckey)
                 cell = None
             else:
-                secret = self.ntor.verify(cell.ntor_reply, onionkey, \
+                secret = self.ntor.verify(cell.ntor_reply, onionkey,
                         idkey, b'circuit')
                 enckey = nacl.hash.sha256(secret + b'upstream')
                 deckey = nacl.hash.sha256(secret + b'downstream')
@@ -283,7 +283,7 @@ class ClientChannelManager(relay.ChannelManager):
 
         while True:
             if self.guardaddr is None:
-                #randomly-sample a guard
+                #randomly sample a guard
                 logging.warning("Unimplemented! guard should be selected from any relays.")
                 self.guard = self.relaypicker.pick_weighted_relay()
                 # here, we have a SNIP instead of a relay descriptor
@@ -576,39 +576,13 @@ if __name__ == '__main__':
 
     logging.basicConfig(level=logging.DEBUG)
 
-    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)
-
-    snipauth_mode = network.SNIPAuthMode.string_to_type(sys.argv[2])
-    if network_mode == -1:
-        print("Not a valid SNIP authentication mode: " + snipauth_mode)
-        sys.exit(0)
+    womode = network.WOMode[sys.argv[1].upper()]
+    snipauthmode = network.SNIPAuthMode[sys.argv[2].upper()]
+    network.thenetwork.set_wo_style(womode, snipauthmode)
 
     # Initialize the (non-cryptographic) random seed
     random.seed(1)
 
-    if network_mode == network.WOMode.VANILLA:
-        network.thenetwork.set_wo_style(network.WOMode.VANILLA,
-            network.SNIPAuthMode.NONE)
-    elif network_mode == network.WOMode.TELESCOPING:
-        if snipauth_mode == network.SNIPAuthMode.MERKLE:
-            network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
-                network.SNIPAuthMode.MERKLE)
-        else:
-            network.thenetwork.set_wo_style(network.WOMode.TELESCOPING,
-                network.SNIPAuthMode.THRESHSIG)
-    elif network_mode == network.WOMode.SINGLEPASS:
-        if snipauth_mode == network.SNIPAuthMode.MERKLE:
-            network.thenetwork.set_wo_style(network.WOMode.SINGLEPASS,
-                network.SNIPAuthMode.MERKLE)
-        else:
-            network.thenetwork.set_wo_style(network.WOMode.SINGLEPASS,
-                network.SNIPAuthMode.THRESHSIG)
-    else:
-        sys.exit("Received unsupported network mode, exiting.")
-
     # Start some dirauths
     numdirauths = 9
     dirauthaddrs = []