Ticket #9087: chobe-9087.patch

File chobe-9087.patch, 6.5 KB (added by chobe, 5 years ago)
  • lib/chutney/TorNet.py

    From 2e70c6206af8c2d8c6563aa6d17bac95b5cc8b3a Mon Sep 17 00:00:00 2001
    From: Scott Griffy <scottgriffy@gmail.com>
    Date: Thu, 19 Feb 2015 07:56:49 -0800
    Subject: [PATCH] moved verify out of TorNet... poorly
    
    ---
     lib/chutney/TorNet.py         | 58 +++----------------------------------------
     tests/chutney_tests/verify.py | 52 ++++++++++++++++++++++++++++++++++++++
     2 files changed, 56 insertions(+), 54 deletions(-)
     create mode 100644 tests/chutney_tests/verify.py
    
    diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
    index 439aa10..bd9e83a 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 runConfigFile(verb, data): 
    979925
    980926    exec(data, _GLOBALS)
    981927    network = _GLOBALS['_THE_NETWORK']
     928    if verb+".py" in os.listdir("tests/chutney_tests"):
     929        execfile("tests/chutney_tests/"+verb+".py")
     930        test(network)
     931        return
    982932
    983933    if not hasattr(network, verb):
    984934        print(usage(network))
  • new file tests/chutney_tests/verify.py

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