From be2dc01a94c7861d8ca19a14df264f8c35a5d509 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 10 Feb 2019 11:44:11 -0800 Subject: [PATCH] wormhole.py: add debug switch to enable dilation (for tests) --- src/wormhole/wormhole.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index e17b7a1..7d1ef24 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -125,7 +125,7 @@ class _DelegatedWormhole(object): @implementer(IWormhole, IDeferredWormhole) class _DeferredWormhole(object): - def __init__(self, reactor, eq): + def __init__(self, reactor, eq, _enable_dilate=False): self._reactor = reactor self._welcome_observer = OneShotObserver(eq) self._code_observer = OneShotObserver(eq) @@ -137,6 +137,8 @@ class _DeferredWormhole(object): self._closed = False self._closed_observer = OneShotObserver(eq) + self._enable_dilate = _enable_dilate + def _set_boss(self, boss): self._boss = boss @@ -192,7 +194,8 @@ class _DeferredWormhole(object): return derive_key(self._key, to_bytes(purpose), length) def dilate(self): - raise NotImplementedError + if not self._enable_dilate: + raise NotImplementedError return self._boss.dilate() # fires with (endpoints) def close(self): @@ -261,7 +264,8 @@ def create( tor=None, timing=None, stderr=sys.stderr, - _eventual_queue=None): + _eventual_queue=None, + _enable_dilate=False): timing = timing or DebugTiming() side = bytes_to_hexstr(os.urandom(5)) journal = journal or ImmediateJournal() @@ -270,13 +274,14 @@ def create( if delegate: w = _DelegatedWormhole(delegate) else: - w = _DeferredWormhole(reactor, eq) + w = _DeferredWormhole(reactor, eq, _enable_dilate=_enable_dilate) # this indicates Wormhole capabilities wormhole_versions = { "can-dilate": DILATION_VERSIONS, "dilation-abilities": Connector.get_connection_abilities(), } - wormhole_versions = {} # don't advertise Dilation yet: not ready + if not _enable_dilate: + wormhole_versions = {} # don't advertise Dilation yet: not ready wormhole_versions["app_versions"] = versions # app-specific capabilities v = __version__ if isinstance(v, type(b"")):