[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [chutney/master] Make chutney bidirectional by default



commit 36a3ee88f19391fb3525454ba527a2479010c85d
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri May 10 11:44:10 2019 -0400

    Make chutney bidirectional by default
    
    The default client/responder pair is no longer source/sink, but
    echoclient/echoserver.
---
 lib/chutney/Traffic.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 3 deletions(-)

diff --git a/lib/chutney/Traffic.py b/lib/chutney/Traffic.py
index de21d60..167647b 100755
--- a/lib/chutney/Traffic.py
+++ b/lib/chutney/Traffic.py
@@ -286,6 +286,49 @@ class Source(asynchat.async_chat):
     def fileno(self):
         return self.socket.fileno()
 
+class EchoServer(asynchat.async_chat):
+    def __init__(self, sock, tt):
+        asynchat.async_chat.__init__(self, sock)
+        self.set_terminator(None)
+        self.tt = tt
+
+    def collect_incoming_data(self, data):
+        self.push(data)
+
+    def handle_close(self):
+        self.close_when_done()
+
+class EchoClient(Source):
+    def __init__(self, tt, server, proxy=None):
+        Source.__init__(self, tt, server, proxy)
+        self.data_checker = DataChecker(tt.data_source.copy())
+        self.testname_check = "check-%s"%id(self)
+
+    def get_test_names(self):
+        return [ self.testname, self.testname_check ]
+
+    def handle_close(self):
+        self.close_when_done()
+
+    def collect_incoming_data(self, data):
+        if self.state == self.CONNECTING_THROUGH_PROXY:
+            Source.collect_incoming_data(self, data)
+            if self.state == self.CONNECTING_THROUGH_PROXY:
+                return
+            data = self.inbuf
+            self.inbuf = b""
+
+        self.data_checker.consume(data)
+
+        if self.data_checker.succeeded:
+            debug("successful verification")
+            self.close()
+            self.tt.success(self.testname_check)
+        elif self.data_checker.failed:
+            debug("receive comparison failed")
+            self.tt.failure(self.testname_check)
+            self.close()
+
 class TrafficTester(object):
     """
     Hang on select.select() and dispatch to Sources and Sinks.
@@ -300,7 +343,15 @@ class TrafficTester(object):
                  data=b"",
                  timeout=3,
                  repetitions=1,
-                 dot_repetitions=0):
+                 dot_repetitions=0,
+                 chat_type="Echo"):
+        if chat_type == "Echo":
+            self.client_class = EchoClient
+            self.responder_class = EchoServer
+        else:
+            self.client_class = Source
+            self.responder_class = Sink
+
         self.listener = Listener(self, endpoint)
         self.pending_close = []
         self.timeout = timeout
@@ -320,11 +371,11 @@ class TrafficTester(object):
                 self.tests.add(name)
 
     def add_client(self, server, proxy=None):
-        source = Source(self, server, proxy)
+        source = self.client_class(self, server, proxy)
         self.add(source)
 
     def add_responder(self, socket):
-        sink = Sink(socket, self)
+        sink = self.responder_class(socket, self)
         self.add(sink)
 
     def success(self, name):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits