From 7f6410812cab8859c1d1bd1b0557513b4636002e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 6 Oct 2015 19:29:59 -0700 Subject: [PATCH] transit URL, transit hints are now unicode --- docs/api.md | 4 ++-- src/wormhole/blocking/transit.py | 17 +++++++++++++---- src/wormhole/public_relay.py | 2 +- src/wormhole/scripts/runner.py | 3 ++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/api.md b/docs/api.md index 26d1129..e6040f5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -252,12 +252,12 @@ Some human-readable parameters are passed as strings: "str" in python2, "str" (i.e. unicode) in python3: * wormhole code -* transit URLs -* transit connection hints (e.g. "host:port") And some are always unicode, in both python2 and python3: * relay URL +* transit URLs +* transit connection hints (e.g. "host:port") * application identifier * derived-key "purpose" string: `w.derive_key(PURPOSE)` diff --git a/src/wormhole/blocking/transit.py b/src/wormhole/blocking/transit.py index 49b6cce..d0b728d 100644 --- a/src/wormhole/blocking/transit.py +++ b/src/wormhole/blocking/transit.py @@ -84,7 +84,7 @@ def wait_for(skt, expected, description): # publisher wants anonymity, their only hint's ADDR will end in .onion . def parse_hint_tcp(hint): - assert isinstance(hint, str) + assert isinstance(hint, type(u"")) # return tuple or None for an unparseable hint mo = re.search(r'^([a-zA-Z0-9]+):(.*)$', hint) if not mo: @@ -269,6 +269,7 @@ class RecordPipe: class Common: def __init__(self, transit_relay): + if not isinstance(transit_relay, type(u"")): raise UsageError self._transit_relay = transit_relay self.winning = threading.Event() self._negotiation_check_lock = threading.Lock() @@ -279,7 +280,7 @@ class Common: def _start_server(self): server = MyTCPServer(("", 0), None) _, port = server.server_address - self.my_direct_hints = ["tcp:%s:%d" % (addr, port) + self.my_direct_hints = [u"tcp:%s:%d" % (addr, port) for addr in ipaddrs.find_addresses()] server.owner = self server_thread = threading.Thread(target=server.serve_forever) @@ -293,9 +294,17 @@ class Common: return [self._transit_relay] def add_their_direct_hints(self, hints): - self._their_direct_hints = [str(h) for h in hints] + for h in hints: + if not isinstance(h, type(u"")): + raise TypeError("hint '%r' should be unicode, not %s" + % (h, type(h))) + self._their_direct_hints = list(hints) def add_their_relay_hints(self, hints): - self._their_relay_hints = [str(h) for h in hints] + for h in hints: + if not isinstance(h, type(u"")): + raise TypeError("hint '%r' should be unicode, not %s" + % (h, type(h))) + self._their_relay_hints = list(hints) def _send_this(self): if self.is_sender: diff --git a/src/wormhole/public_relay.py b/src/wormhole/public_relay.py index f486662..de7b339 100644 --- a/src/wormhole/public_relay.py +++ b/src/wormhole/public_relay.py @@ -2,4 +2,4 @@ # This is a relay I run on a personal server. If it gets too expensive to # run, I'll shut it down. RENDEZVOUS_RELAY = u"http://wormhole-relay.petmail.org:3000/wormhole-relay/" -TRANSIT_RELAY = "tcp:wormhole-transit-relay.petmail.org:3001" +TRANSIT_RELAY = u"tcp:wormhole-transit-relay.petmail.org:3001" diff --git a/src/wormhole/scripts/runner.py b/src/wormhole/scripts/runner.py index 620c7c8..18b38c7 100644 --- a/src/wormhole/scripts/runner.py +++ b/src/wormhole/scripts/runner.py @@ -20,7 +20,8 @@ g = parser.add_argument_group("wormhole configuration options") g.add_argument("--relay-url", default=public_relay.RENDEZVOUS_RELAY, metavar="URL", help="rendezvous relay to use", type=type(u"")) g.add_argument("--transit-helper", default=public_relay.TRANSIT_RELAY, - metavar="tcp:HOST:PORT", help="transit relay to use") + metavar="tcp:HOST:PORT", help="transit relay to use", + type=type(u"")) g.add_argument("-c", "--code-length", type=int, default=2, metavar="WORDS", help="length of code (in bytes/words)") g.add_argument("-v", "--verify", action="store_true",