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.
This commit is contained in:
Brian Warner 2019-05-06 21:35:30 -07:00
parent 7eb1201379
commit 55056bd324
5 changed files with 13 additions and 14 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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

View File

@ -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()])

View File

@ -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