report clinet version on bind

This commit is contained in:
Baeumla 2018-03-08 11:54:27 +01:00
parent 86edf01070
commit 4f8aa5a69e
8 changed files with 36 additions and 12 deletions

View File

@ -32,10 +32,12 @@ 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"")))
_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
@ -52,7 +54,9 @@ class Boss(object):
self._R = Receive(self._side, self._timing) self._R = Receive(self._side, self._timing)
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._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)

View File

@ -67,6 +67,8 @@ 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"")))
_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
@ -165,7 +167,8 @@ class RendezvousConnector(object):
self._have_made_a_successful_connection = True self._have_made_a_successful_connection = True
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)
self._N.connected() self._N.connected()
self._M.connected() self._M.connected()
self._L.connected() self._L.connected()

View File

@ -94,6 +94,7 @@ 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

View File

@ -47,6 +47,7 @@ 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)
@ -67,6 +68,7 @@ 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

View File

@ -34,6 +34,7 @@ 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):
@ -52,6 +53,7 @@ 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)

View File

@ -1216,12 +1216,14 @@ 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"
b = MockBoss(wormhole, "side", "url", "appid", versions, b = MockBoss(wormhole, "side", "url", "appid", versions,
reactor, journal, tor_manager, version, reactor, journal, tor_manager,
timing.DebugTiming()) timing.DebugTiming(), implementation)
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")
@ -1449,10 +1451,13 @@ class Rendezvous(unittest.TestCase):
reactor = object() reactor = object()
journal = ImmediateJournal() journal = ImmediateJournal()
tor_manager = None tor_manager = None
wormhole_version = "version1"
implementation = "python"
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)
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")
@ -1502,7 +1507,8 @@ class Rendezvous(unittest.TestCase):
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", id="0000",
type="bind"), type="bind", wormhole_version="version1",
implementation="python"),
]) ])
rc.ws_close(True, None, None) rc.ws_close(True, None, None)

View File

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

View File

@ -230,8 +230,14 @@ 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
b = Boss(w, side, relay_url, appid, wormhole_versions, #version to be sent with bind if provided
reactor, journal, tor, timing) if type(versions) is dict and versions != {} :
wormhole_version = list(versions.values())[0] or ""
else:
wormhole_version = versions or ""
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