diff --git a/setup.py b/setup.py index d1c239a..f652859 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ setup(name="magic-wormhole", "wormhole.cli", "wormhole.server", "wormhole.test", - "wormhole.twisted", ], package_data={"wormhole.server": ["db-schemas/*.sql"]}, entry_points={"console_scripts": diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index 2e0447a..e7fa2ab 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -4,7 +4,7 @@ from tqdm import tqdm from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue from ..wormhole import wormhole -from ..twisted.transit import TransitReceiver +from ..transit import TransitReceiver from ..errors import TransferError APPID = u"lothar.com/wormhole/text-or-file-xfer" @@ -38,7 +38,7 @@ class TwistedReceiver: tor_manager = None if self.args.tor: with self.args.timing.add("import", which="tor_manager"): - from ..twisted.tor_manager import TorManager + from ..tor_manager import TorManager tor_manager = TorManager(self._reactor, timing=self.args.timing) # For now, block everything until Tor has started. Soon: launch # tor in parallel with everything else, make sure the TorManager diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index dba5ee0..e393a0d 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -6,7 +6,7 @@ from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks, returnValue from ..errors import TransferError from ..wormhole import wormhole -from ..twisted.transit import TransitSender +from ..transit import TransitSender APPID = u"lothar.com/wormhole/text-or-file-xfer" @@ -41,7 +41,7 @@ def send(args, reactor=reactor): tor_manager = None if args.tor: with args.timing.add("import", which="tor_manager"): - from ..twisted.tor_manager import TorManager + from ..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/twisted/ipaddrs.py b/src/wormhole/ipaddrs.py similarity index 100% rename from src/wormhole/twisted/ipaddrs.py rename to src/wormhole/ipaddrs.py diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 48c0685..b50f776 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 ..transit import allocate_tcp_port from ..server.server import RelayServer from .. import __version__ diff --git a/src/wormhole/test/test_transit_twisted.py b/src/wormhole/test/test_transit_twisted.py index 4d87816..bbc33a8 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 .. import transit from ..errors import UsageError from nacl.secret import SecretBox from nacl.exceptions import CryptoError diff --git a/src/wormhole/twisted/tor_manager.py b/src/wormhole/tor_manager.py similarity index 99% rename from src/wormhole/twisted/tor_manager.py rename to src/wormhole/tor_manager.py index 80a72c1..4e96284 100644 --- a/src/wormhole/twisted/tor_manager.py +++ b/src/wormhole/tor_manager.py @@ -4,7 +4,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue from twisted.internet.error import ConnectError import txtorcon import ipaddr -from ..timing import DebugTiming +from .timing import DebugTiming from .transit import allocate_tcp_port class TorManager: diff --git a/src/wormhole/twisted/transit.py b/src/wormhole/transit.py similarity index 99% rename from src/wormhole/twisted/transit.py rename to src/wormhole/transit.py index cbc8724..c94e919 100644 --- a/src/wormhole/twisted/transit.py +++ b/src/wormhole/transit.py @@ -1,4 +1,4 @@ -from __future__ import print_function +from __future__ import print_function, absolute_import import re, sys, time, socket, collections from binascii import hexlify, unhexlify from zope.interface import implementer @@ -9,8 +9,8 @@ from twisted.internet.defer import inlineCallbacks, returnValue from twisted.protocols import policies from nacl.secret import SecretBox from hkdf import Hkdf -from ..errors import UsageError -from ..timing import DebugTiming +from .errors import UsageError +from .timing import DebugTiming from . import ipaddrs def HKDF(skm, outlen, salt=None, CTXinfo=b""): diff --git a/src/wormhole/twisted/__init__.py b/src/wormhole/twisted/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/wormhole/twisted/eventual.py b/src/wormhole/twisted/eventual.py deleted file mode 100644 index 02fbdd5..0000000 --- a/src/wormhole/twisted/eventual.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- test-case-name: foolscap.test.test_eventual -*- - -from twisted.internet import reactor, defer -from twisted.python import log - -class _SimpleCallQueue(object): - # XXX TODO: merge epsilon.cooperator in, and make this more complete. - def __init__(self): - self._events = [] - self._flushObservers = [] - self._timer = None - - def append(self, cb, args, kwargs): - self._events.append((cb, args, kwargs)) - if not self._timer: - self._timer = reactor.callLater(0, self._turn) - - def _turn(self): - self._timer = None - # flush all the messages that are currently in the queue. If anything - # gets added to the queue while we're doing this, those events will - # be put off until the next turn. - events, self._events = self._events, [] - for cb, args, kwargs in events: - try: - cb(*args, **kwargs) - except: - log.err() - if not self._events: - observers, self._flushObservers = self._flushObservers, [] - for o in observers: - o.callback(None) - - def flush(self): - """Return a Deferred that will fire (with None) when the call queue - is completely empty.""" - if not self._events: - return defer.succeed(None) - d = defer.Deferred() - self._flushObservers.append(d) - return d - - -_theSimpleQueue = _SimpleCallQueue() - -def eventually(cb, *args, **kwargs): - """This is the eventual-send operation, used as a plan-coordination - primitive. The callable will be invoked (with args and kwargs) in a later - reactor turn. Doing 'eventually(a); eventually(b)' guarantees that a will - be called before b. - - Any exceptions that occur in the callable will be logged with log.err(). - If you really want to ignore them, be sure to provide a callable that - catches those exceptions. - - This function returns None. If you care to know when the callable was - run, be sure to provide a callable that notifies somebody. - """ - _theSimpleQueue.append(cb, args, kwargs) - - -def fireEventually(value=None): - """This returns a Deferred which will fire in a later reactor turn, after - the current call stack has been completed, and after all other deferreds - previously scheduled with callEventually(). - """ - d = defer.Deferred() - eventually(d.callback, value) - return d - -def flushEventualQueue(_ignored=None): - """This returns a Deferred which fires when the eventual-send queue is - finally empty. This is useful to wait upon as the last step of a Trial - test method. - """ - return _theSimpleQueue.flush()