Ticket #9087: chobe-9087-v2.patch

File chobe-9087-v2.patch, 8.2 KB (added by chobe, 5 years ago)
  • README

    diff --git a/README b/README
    index a8b5660..50a567e 100644
    a b The configuration files: 
    2929The working files:
    3030  chutney sticks its working files, including all data directories, log
    3131  files, etc, in ./net/.  Each tor instance gets a subdirectory of net/nodes.
     32
     33Test scripts:
     34  test scripts are python scripts that are stored in "scripts/chutney_tests"
     35  when your test script must have a "run_test(network)" function defined
     36  files in "scripts/chutney_tests" starting with an "_" are not considered
     37  test scripts
  • chutney

    diff --git a/chutney b/chutney
    index 4a26464..acf232c 100755
    a b  
    11#!/bin/sh
    22
    3 export PYTHONPATH="`dirname $0`/lib:${PYTHONPATH}"
     3export PYTHONPATH="`dirname $0`/scripts:`dirname $0`/lib:${PYTHONPATH}"
    44${PYTHON:=python2} -m chutney.TorNet "$@"
  • lib/chutney/TorNet.py

    diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
    index 439aa10..b239558 100644
    a b class Network(object): 
    895895            for c in controllers:
    896896                c.check(listNonRunning=False)
    897897
    898     def verify(self):
    899         print("Verifying data transmission:")
    900         status = self._verify_traffic()
    901         print("Transmission: %s" % ("Success" if status else "Failure"))
    902         return status
    903 
    904     def _verify_traffic(self):
    905         """Verify (parts of) the network by sending traffic through it
    906         and verify what is received."""
    907         LISTEN_PORT = 4747 # FIXME: Do better! Note the default exit policy.
    908         # HSs must have a HiddenServiceDir with
    909         # "HiddenServicePort <HS_PORT> 127.0.0.1:<LISTEN_PORT>"
    910         HS_PORT = 5858
    911         DATALEN = 10 * 1024               # Octets.
    912         TIMEOUT = 3                     # Seconds.
    913         with open('/dev/urandom', 'r') as randfp:
    914             tmpdata = randfp.read(DATALEN)
    915         bind_to = ('127.0.0.1', LISTEN_PORT)
    916         tt = chutney.Traffic.TrafficTester(bind_to, tmpdata, TIMEOUT)
    917         client_list = filter(lambda n:
    918                              n._env['tag'] == 'c' or n._env['tag'] == 'bc',
    919                              self._nodes)
    920         if len(client_list) == 0:
    921             print("  Unable to verify network: no client nodes available")
    922             return False
    923         # Each client binds directly to 127.0.0.1:LISTEN_PORT via an Exit relay
    924         for op in client_list:
    925             print("  Exit to %s:%d via client %s:%s"
    926                    % ('127.0.0.1', LISTEN_PORT,
    927                       'localhost', op._env['socksport']))
    928             tt.add(chutney.Traffic.Source(tt, bind_to, tmpdata,
    929                                           ('localhost',
    930                                            int(op._env['socksport']))))
    931         # The HS redirects .onion connections made to hs_hostname:HS_PORT
    932         # to the Traffic Tester's 127.0.0.1:LISTEN_PORT
    933         # We must have at least one working client for the hs test to succeed
    934         for hs in filter(lambda n:
    935                          n._env['tag'] == 'h',
    936                          self._nodes):
    937             # Instead of binding directly to LISTEN_PORT via an Exit relay,
    938             # we bind to hs_hostname:HS_PORT via a hidden service connection
    939             # through the first available client
    940             bind_to = (hs._env['hs_hostname'], HS_PORT)
    941             # Just choose the first client
    942             client = client_list[0]
    943             print("  HS to %s:%d (%s:%d) via client %s:%s"
    944                   % (hs._env['hs_hostname'], HS_PORT,
    945                      '127.0.0.1', LISTEN_PORT,
    946                      'localhost', client._env['socksport']))
    947             tt.add(chutney.Traffic.Source(tt, bind_to, tmpdata,
    948                                           ('localhost',
    949                                            int(client._env['socksport']))))
    950         return tt.run()
    951 
    952898
    953899def ConfigureNodes(nodelist):
    954900    network = _THE_NETWORK
    def ConfigureNodes(nodelist): 
    958904        if n._env['bridgeauthority']:
    959905            network._dfltEnv['hasbridgeauth'] = True
    960906
     907def getTests():
     908    tests = []
     909    for x in os.listdir("scripts/chutney_tests/"):
     910        if not x.startswith("_") and os.path.splitext(x)[1] == ".py":
     911            tests.append(os.path.splitext(x)[0])
     912    return tests
    961913
    962914def usage(network):
    963     return "\n".join(["Usage: chutney {command} {networkfile}",
     915    return "\n".join(["Usage: chutney {command/test} {networkfile}",
    964916                      "Known commands are: %s" % (
    965917                          " ".join(x for x in dir(network)
    966                                    if not x.startswith("_")))])
     918                                  if not x.startswith("_"))),
     919                      "Known tests are: %s" % (
     920                          " ".join(getTests()))
     921                      ])
    967922
    968923
    969924def exit_on_error(err_msg):
    def runConfigFile(verb, data): 
    980935    exec(data, _GLOBALS)
    981936    network = _GLOBALS['_THE_NETWORK']
    982937
     938    # let's check if the verb is a valid test and run it
     939    if verb in getTests():
     940        tests = __import__("chutney_tests", fromlist=[verb], level=0)
     941        test_module = getattr(tests, verb)
     942        return test_module.run_test(network)
     943
     944    # tell the user we don't know what their verb meant
    983945    if not hasattr(network, verb):
    984946        print(usage(network))
    985947        print("Error: I don't know how to %s." % verb)
  • new file scripts/chutney_tests/verify.py

    diff --git a/scripts/chutney_tests/__init__.py b/scripts/chutney_tests/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/scripts/chutney_tests/verify.py b/scripts/chutney_tests/verify.py
    new file mode 100644
    index 0000000..1f4027a
    - +  
     1import chutney
     2
     3def run_test(network):
     4    print("Verifying data transmission:")
     5    """Verify (parts of) the network by sending traffic through it
     6    and verify what is received."""
     7    status = _verify_traffic(network)
     8    print("Transmission: %s" % ("Success" if status else "Failure"))
     9    return status
     10
     11def _verify_traffic(network):
     12    LISTEN_PORT = 4747 # FIXME: Do better! Note the default exit policy.
     13    # HSs must have a HiddenServiceDir with
     14    # "HiddenServicePort <HS_PORT> 127.0.0.1:<LISTEN_PORT>"
     15    HS_PORT = 5858
     16    DATALEN = 10 * 1024               # Octets.
     17    TIMEOUT = 3                     # Seconds.
     18    with open('/dev/urandom', 'r') as randfp:
     19        tmpdata = randfp.read(DATALEN)
     20    bind_to = ('127.0.0.1', LISTEN_PORT)
     21    tt = chutney.Traffic.TrafficTester(bind_to, tmpdata, TIMEOUT)
     22    client_list = filter(lambda n:
     23                         n._env['tag'] == 'c' or n._env['tag'] == 'bc',
     24                         network._nodes)
     25    if len(client_list) == 0:
     26        print("  Unable to verify network: no client nodes available")
     27        return False
     28    # Each client binds directly to 127.0.0.1:LISTEN_PORT via an Exit relay
     29    for op in client_list:
     30        print("  Exit to %s:%d via client %s:%s"
     31               % ('127.0.0.1', LISTEN_PORT,
     32                  'localhost', op._env['socksport']))
     33        tt.add(chutney.Traffic.Source(tt, bind_to, tmpdata,
     34                                      ('localhost',
     35                                       int(op._env['socksport']))))
     36    # The HS redirects .onion connections made to hs_hostname:HS_PORT
     37    # to the Traffic Tester's 127.0.0.1:LISTEN_PORT
     38    # We must have at least one working client for the hs test to succeed
     39    for hs in filter(lambda n:
     40                     n._env['tag'] == 'h',
     41                     network._nodes):
     42        # Instead of binding directly to LISTEN_PORT via an Exit relay,
     43        # we bind to hs_hostname:HS_PORT via a hidden service connection
     44        # through the first available client
     45        bind_to = (hs._env['hs_hostname'], HS_PORT)
     46        # Just choose the first client
     47        client = client_list[0]
     48        print("  HS to %s:%d (%s:%d) via client %s:%s"
     49              % (hs._env['hs_hostname'], HS_PORT,
     50                 '127.0.0.1', LISTEN_PORT,
     51                 'localhost', client._env['socksport']))
     52        tt.add(chutney.Traffic.Source(tt, bind_to, tmpdata,
     53                                      ('localhost',
     54                                       int(client._env['socksport']))))
     55    return tt.run()
     56
     57