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 4 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
             debug("new client from %s:%s (fd=%d)" %
                   (endpoint[0], endpoint[1], newsock.fileno()))
-            handler = Sink(newsock, self.tt)
-            self.tt.add(handler)
+            self.tt.add_responder(newsock)
 
     def fileno(self):
         return self.socket.fileno()
@@ -320,6 +319,14 @@ class TrafficTester(object):
             for name in item.get_test_names():
                 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):
         """Declare that a single test has passed."""
         self.tests.success(name)
@@ -355,7 +362,7 @@ def main():
 
     tt = TrafficTester(bind_to, DATA)
     # 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()
 
     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']))
             for _ in range(connection_count):
                 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
 
 
@@ -187,7 +187,7 @@ def _configure_hs(tt, tmpdata, reps, client_list, hs_list, HS_PORT,
                      'localhost', client._env['socksport']))
             for _ in range(connection_count):
                 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