bind passes tuple, fixed implementation issues
This commit is contained in:
parent
82dc4a4e2e
commit
e77a2d605b
|
@ -32,12 +32,11 @@ class Boss(object):
|
|||
_url = attrib(validator=instance_of(type(u"")))
|
||||
_appid = attrib(validator=instance_of(type(u"")))
|
||||
_versions = attrib(validator=instance_of(dict))
|
||||
_wormhole_version = attrib(validator=instance_of(type(u"")))
|
||||
_client_version = attrib(validator=instance_of(tuple))
|
||||
_reactor = attrib()
|
||||
_journal = attrib(validator=provides(_interfaces.IJournal))
|
||||
_tor = attrib(validator=optional(provides(_interfaces.ITorManager)))
|
||||
_timing = attrib(validator=provides(_interfaces.ITiming))
|
||||
_implementation = attrib(validator=instance_of(type(u"")))
|
||||
m = MethodicalMachine()
|
||||
set_trace = getattr(m, "_setTrace", lambda self, f: None) # pragma: no cover
|
||||
|
||||
|
@ -55,8 +54,7 @@ class Boss(object):
|
|||
self._RC = RendezvousConnector(self._url, self._appid, self._side,
|
||||
self._reactor, self._journal,
|
||||
self._tor, self._timing,
|
||||
self._wormhole_version,
|
||||
self._implementation)
|
||||
self._client_version)
|
||||
self._L = Lister(self._timing)
|
||||
self._A = Allocator(self._timing)
|
||||
self._I = Input(self._timing)
|
||||
|
|
|
@ -67,8 +67,7 @@ class RendezvousConnector(object):
|
|||
_journal = attrib(validator=provides(_interfaces.IJournal))
|
||||
_tor = attrib(validator=optional(provides(_interfaces.ITorManager)))
|
||||
_timing = attrib(validator=provides(_interfaces.ITiming))
|
||||
_wormhole_version = attrib(validator=instance_of(type(u"")))
|
||||
_implementation = attrib(validator=instance_of(type(u"")))
|
||||
_client_version = attrib(validator=instance_of(tuple))
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
self._have_made_a_successful_connection = False
|
||||
|
@ -168,7 +167,7 @@ class RendezvousConnector(object):
|
|||
self._ws = proto
|
||||
try:
|
||||
self._tx("bind", appid=self._appid, side=self._side,
|
||||
implementation=self._implementation, wormhole_version=self._wormhole_version)
|
||||
client_version=self._client_version)
|
||||
self._N.connected()
|
||||
self._M.connected()
|
||||
self._L.connected()
|
||||
|
|
|
@ -94,7 +94,6 @@ def wormhole(context, dump_timing, transit_helper, relay_url, appid):
|
|||
cfg.relay_url = relay_url
|
||||
cfg.transit_helper = transit_helper
|
||||
cfg.dump_timing = dump_timing
|
||||
cfg.version = __version__
|
||||
|
||||
|
||||
@inlineCallbacks
|
||||
|
|
|
@ -47,7 +47,6 @@ class Receiver:
|
|||
self._reactor = reactor
|
||||
self._tor = None
|
||||
self._transit_receiver = None
|
||||
self._version = {"v1" : args.version}
|
||||
|
||||
def _msg(self, *args, **kwargs):
|
||||
print(*args, file=self.args.stderr, **kwargs)
|
||||
|
@ -68,7 +67,6 @@ class Receiver:
|
|||
|
||||
w = create(self.args.appid or APPID, self.args.relay_url,
|
||||
self._reactor,
|
||||
versions = self._version,
|
||||
tor=self._tor,
|
||||
timing=self.args.timing)
|
||||
self._w = w # so tests can wait on events too
|
||||
|
|
|
@ -34,7 +34,6 @@ class Sender:
|
|||
self._timing = args.timing
|
||||
self._fd_to_send = None
|
||||
self._transit_sender = None
|
||||
self._version = {"v1" : args.version}
|
||||
|
||||
@inlineCallbacks
|
||||
def go(self):
|
||||
|
@ -53,7 +52,6 @@ class Sender:
|
|||
|
||||
w = create(self._args.appid or APPID, self._args.relay_url,
|
||||
self._reactor,
|
||||
versions = self._version,
|
||||
tor=self._tor,
|
||||
timing=self._timing)
|
||||
d = self._go(w)
|
||||
|
|
|
@ -5,7 +5,7 @@ from zope.interface import directlyProvides, implementer
|
|||
from twisted.trial import unittest
|
||||
from .. import (errors, timing, _order, _receive, _key, _code, _lister, _boss,
|
||||
_input, _allocator, _send, _terminator, _nameplate, _mailbox,
|
||||
_rendezvous)
|
||||
_rendezvous, __version__)
|
||||
from .._interfaces import (IKey, IReceive, IBoss, ISend, IMailbox, IOrder,
|
||||
IRendezvousConnector, ILister, IInput, IAllocator,
|
||||
INameplate, ICode, IWordlist, ITerminator)
|
||||
|
@ -1216,14 +1216,13 @@ class Boss(unittest.TestCase):
|
|||
"got_code", "got_key", "got_verifier", "got_versions",
|
||||
"received", "closed")
|
||||
versions = {"app": "version1"}
|
||||
version = "version1"
|
||||
reactor = None
|
||||
journal = ImmediateJournal()
|
||||
tor_manager = None
|
||||
implementation = "python"
|
||||
client_version = ("python", __version__)
|
||||
b = MockBoss(wormhole, "side", "url", "appid", versions,
|
||||
version, reactor, journal, tor_manager,
|
||||
timing.DebugTiming(), implementation)
|
||||
client_version, reactor, journal, tor_manager,
|
||||
timing.DebugTiming())
|
||||
b._T = Dummy("t", events, ITerminator, "close")
|
||||
b._S = Dummy("s", events, ISend, "send")
|
||||
b._RC = Dummy("rc", events, IRendezvousConnector, "start")
|
||||
|
@ -1451,13 +1450,13 @@ class Rendezvous(unittest.TestCase):
|
|||
reactor = object()
|
||||
journal = ImmediateJournal()
|
||||
tor_manager = None
|
||||
wormhole_version = "version1"
|
||||
implementation = "python"
|
||||
client_version = ("python", __version__)
|
||||
print(client_version)
|
||||
rc = _rendezvous.RendezvousConnector("ws://host:4000/v1", "appid",
|
||||
"side", reactor,
|
||||
journal, tor_manager,
|
||||
timing.DebugTiming(),
|
||||
wormhole_version, implementation)
|
||||
timing.DebugTiming(),
|
||||
client_version)
|
||||
b = Dummy("b", events, IBoss, "error")
|
||||
n = Dummy("n", events, INameplate, "connected", "lost")
|
||||
m = Dummy("m", events, IMailbox, "connected", "lost")
|
||||
|
@ -1506,9 +1505,9 @@ class Rendezvous(unittest.TestCase):
|
|||
self.assertEqual(c[1][1], False, ws.mock_calls)
|
||||
yield bytes_to_dict(c[1][0])
|
||||
self.assertEqual(list(sent_messages(ws)),
|
||||
[dict(appid="appid", side="side", id="0000",
|
||||
type="bind", wormhole_version="version1",
|
||||
implementation="python"),
|
||||
[dict(appid="appid", side="side",
|
||||
client_version=["python", __version__],
|
||||
id="0000", type="bind"),
|
||||
])
|
||||
|
||||
rc.ws_close(True, None, None)
|
||||
|
|
|
@ -526,16 +526,16 @@ class Wormholes(ServerBase, unittest.TestCase):
|
|||
def test_versions(self):
|
||||
# there's no API for this yet, but make sure the internals work
|
||||
w1 = wormhole.create(APPID, self.relayurl, reactor,
|
||||
versions={"w1": "123"})
|
||||
versions={"w1": 123})
|
||||
w2 = wormhole.create(APPID, self.relayurl, reactor,
|
||||
versions={"w2": "456"})
|
||||
versions={"w2": 456})
|
||||
w1.allocate_code()
|
||||
code = yield w1.get_code()
|
||||
w2.set_code(code)
|
||||
w1_versions = yield w2.get_versions()
|
||||
self.assertEqual(w1_versions, {"w1": "123"})
|
||||
self.assertEqual(w1_versions, {"w1": 123})
|
||||
w2_versions = yield w1.get_versions()
|
||||
self.assertEqual(w2_versions, {"w2": "456"})
|
||||
self.assertEqual(w2_versions, {"w2": 456})
|
||||
yield w1.close()
|
||||
yield w2.close()
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import os, sys
|
|||
from attr import attrs, attrib
|
||||
from zope.interface import implementer
|
||||
from twisted.python import failure
|
||||
from . import __version__
|
||||
from ._interfaces import IWormhole, IDeferredWormhole
|
||||
from .util import bytes_to_hexstr
|
||||
from .eventual import EventualQueue
|
||||
|
@ -230,18 +231,9 @@ def create(appid, relay_url, reactor, # use keyword args for everything else
|
|||
w = _DeferredWormhole(eq)
|
||||
wormhole_versions = {} # will be used to indicate Wormhole capabilities
|
||||
wormhole_versions["app_versions"] = versions # app-specific capabilities
|
||||
#version to be sent with bind if provided
|
||||
wormhole_version = u""
|
||||
if type(versions) is dict and versions != {} :
|
||||
wormhole_version = list(versions.values())[0] or ""
|
||||
else:
|
||||
wormhole_version = versions or ""
|
||||
#workaround for py2.7, py3.X
|
||||
if sys.version_info < (3, 0):
|
||||
wormhole_version = wormhole_version.decode('unicode-escape')
|
||||
implementation = "python"
|
||||
b = Boss(w, side, relay_url, appid, wormhole_versions, wormhole_version,
|
||||
reactor, journal, tor, timing, implementation)
|
||||
client_version = ("python", __version__.decode("utf-8", errors="replace"))
|
||||
b = Boss(w, side, relay_url, appid, wormhole_versions, client_version,
|
||||
reactor, journal, tor, timing)
|
||||
w._set_boss(b)
|
||||
b.start()
|
||||
return w
|
||||
|
@ -255,6 +247,6 @@ def create(appid, relay_url, reactor, # use keyword args for everything else
|
|||
## # now unpack state machines, including the SPAKE2 in Key
|
||||
## b = Boss.from_serialized(w, serialized["boss"], reactor, journal, timing)
|
||||
## w._set_boss(b)
|
||||
## b .start() # ??
|
||||
## b.start() # ??
|
||||
## raise NotImplemented
|
||||
## # should the new Wormhole call got_code? only if it wasn't called before.
|
||||
|
|
Loading…
Reference in New Issue
Block a user