Merge branch 'remove-wormhole.twisted'
This commit is contained in:
		
						commit
						2c7e1529dd
					
				
							
								
								
									
										1
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								setup.py
									
									
									
									
									
								
							| 
						 | 
					@ -17,7 +17,6 @@ setup(name="magic-wormhole",
 | 
				
			||||||
                "wormhole.cli",
 | 
					                "wormhole.cli",
 | 
				
			||||||
                "wormhole.server",
 | 
					                "wormhole.server",
 | 
				
			||||||
                "wormhole.test",
 | 
					                "wormhole.test",
 | 
				
			||||||
                "wormhole.twisted",
 | 
					 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
      package_data={"wormhole.server": ["db-schemas/*.sql"]},
 | 
					      package_data={"wormhole.server": ["db-schemas/*.sql"]},
 | 
				
			||||||
      entry_points={"console_scripts":
 | 
					      entry_points={"console_scripts":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ from tqdm import tqdm
 | 
				
			||||||
from twisted.internet import reactor
 | 
					from twisted.internet import reactor
 | 
				
			||||||
from twisted.internet.defer import inlineCallbacks, returnValue
 | 
					from twisted.internet.defer import inlineCallbacks, returnValue
 | 
				
			||||||
from ..wormhole import wormhole
 | 
					from ..wormhole import wormhole
 | 
				
			||||||
from ..twisted.transit import TransitReceiver
 | 
					from ..transit import TransitReceiver
 | 
				
			||||||
from ..errors import TransferError
 | 
					from ..errors import TransferError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
APPID = u"lothar.com/wormhole/text-or-file-xfer"
 | 
					APPID = u"lothar.com/wormhole/text-or-file-xfer"
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ class TwistedReceiver:
 | 
				
			||||||
        tor_manager = None
 | 
					        tor_manager = None
 | 
				
			||||||
        if self.args.tor:
 | 
					        if self.args.tor:
 | 
				
			||||||
            with self.args.timing.add("import", which="tor_manager"):
 | 
					            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)
 | 
					            tor_manager = TorManager(self._reactor, timing=self.args.timing)
 | 
				
			||||||
            # For now, block everything until Tor has started. Soon: launch
 | 
					            # For now, block everything until Tor has started. Soon: launch
 | 
				
			||||||
            # tor in parallel with everything else, make sure the TorManager
 | 
					            # tor in parallel with everything else, make sure the TorManager
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ from twisted.internet import reactor
 | 
				
			||||||
from twisted.internet.defer import inlineCallbacks, returnValue
 | 
					from twisted.internet.defer import inlineCallbacks, returnValue
 | 
				
			||||||
from ..errors import TransferError
 | 
					from ..errors import TransferError
 | 
				
			||||||
from ..wormhole import wormhole
 | 
					from ..wormhole import wormhole
 | 
				
			||||||
from ..twisted.transit import TransitSender
 | 
					from ..transit import TransitSender
 | 
				
			||||||
 | 
					
 | 
				
			||||||
APPID = u"lothar.com/wormhole/text-or-file-xfer"
 | 
					APPID = u"lothar.com/wormhole/text-or-file-xfer"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ def send(args, reactor=reactor):
 | 
				
			||||||
    tor_manager = None
 | 
					    tor_manager = None
 | 
				
			||||||
    if args.tor:
 | 
					    if args.tor:
 | 
				
			||||||
        with args.timing.add("import", which="tor_manager"):
 | 
					        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)
 | 
					        tor_manager = TorManager(reactor, timing=args.timing)
 | 
				
			||||||
        # For now, block everything until Tor has started. Soon: launch tor
 | 
					        # For now, block everything until Tor has started. Soon: launch tor
 | 
				
			||||||
        # in parallel with everything else, make sure the TorManager can
 | 
					        # in parallel with everything else, make sure the TorManager can
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
from twisted.application import service
 | 
					from twisted.application import service
 | 
				
			||||||
from twisted.internet import reactor, defer
 | 
					from twisted.internet import reactor, defer
 | 
				
			||||||
from twisted.python import log
 | 
					from twisted.python import log
 | 
				
			||||||
from ..twisted.transit import allocate_tcp_port
 | 
					from ..transit import allocate_tcp_port
 | 
				
			||||||
from ..server.server import RelayServer
 | 
					from ..server.server import RelayServer
 | 
				
			||||||
from .. import __version__
 | 
					from .. import __version__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ from twisted.internet import defer, task, endpoints, protocol, address, error
 | 
				
			||||||
from twisted.internet.defer import gatherResults, inlineCallbacks
 | 
					from twisted.internet.defer import gatherResults, inlineCallbacks
 | 
				
			||||||
from twisted.python import log, failure
 | 
					from twisted.python import log, failure
 | 
				
			||||||
from twisted.test import proto_helpers
 | 
					from twisted.test import proto_helpers
 | 
				
			||||||
from ..twisted import transit
 | 
					from .. import transit
 | 
				
			||||||
from ..errors import UsageError
 | 
					from ..errors import UsageError
 | 
				
			||||||
from nacl.secret import SecretBox
 | 
					from nacl.secret import SecretBox
 | 
				
			||||||
from nacl.exceptions import CryptoError
 | 
					from nacl.exceptions import CryptoError
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue
 | 
				
			||||||
from twisted.internet.error import ConnectError
 | 
					from twisted.internet.error import ConnectError
 | 
				
			||||||
import txtorcon
 | 
					import txtorcon
 | 
				
			||||||
import ipaddr
 | 
					import ipaddr
 | 
				
			||||||
from ..timing import DebugTiming
 | 
					from .timing import DebugTiming
 | 
				
			||||||
from .transit import allocate_tcp_port
 | 
					from .transit import allocate_tcp_port
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TorManager:
 | 
					class TorManager:
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
from __future__ import print_function
 | 
					from __future__ import print_function, absolute_import
 | 
				
			||||||
import re, sys, time, socket, collections
 | 
					import re, sys, time, socket, collections
 | 
				
			||||||
from binascii import hexlify, unhexlify
 | 
					from binascii import hexlify, unhexlify
 | 
				
			||||||
from zope.interface import implementer
 | 
					from zope.interface import implementer
 | 
				
			||||||
| 
						 | 
					@ -9,8 +9,8 @@ from twisted.internet.defer import inlineCallbacks, returnValue
 | 
				
			||||||
from twisted.protocols import policies
 | 
					from twisted.protocols import policies
 | 
				
			||||||
from nacl.secret import SecretBox
 | 
					from nacl.secret import SecretBox
 | 
				
			||||||
from hkdf import Hkdf
 | 
					from hkdf import Hkdf
 | 
				
			||||||
from ..errors import UsageError
 | 
					from .errors import UsageError
 | 
				
			||||||
from ..timing import DebugTiming
 | 
					from .timing import DebugTiming
 | 
				
			||||||
from . import ipaddrs
 | 
					from . import ipaddrs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def HKDF(skm, outlen, salt=None, CTXinfo=b""):
 | 
					def HKDF(skm, outlen, salt=None, CTXinfo=b""):
 | 
				
			||||||
| 
						 | 
					@ -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()
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user