From 55056bd32433710e747619339f5468bd4d9ac6bf Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 6 May 2019 21:35:30 -0700 Subject: [PATCH] make no_listen= an argument to w.dilate() rather than create() It wasn't exposed in create(), and I need it for more tests. This might not be the best approach, I'll have to play with it a bit to tell. --- src/wormhole/_boss.py | 4 ++-- src/wormhole/_dilation/manager.py | 9 ++++----- src/wormhole/test/dilate/test_connect.py | 4 ++-- src/wormhole/test/dilate/test_manager.py | 6 +++--- src/wormhole/wormhole.py | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/wormhole/_boss.py b/src/wormhole/_boss.py index 226735b..ec6c845 100644 --- a/src/wormhole/_boss.py +++ b/src/wormhole/_boss.py @@ -205,8 +205,8 @@ class Boss(object): self._did_start_code = True self._C.set_code(code) - def dilate(self): - return self._D.dilate() # fires with endpoints + def dilate(self, no_listen=False): + return self._D.dilate(no_listen=no_listen) # fires with endpoints @m.input() def send(self, plaintext): diff --git a/src/wormhole/_dilation/manager.py b/src/wormhole/_dilation/manager.py index f5724be..abdf68c 100644 --- a/src/wormhole/_dilation/manager.py +++ b/src/wormhole/_dilation/manager.py @@ -477,7 +477,6 @@ class Dilator(object): _reactor = attrib() _eventual_queue = attrib() _cooperator = attrib() - _no_listen = attrib(default=False) def __attrs_post_init__(self): self._got_versions_d = Deferred() @@ -491,15 +490,15 @@ class Dilator(object): self._T = ITerminator(terminator) # this is the primary entry point, called when w.dilate() is invoked - def dilate(self, transit_relay_location=None): + def dilate(self, transit_relay_location=None, no_listen=False): self._transit_relay_location = transit_relay_location if not self._started: self._started = True - self._start().addBoth(self._endpoints.fire) + self._start(no_listen).addBoth(self._endpoints.fire) return self._endpoints.when_fired() @inlineCallbacks - def _start(self): + def _start(self, no_listen): # first, we wait until we hear the VERSION message, which tells us 1: # the PAKE key works, so we can talk securely, 2: that they can do # dilation at all (if they can't then w.dilate() errbacks) @@ -522,7 +521,7 @@ class Dilator(object): self._transit_key, self._transit_relay_location, self._reactor, self._eventual_queue, - self._cooperator, no_listen=self._no_listen) + self._cooperator, no_listen) self._manager.start() while self._pending_inbound_dilate_messages: diff --git a/src/wormhole/test/dilate/test_connect.py b/src/wormhole/test/dilate/test_connect.py index 7a60400..b5d575e 100644 --- a/src/wormhole/test/dilate/test_connect.py +++ b/src/wormhole/test/dilate/test_connect.py @@ -52,7 +52,7 @@ class Connect(unittest.TestCase): t_left = FakeTerminator() t_right = FakeTerminator() - d_left = manager.Dilator(reactor, eq, cooperator, no_listen=True) + d_left = manager.Dilator(reactor, eq, cooperator) d_left.wire(send_left, t_left) d_left.got_key(key) d_left.got_wormhole_versions({"can-dilate": ["1"]}) @@ -66,7 +66,7 @@ class Connect(unittest.TestCase): with mock.patch("wormhole._dilation.connector.ipaddrs.find_addresses", return_value=["127.0.0.1"]): - eps_left_d = d_left.dilate() + eps_left_d = d_left.dilate(no_listen=True) eps_right_d = d_right.dilate() eps_left = yield eps_left_d diff --git a/src/wormhole/test/dilate/test_manager.py b/src/wormhole/test/dilate/test_manager.py index b8258f1..42ef0f6 100644 --- a/src/wormhole/test/dilate/test_manager.py +++ b/src/wormhole/test/dilate/test_manager.py @@ -66,7 +66,7 @@ class TestDilator(unittest.TestCase): dil.got_wormhole_versions({"can-dilate": ["1"]}) # that should create the Manager self.assertEqual(ml.mock_calls, [mock.call(send, "us", transit_key, - None, reactor, eq, coop, no_listen=False)]) + None, reactor, eq, coop, False)]) # and tell it to start, and get wait-for-it-to-connect Deferred self.assertEqual(m.mock_calls, [mock.call.start(), mock.call.when_first_connected(), @@ -182,7 +182,7 @@ class TestDilator(unittest.TestCase): return_value="us"): dil.got_wormhole_versions({"can-dilate": ["1"]}) self.assertEqual(ml.mock_calls, [mock.call(send, "us", b"key", - None, reactor, eq, coop, no_listen=False)]) + None, reactor, eq, coop, False)]) self.assertEqual(m.mock_calls, [mock.call.start(), mock.call.rx_PLEASE(pleasemsg), mock.call.rx_HINTS(hintmsg), @@ -200,7 +200,7 @@ class TestDilator(unittest.TestCase): return_value="us"): dil.got_wormhole_versions({"can-dilate": ["1"]}) self.assertEqual(ml.mock_calls, [mock.call(send, "us", b"key", - relay, reactor, eq, coop, no_listen=False), + relay, reactor, eq, coop, False), mock.call().start(), mock.call().when_first_connected()]) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 7d1ef24..1e5509d 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -193,10 +193,10 @@ class _DeferredWormhole(object): raise NoKeyError() return derive_key(self._key, to_bytes(purpose), length) - def dilate(self): + def dilate(self, no_listen=False): if not self._enable_dilate: raise NotImplementedError - return self._boss.dilate() # fires with (endpoints) + return self._boss.dilate(no_listen) # fires with (endpoints) def close(self): # fails with WormholeError unless we established a connection