Browse Source

Make TrafficTester create sources and sinks

We'd like to be able to change the client and responder behavior,
but we need to keep both parts synchronized as we do so.
Nick Mathewson 5 years ago
parent
commit
58c5a3c69d
2 changed files with 12 additions and 5 deletions
  1. 10 3
      lib/chutney/Traffic.py
  2. 2 2
      scripts/chutney_tests/verify.py

+ 10 - 3
lib/chutney/Traffic.py

@@ -125,8 +125,7 @@ class Listener(asyncore.dispatcher):
             newsock, endpoint = pair
             newsock, endpoint = pair
             debug("new client from %s:%s (fd=%d)" %
             debug("new client from %s:%s (fd=%d)" %
                   (endpoint[0], endpoint[1], newsock.fileno()))
                   (endpoint[0], endpoint[1], newsock.fileno()))
-            handler = Sink(newsock, self.tt)
-            self.tt.add(handler)
+            self.tt.add_responder(newsock)
 
 
     def fileno(self):
     def fileno(self):
         return self.socket.fileno()
         return self.socket.fileno()
@@ -320,6 +319,14 @@ class TrafficTester(object):
             for name in item.get_test_names():
             for name in item.get_test_names():
                 self.tests.add(name)
                 self.tests.add(name)
 
 
+    def add_client(self, server, proxy=None):
+        source = Source(self, server, proxy)
+        self.add(source)
+
+    def add_responder(self, socket):
+        sink = Sink(socket, self)
+        self.add(sink)
+
     def success(self, name):
     def success(self, name):
         """Declare that a single test has passed."""
         """Declare that a single test has passed."""
         self.tests.success(name)
         self.tests.success(name)
@@ -355,7 +362,7 @@ def main():
 
 
     tt = TrafficTester(bind_to, DATA)
     tt = TrafficTester(bind_to, DATA)
     # Don't use a proxy for self-testing, so that we avoid tor entirely
     # Don't use a proxy for self-testing, so that we avoid tor entirely
-    tt.add(Source(tt, bind_to))
+    tt.add_client(bind_to)
     success = tt.run()
     success = tt.run()
 
 
     if success:
     if success:

+ 2 - 2
scripts/chutney_tests/verify.py

@@ -155,7 +155,7 @@ def _configure_exits(tt, bind_to, tmpdata, reps, client_list, exit_list,
                      'localhost', op._env['socksport']))
                      'localhost', op._env['socksport']))
             for _ in range(connection_count):
             for _ in range(connection_count):
                 proxy = ('localhost', int(op._env['socksport']))
                 proxy = ('localhost', int(op._env['socksport']))
-                tt.add(chutney.Traffic.Source(tt, bind_to, proxy))
+                tt.add_client(bind_to, proxy)
     return exit_path_node_count
     return exit_path_node_count
 
 
 
 
@@ -187,7 +187,7 @@ def _configure_hs(tt, tmpdata, reps, client_list, hs_list, HS_PORT,
                      'localhost', client._env['socksport']))
                      'localhost', client._env['socksport']))
             for _ in range(connection_count):
             for _ in range(connection_count):
                 proxy = ('localhost', int(client._env['socksport']))
                 proxy = ('localhost', int(client._env['socksport']))
-                tt.add(chutney.Traffic.Source(tt, hs_bind_to, proxy))
+                tt.add_client(hs_bind_to, proxy)
 
 
     return hs_path_node_count
     return hs_path_node_count