From 4f8aa5a69ed012745a1dcd128a0c075e359dc485 Mon Sep 17 00:00:00 2001 From: Baeumla Date: Thu, 8 Mar 2018 11:54:27 +0100 Subject: [PATCH] report clinet version on bind --- src/wormhole/_boss.py | 6 +++++- src/wormhole/_rendezvous.py | 5 ++++- src/wormhole/cli/cli.py | 1 + src/wormhole/cli/cmd_receive.py | 2 ++ src/wormhole/cli/cmd_send.py | 2 ++ src/wormhole/test/test_machines.py | 14 ++++++++++---- src/wormhole/test/test_wormhole.py | 8 ++++---- src/wormhole/wormhole.py | 10 ++++++++-- 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/wormhole/_boss.py b/src/wormhole/_boss.py index 33c00e2..cd97145 100644 --- a/src/wormhole/_boss.py +++ b/src/wormhole/_boss.py @@ -32,10 +32,12 @@ 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""))) _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 @@ -52,7 +54,9 @@ class Boss(object): self._R = Receive(self._side, self._timing) self._RC = RendezvousConnector(self._url, self._appid, self._side, self._reactor, self._journal, - self._tor, self._timing) + self._tor, self._timing, + self._wormhole_version, + self._implementation) self._L = Lister(self._timing) self._A = Allocator(self._timing) self._I = Input(self._timing) diff --git a/src/wormhole/_rendezvous.py b/src/wormhole/_rendezvous.py index 28a64cd..e55b902 100644 --- a/src/wormhole/_rendezvous.py +++ b/src/wormhole/_rendezvous.py @@ -67,6 +67,8 @@ 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""))) def __attrs_post_init__(self): self._have_made_a_successful_connection = False @@ -165,7 +167,8 @@ class RendezvousConnector(object): self._have_made_a_successful_connection = True self._ws = proto 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._M.connected() self._L.connected() diff --git a/src/wormhole/cli/cli.py b/src/wormhole/cli/cli.py index 58ccd8f..9be4545 100644 --- a/src/wormhole/cli/cli.py +++ b/src/wormhole/cli/cli.py @@ -94,6 +94,7 @@ 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 diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index 1cb457b..3cd48d1 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -47,6 +47,7 @@ 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) @@ -67,6 +68,7 @@ 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 diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 969ab0f..2d37d2c 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -34,6 +34,7 @@ class Sender: self._timing = args.timing self._fd_to_send = None self._transit_sender = None + self._version = {"v1" : args.version} @inlineCallbacks def go(self): @@ -52,6 +53,7 @@ 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) diff --git a/src/wormhole/test/test_machines.py b/src/wormhole/test/test_machines.py index 52a2d0c..1250e56 100644 --- a/src/wormhole/test/test_machines.py +++ b/src/wormhole/test/test_machines.py @@ -1216,12 +1216,14 @@ 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" b = MockBoss(wormhole, "side", "url", "appid", versions, - reactor, journal, tor_manager, - timing.DebugTiming()) + version, reactor, journal, tor_manager, + timing.DebugTiming(), implementation) b._T = Dummy("t", events, ITerminator, "close") b._S = Dummy("s", events, ISend, "send") b._RC = Dummy("rc", events, IRendezvousConnector, "start") @@ -1449,10 +1451,13 @@ class Rendezvous(unittest.TestCase): reactor = object() journal = ImmediateJournal() tor_manager = None + wormhole_version = "version1" + implementation = "python" rc = _rendezvous.RendezvousConnector("ws://host:4000/v1", "appid", "side", reactor, journal, tor_manager, - timing.DebugTiming()) + timing.DebugTiming(), + wormhole_version, implementation) b = Dummy("b", events, IBoss, "error") n = Dummy("n", events, INameplate, "connected", "lost") m = Dummy("m", events, IMailbox, "connected", "lost") @@ -1502,7 +1507,8 @@ class Rendezvous(unittest.TestCase): yield bytes_to_dict(c[1][0]) self.assertEqual(list(sent_messages(ws)), [dict(appid="appid", side="side", id="0000", - type="bind"), + type="bind", wormhole_version="version1", + implementation="python"), ]) rc.ws_close(True, None, None) diff --git a/src/wormhole/test/test_wormhole.py b/src/wormhole/test/test_wormhole.py index df5830f..ce3e302 100644 --- a/src/wormhole/test/test_wormhole.py +++ b/src/wormhole/test/test_wormhole.py @@ -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() diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 72feb07..12a9c7e 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -230,8 +230,14 @@ 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 - b = Boss(w, side, relay_url, appid, wormhole_versions, - reactor, journal, tor, timing) + #version to be sent with bind if provided + 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) b.start() return w