diff --git a/docs/api.md b/docs/api.md index 1f4e084..eff862d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -53,7 +53,7 @@ The synchronous+blocking flow looks like this: from wormhole.blocking.transcribe import Wormhole from wormhole.public_relay import RENDEZVOUS_RELAY mydata = b"initiator's data" -i = Wormhole("appid", RENDEZVOUS_RELAY) +i = Wormhole(b"appid", RENDEZVOUS_RELAY) code = i.get_code() print("Invitation Code: %s" % code) theirdata = i.get_data(mydata) @@ -66,7 +66,7 @@ from wormhole.blocking.transcribe import Wormhole from wormhole.public_relay import RENDEZVOUS_RELAY mydata = b"receiver's data" code = sys.argv[1] -r = Wormhole("appid", RENDEZVOUS_RELAY) +r = Wormhole(b"appid", RENDEZVOUS_RELAY) r.set_code(code) theirdata = r.get_data(mydata) print("Their data: %s" % theirdata.decode("ascii")) @@ -81,7 +81,7 @@ from twisted.internet import reactor from wormhole.public_relay import RENDEZVOUS_RELAY from wormhole.twisted.transcribe import Wormhole outbound_message = b"outbound data" -w1 = Wormhole("appid", RENDEZVOUS_RELAY) +w1 = Wormhole(b"appid", RENDEZVOUS_RELAY) d = w1.get_code() def _got_code(code): print "Invitation Code:", code @@ -97,7 +97,7 @@ reactor.run() On the other side, you call `set_code()` instead of waiting for `get_code()`: ```python -w2 = Wormhole("appid", RENDEZVOUS_RELAY) +w2 = Wormhole(b"appid", RENDEZVOUS_RELAY) w2.set_code(code) d = w2.get_data(my_message) ... @@ -140,7 +140,8 @@ simple bytestring that distinguishes one application from another. To ensure uniqueness, use a domain name. To use multiple apps for a single domain, just use a string like `example.com/app1`. This string must be the same on both clients, otherwise they will not see each other. The invitation codes are -scoped to the app-id. +scoped to the app-id. Note that the app-id must be a bytestring, not unicode, +so on python3 use `b"appid"`. Distinct app-ids reduce the size of the connection-id numbers. If fewer than ten initiators are active for a given app-id, the connection-id will only diff --git a/src/wormhole/blocking/transcribe.py b/src/wormhole/blocking/transcribe.py index 6a6c250..af57fcb 100644 --- a/src/wormhole/blocking/transcribe.py +++ b/src/wormhole/blocking/transcribe.py @@ -29,6 +29,7 @@ class Wormhole: version_warning_displayed = False def __init__(self, appid, relay): + if not isinstance(appid, type(b"")): raise UsageError self.appid = appid self.relay = relay if not self.relay.endswith("/"): raise UsageError diff --git a/src/wormhole/scripts/cmd_receive_file.py b/src/wormhole/scripts/cmd_receive_file.py index c215da1..2612544 100644 --- a/src/wormhole/scripts/cmd_receive_file.py +++ b/src/wormhole/scripts/cmd_receive_file.py @@ -2,7 +2,7 @@ from __future__ import print_function import sys, os, json, binascii from ..errors import handle_server_error -APPID = "lothar.com/wormhole/file-xfer" +APPID = b"lothar.com/wormhole/file-xfer" @handle_server_error def receive_file(args): @@ -50,7 +50,7 @@ def receive_file(args): # now receive the rest of the owl tdata = data["transit"] - transit_key = w.derive_key(APPID+"/transit-key") + transit_key = w.derive_key(APPID+b"/transit-key") transit_receiver.set_transit_key(transit_key) transit_receiver.add_their_direct_hints(tdata["direct_connection_hints"]) transit_receiver.add_their_relay_hints(tdata["relay_connection_hints"]) diff --git a/src/wormhole/scripts/cmd_receive_text.py b/src/wormhole/scripts/cmd_receive_text.py index ea374c2..928ad61 100644 --- a/src/wormhole/scripts/cmd_receive_text.py +++ b/src/wormhole/scripts/cmd_receive_text.py @@ -2,7 +2,7 @@ from __future__ import print_function import sys, json, binascii from ..errors import handle_server_error -APPID = "lothar.com/wormhole/text-xfer" +APPID = b"lothar.com/wormhole/text-xfer" @handle_server_error def receive_text(args): diff --git a/src/wormhole/scripts/cmd_send_file.py b/src/wormhole/scripts/cmd_send_file.py index 3d3046d..22da29c 100644 --- a/src/wormhole/scripts/cmd_send_file.py +++ b/src/wormhole/scripts/cmd_send_file.py @@ -2,7 +2,7 @@ from __future__ import print_function import os, sys, json, binascii from ..errors import handle_server_error -APPID = "lothar.com/wormhole/file-xfer" +APPID = b"lothar.com/wormhole/file-xfer" @handle_server_error def send_file(args): @@ -70,7 +70,7 @@ def send_file(args): tdata = them_d["transit"] - transit_key = w.derive_key(APPID+"/transit-key") + transit_key = w.derive_key(APPID+b"/transit-key") transit_sender.set_transit_key(transit_key) transit_sender.add_their_direct_hints(tdata["direct_connection_hints"]) transit_sender.add_their_relay_hints(tdata["relay_connection_hints"]) diff --git a/src/wormhole/scripts/cmd_send_text.py b/src/wormhole/scripts/cmd_send_text.py index 7651cb1..2041e6f 100644 --- a/src/wormhole/scripts/cmd_send_text.py +++ b/src/wormhole/scripts/cmd_send_text.py @@ -2,7 +2,7 @@ from __future__ import print_function import sys, json, binascii from ..errors import handle_server_error -APPID = "lothar.com/wormhole/text-xfer" +APPID = b"lothar.com/wormhole/text-xfer" @handle_server_error def send_text(args): diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index e299d9e..769642d 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -10,7 +10,7 @@ class Blocking(ServerBase, unittest.TestCase): # with deferToThread() def test_basic(self): - appid = "appid" + appid = b"appid" w1 = BlockingWormhole(appid, self.relayurl) w2 = BlockingWormhole(appid, self.relayurl) d = deferToThread(w1.get_code) @@ -31,7 +31,7 @@ class Blocking(ServerBase, unittest.TestCase): return d def test_fixed_code(self): - appid = "appid" + appid = b"appid" w1 = BlockingWormhole(appid, self.relayurl) w2 = BlockingWormhole(appid, self.relayurl) w1.set_code("123-purple-elephant") @@ -50,7 +50,7 @@ class Blocking(ServerBase, unittest.TestCase): return d def test_errors(self): - appid = "appid" + appid = b"appid" w1 = BlockingWormhole(appid, self.relayurl) self.assertRaises(UsageError, w1.get_verifier) self.assertRaises(UsageError, w1.get_data, "data") @@ -65,7 +65,7 @@ class Blocking(ServerBase, unittest.TestCase): return d def test_serialize(self): - appid = "appid" + appid = b"appid" w1 = BlockingWormhole(appid, self.relayurl) self.assertRaises(UsageError, w1.serialize) # too early w2 = BlockingWormhole(appid, self.relayurl) diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index 9376f86..533b62f 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -9,7 +9,7 @@ from .common import ServerBase class Basic(ServerBase, unittest.TestCase): def test_basic(self): - appid = "appid" + appid = b"appid" w1 = Wormhole(appid, self.relayurl) w2 = Wormhole(appid, self.relayurl) d = w1.get_code() @@ -30,7 +30,7 @@ class Basic(ServerBase, unittest.TestCase): return d def test_fixed_code(self): - appid = "appid" + appid = b"appid" w1 = Wormhole(appid, self.relayurl) w2 = Wormhole(appid, self.relayurl) w1.set_code("123-purple-elephant") @@ -49,7 +49,7 @@ class Basic(ServerBase, unittest.TestCase): return d def test_errors(self): - appid = "appid" + appid = b"appid" w1 = Wormhole(appid, self.relayurl) self.assertRaises(UsageError, w1.get_verifier) self.assertRaises(UsageError, w1.get_data, "data") @@ -62,7 +62,7 @@ class Basic(ServerBase, unittest.TestCase): return d def test_serialize(self): - appid = "appid" + appid = b"appid" w1 = Wormhole(appid, self.relayurl) self.assertRaises(UsageError, w1.serialize) # too early w2 = Wormhole(appid, self.relayurl) diff --git a/src/wormhole/twisted/transcribe.py b/src/wormhole/twisted/transcribe.py index ee047dd..40bf6e9 100644 --- a/src/wormhole/twisted/transcribe.py +++ b/src/wormhole/twisted/transcribe.py @@ -38,6 +38,7 @@ class Wormhole: version_warning_displayed = False def __init__(self, appid, relay): + if not isinstance(appid, type(b"")): raise UsageError self.appid = appid self.relay = relay self.agent = web_client.Agent(reactor)