wormhole.py: add debug switch to enable dilation (for tests)

This commit is contained in:
Brian Warner 2019-02-10 11:44:11 -08:00
parent 6bd7e85a53
commit be2dc01a94

View File

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