From 0b162af09e46cfc6359072e472fd48fca7d344b1 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 18 Apr 2016 16:24:13 -0700 Subject: [PATCH 1/3] move ipaddrs.py from wormhole.util to wormhole.twisted --- src/wormhole/{util => twisted}/ipaddrs.py | 0 src/wormhole/twisted/transit.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/wormhole/{util => twisted}/ipaddrs.py (100%) diff --git a/src/wormhole/util/ipaddrs.py b/src/wormhole/twisted/ipaddrs.py similarity index 100% rename from src/wormhole/util/ipaddrs.py rename to src/wormhole/twisted/ipaddrs.py diff --git a/src/wormhole/twisted/transit.py b/src/wormhole/twisted/transit.py index 199b361..d22f1ad 100644 --- a/src/wormhole/twisted/transit.py +++ b/src/wormhole/twisted/transit.py @@ -8,10 +8,10 @@ from twisted.internet import (reactor, interfaces, defer, protocol, from twisted.internet.defer import inlineCallbacks, returnValue from twisted.protocols import policies from nacl.secret import SecretBox -from ..util import ipaddrs from ..util.hkdf import HKDF from ..errors import UsageError from ..timing import DebugTiming +from . import ipaddrs def debug(msg): if False: From 323175ddfe9e45664c40717d9de6a2459959f115 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 15 Apr 2016 17:00:11 -0700 Subject: [PATCH 2/3] split txwormhole step 1: move files --- setup.py | 3 +- .../twisted => txwormhole}/__init__.py | 0 .../eventsource.py} | 0 src/{wormhole/util => txwormhole}/eventual.py | 0 .../twisted => txwormhole}/ipaddrs.py | 0 .../twisted => txwormhole}/tor_manager.py | 0 .../twisted => txwormhole}/transcribe.py | 0 .../twisted => txwormhole}/transit.py | 0 src/wormhole/twisted/demo.py | 72 ------------------- 9 files changed, 2 insertions(+), 73 deletions(-) rename src/{wormhole/twisted => txwormhole}/__init__.py (100%) rename src/{wormhole/twisted/eventsource_twisted.py => txwormhole/eventsource.py} (100%) rename src/{wormhole/util => txwormhole}/eventual.py (100%) rename src/{wormhole/twisted => txwormhole}/ipaddrs.py (100%) rename src/{wormhole/twisted => txwormhole}/tor_manager.py (100%) rename src/{wormhole/twisted => txwormhole}/transcribe.py (100%) rename src/{wormhole/twisted => txwormhole}/transit.py (100%) delete mode 100644 src/wormhole/twisted/demo.py diff --git a/setup.py b/setup.py index eba24cd..286d283 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,8 @@ setup(name="magic-wormhole", url="https://github.com/warner/magic-wormhole", package_dir={"": "src"}, packages=["wormhole", - "wormhole.blocking", "wormhole.twisted", + "wormhole.blocking", + "txwormhole", "wormhole.scripts", "wormhole.test", "wormhole.util", "wormhole_server"], package_data={"wormhole_server": ["db-schemas/*.sql"]}, diff --git a/src/wormhole/twisted/__init__.py b/src/txwormhole/__init__.py similarity index 100% rename from src/wormhole/twisted/__init__.py rename to src/txwormhole/__init__.py diff --git a/src/wormhole/twisted/eventsource_twisted.py b/src/txwormhole/eventsource.py similarity index 100% rename from src/wormhole/twisted/eventsource_twisted.py rename to src/txwormhole/eventsource.py diff --git a/src/wormhole/util/eventual.py b/src/txwormhole/eventual.py similarity index 100% rename from src/wormhole/util/eventual.py rename to src/txwormhole/eventual.py diff --git a/src/wormhole/twisted/ipaddrs.py b/src/txwormhole/ipaddrs.py similarity index 100% rename from src/wormhole/twisted/ipaddrs.py rename to src/txwormhole/ipaddrs.py diff --git a/src/wormhole/twisted/tor_manager.py b/src/txwormhole/tor_manager.py similarity index 100% rename from src/wormhole/twisted/tor_manager.py rename to src/txwormhole/tor_manager.py diff --git a/src/wormhole/twisted/transcribe.py b/src/txwormhole/transcribe.py similarity index 100% rename from src/wormhole/twisted/transcribe.py rename to src/txwormhole/transcribe.py diff --git a/src/wormhole/twisted/transit.py b/src/txwormhole/transit.py similarity index 100% rename from src/wormhole/twisted/transit.py rename to src/txwormhole/transit.py diff --git a/src/wormhole/twisted/demo.py b/src/wormhole/twisted/demo.py deleted file mode 100644 index bc552e2..0000000 --- a/src/wormhole/twisted/demo.py +++ /dev/null @@ -1,72 +0,0 @@ -from __future__ import print_function -import sys, json -from twisted.python import log -from twisted.internet import reactor -from .transcribe import Wormhole -from .. import public_relay - -APPID = u"lothar.com/wormhole/text-or-file-xfer" -relay_url = public_relay.RENDEZVOUS_RELAY - -w = Wormhole(APPID, relay_url) - -if sys.argv[1] == "send": - message = sys.argv[2] - data = json.dumps({"message": message}).encode("utf-8") - d = w.get_code() - def _got_code(code): - print("code is:", code) - return w.send_data(data) - d.addCallback(_got_code) - def _sent(_): - return w.get_data() - d.addCallback(_sent) - def _got_data(them_bytes): - them_d = json.loads(them_bytes.decode("utf-8")) - if them_d["message_ack"] == "ok": - print("text sent") - else: - print("error sending text: %r" % (them_d,)) - d.addCallback(_got_data) -elif sys.argv[1] == "receive": - code = sys.argv[2].decode("utf-8") - w.set_code(code) - d = w.get_data() - def _got_data(them_bytes): - them_d = json.loads(them_bytes.decode("utf-8")) - if "error" in them_d: - print("ERROR: " + them_d["error"], file=sys.stderr) - raise RuntimeError - if "file" in them_d: - print("they're trying to send us a file, which I don't handle") - data = json.dumps({"error": "not capable of receiving files"}) - d1 = w.send_data(data.encode("utf-8")) - d1.addCallback(lambda _: RuntimeError()) - return d1 - if not "message" in them_d: - print("I don't know what they're offering\n") - print(them_d) - data = json.dumps({"error": "huh?"}) - d1 = w.send_data(data.encode("utf-8")) - d1.addCallback(lambda _: RuntimeError()) - return d1 - print(them_d["message"]) - data = json.dumps({"message_ack": "ok"}) - d1 = w.send_data(data.encode("utf-8")) - d1.addCallback(lambda _: 0) - return d1 - d.addCallback(_got_data) -else: - raise ValueError("bad command") - -d.addBoth(w.close) -rc = [] -def _success(res): - rc.append(res) -def _fail(f): - log.err(f) - rc.append(1) -d.addCallbacks(_success, _fail) -d.addCallback(lambda _: reactor.stop()) -reactor.run() -sys.exit(rc[0]) From 1688da74d9e465d9ea3b1a0c10c0f192ed530196 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 15 Apr 2016 17:48:44 -0700 Subject: [PATCH 3/3] split txwormhole step 2: fix imports --- src/txwormhole/__init__.py | 2 ++ src/txwormhole/eventsource.py | 2 +- src/txwormhole/tor_manager.py | 2 +- src/txwormhole/transcribe.py | 14 +++++++------- src/txwormhole/transit.py | 6 +++--- src/wormhole/scripts/cmd_receive.py | 6 +++--- src/wormhole/scripts/cmd_send.py | 6 +++--- src/wormhole/test/common.py | 2 +- src/wormhole/test/test_interop.py | 2 +- src/wormhole/test/test_load.py | 2 ++ src/wormhole/test/test_server.py | 2 +- src/wormhole/test/test_transit_twisted.py | 2 +- src/wormhole/test/test_twisted.py | 6 +++--- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/txwormhole/__init__.py b/src/txwormhole/__init__.py index e69de29..0ff5129 100644 --- a/src/txwormhole/__init__.py +++ b/src/txwormhole/__init__.py @@ -0,0 +1,2 @@ +from wormhole import __version__ +__version__ # hush pyflakes diff --git a/src/txwormhole/eventsource.py b/src/txwormhole/eventsource.py index 0ea1647..19272ca 100644 --- a/src/txwormhole/eventsource.py +++ b/src/txwormhole/eventsource.py @@ -6,7 +6,7 @@ from twisted.protocols import basic from twisted.web.client import Agent, ResponseDone from twisted.web.http_headers import Headers from cgi import parse_header -from ..util.eventual import eventually +from .eventual import eventually #if sys.version_info[0] == 2: # to_unicode = unicode diff --git a/src/txwormhole/tor_manager.py b/src/txwormhole/tor_manager.py index 277f8b5..0625ca3 100644 --- a/src/txwormhole/tor_manager.py +++ b/src/txwormhole/tor_manager.py @@ -8,7 +8,7 @@ from twisted.internet.error import ConnectError from twisted.web import iweb import txtorcon import ipaddr -from ..timing import DebugTiming +from wormhole.timing import DebugTiming from .transit import allocate_tcp_port # based on twisted.web.client._StandardEndpointFactory diff --git a/src/txwormhole/transcribe.py b/src/txwormhole/transcribe.py index 585fbfd..cdb1aae 100644 --- a/src/txwormhole/transcribe.py +++ b/src/txwormhole/transcribe.py @@ -13,13 +13,13 @@ from nacl.secret import SecretBox from nacl.exceptions import CryptoError from nacl import utils from spake2 import SPAKE2_Symmetric -from .eventsource_twisted import ReconnectingEventSource -from .. import __version__ -from .. import codes -from ..errors import ServerError, Timeout, WrongPasswordError, UsageError -from ..timing import DebugTiming -from ..util.hkdf import HKDF -from ..channel_monitor import monitor +from .eventsource import ReconnectingEventSource +from wormhole import __version__ +from wormhole import codes +from wormhole.errors import ServerError, Timeout, WrongPasswordError, UsageError +from wormhole.timing import DebugTiming +from wormhole.util.hkdf import HKDF +from wormhole.channel_monitor import monitor CONFMSG_NONCE_LENGTH = 128//8 CONFMSG_MAC_LENGTH = 256//8 diff --git a/src/txwormhole/transit.py b/src/txwormhole/transit.py index d22f1ad..81afa41 100644 --- a/src/txwormhole/transit.py +++ b/src/txwormhole/transit.py @@ -8,9 +8,9 @@ from twisted.internet import (reactor, interfaces, defer, protocol, from twisted.internet.defer import inlineCallbacks, returnValue from twisted.protocols import policies from nacl.secret import SecretBox -from ..util.hkdf import HKDF -from ..errors import UsageError -from ..timing import DebugTiming +from wormhole.util.hkdf import HKDF +from wormhole.errors import UsageError +from wormhole.timing import DebugTiming from . import ipaddrs def debug(msg): diff --git a/src/wormhole/scripts/cmd_receive.py b/src/wormhole/scripts/cmd_receive.py index a48ade7..d016e34 100644 --- a/src/wormhole/scripts/cmd_receive.py +++ b/src/wormhole/scripts/cmd_receive.py @@ -2,8 +2,8 @@ from __future__ import print_function import io, os, sys, json, binascii, six, tempfile, zipfile from twisted.internet import reactor, defer from twisted.internet.defer import inlineCallbacks, returnValue -from ..twisted.transcribe import Wormhole, WrongPasswordError -from ..twisted.transit import TransitReceiver +from txwormhole.transcribe import Wormhole, WrongPasswordError +from txwormhole.transit import TransitReceiver from ..errors import TransferError from .progress import ProgressPrinter @@ -55,7 +55,7 @@ class TwistedReceiver: tor_manager = None if self.args.tor: _start = self.args.timing.add_event("import TorManager") - from ..twisted.tor_manager import TorManager + from txwormhole.tor_manager import TorManager self.args.timing.finish_event(_start) tor_manager = TorManager(reactor, timing=self.args.timing) # For now, block everything until Tor has started. Soon: launch diff --git a/src/wormhole/scripts/cmd_send.py b/src/wormhole/scripts/cmd_send.py index 442a591..d8e9524 100644 --- a/src/wormhole/scripts/cmd_send.py +++ b/src/wormhole/scripts/cmd_send.py @@ -5,8 +5,8 @@ from twisted.internet import reactor, defer from twisted.internet.defer import inlineCallbacks, returnValue from ..errors import TransferError from .progress import ProgressPrinter -from ..twisted.transcribe import Wormhole, WrongPasswordError -from ..twisted.transit import TransitSender +from txwormhole.transcribe import Wormhole, WrongPasswordError +from txwormhole.transit import TransitSender APPID = u"lothar.com/wormhole/text-or-file-xfer" @@ -130,7 +130,7 @@ def send_twisted(args): tor_manager = None if args.tor: - from ..twisted.tor_manager import TorManager + from txwormhole.tor_manager import TorManager tor_manager = TorManager(reactor, timing=args.timing) # For now, block everything until Tor has started. Soon: launch tor # in parallel with everything else, make sure the TorManager can diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 4503eb1..933909a 100644 --- a/src/wormhole/test/common.py +++ b/src/wormhole/test/common.py @@ -1,7 +1,7 @@ from twisted.application import service from twisted.internet import reactor, defer from twisted.python import log -from ..twisted.transit import allocate_tcp_port +from txwormhole.transit import allocate_tcp_port from wormhole_server.server import RelayServer from .. import __version__ diff --git a/src/wormhole/test/test_interop.py b/src/wormhole/test/test_interop.py index 23daa9c..f216a6e 100644 --- a/src/wormhole/test/test_interop.py +++ b/src/wormhole/test/test_interop.py @@ -2,7 +2,7 @@ from __future__ import print_function from twisted.trial import unittest from twisted.internet.defer import gatherResults from twisted.internet.threads import deferToThread -from ..twisted.transcribe import Wormhole as twisted_Wormhole +from txwormhole.transcribe import Wormhole as twisted_Wormhole from ..blocking.transcribe import Wormhole as blocking_Wormhole from .common import ServerBase diff --git a/src/wormhole/test/test_load.py b/src/wormhole/test/test_load.py index 45dccf8..d56160a 100644 --- a/src/wormhole/test/test_load.py +++ b/src/wormhole/test/test_load.py @@ -6,3 +6,5 @@ class Import(unittest.TestCase): self.assertTrue(len(wormhole.__version__)) import wormhole_server self.assertTrue(len(wormhole_server.__version__)) + import txwormhole + self.assertTrue(len(txwormhole.__version__)) diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index ff54b7e..2c07e81 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -11,7 +11,7 @@ from twisted.web.client import getPage, Agent, readBody from .. import __version__ from .common import ServerBase from wormhole_server import relay_server, transit_server -from ..twisted.eventsource_twisted import EventSource +from txwormhole.eventsource import EventSource class Reachable(ServerBase, unittest.TestCase): diff --git a/src/wormhole/test/test_transit_twisted.py b/src/wormhole/test/test_transit_twisted.py index 4e4ea81..2a4e50d 100644 --- a/src/wormhole/test/test_transit_twisted.py +++ b/src/wormhole/test/test_transit_twisted.py @@ -6,7 +6,7 @@ from twisted.internet import defer, task, endpoints, protocol, address, error from twisted.internet.defer import gatherResults, inlineCallbacks from twisted.python import log, failure from twisted.test import proto_helpers -from ..twisted import transit +from txwormhole import transit from ..errors import UsageError from nacl.secret import SecretBox from nacl.exceptions import CryptoError diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index 7ab2f1f..c8159b0 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -2,9 +2,9 @@ from __future__ import print_function import json from twisted.trial import unittest from twisted.internet.defer import gatherResults, succeed -from ..twisted.transcribe import (Wormhole, UsageError, ChannelManager, - WrongPasswordError) -from ..twisted.eventsource_twisted import EventSourceParser +from txwormhole.transcribe import (Wormhole, UsageError, ChannelManager, + WrongPasswordError) +from txwormhole.eventsource import EventSourceParser from .common import ServerBase APPID = u"appid"