From 56fec496e22e7d69f5ec59cd7f64a0fe35af46dd Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 26 May 2016 16:26:00 -0700 Subject: [PATCH] send transit abilities to far end too, for the future This will allow a future peer to figure out what transit modes we can and cannot do, and thus avoid spinning up expensive modes that we won't be able to use (e.g. WebRTC). --- src/wormhole/cli/cmd_receive.py | 5 ++++- src/wormhole/cli/cmd_send.py | 8 ++++++-- src/wormhole/transit.py | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index 7ffa6b6..38a7afc 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -149,8 +149,11 @@ class TwistedReceiver: tr.set_transit_key(transit_key) tr.add_connection_hints(sender_transit.get("hints-v1", [])) + receiver_abilities = tr.get_connection_abilities() receiver_hints = yield tr.get_connection_hints() - receiver_transit = {"hints-v1": receiver_hints} + receiver_transit = {"abilities-v1": receiver_abilities, + "hints-v1": receiver_hints, + } self._send_data({u"transit": receiver_transit}, w) # TODO: send more hints as the TransitReceiver produces them diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index ffb6d02..2341115 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -106,8 +106,12 @@ class Sender: self._transit_sender = ts # for now, send this before the main offer - hints = yield ts.get_connection_hints() - self._send_data({u"transit": {"hints-v1": hints}}, w) + sender_abilities = ts.get_connection_abilities() + sender_hints = yield ts.get_connection_hints() + sender_transit = {"abilities-v1": sender_abilities, + "hints-v1": sender_hints, + } + self._send_data({u"transit": sender_transit}, w) # TODO: move this down below w.get() transit_key = w.derive_key(APPID+"/transit-key", diff --git a/src/wormhole/transit.py b/src/wormhole/transit.py index be27db4..9e268e8 100644 --- a/src/wormhole/transit.py +++ b/src/wormhole/transit.py @@ -602,6 +602,11 @@ class Common: ep = endpoints.serverFromString(reactor, "tcp:%d" % portnum) return direct_hints, ep + def get_connection_abilities(self): + return [{u"type": u"direct-tcp-v1"}, + {u"type": u"relay-v1"}, + ] + @inlineCallbacks def get_connection_hints(self): hints = []