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