diff --git a/src/wormhole/_boss.py b/src/wormhole/_boss.py index 4cb1e36..aefd2d0 100644 --- a/src/wormhole/_boss.py +++ b/src/wormhole/_boss.py @@ -30,6 +30,7 @@ class Boss(object): _welcome_handler = attrib() # TODO: validator: callable _reactor = attrib() _journal = attrib(validator=provides(_interfaces.IJournal)) + _tor_manager = attrib() # TODO: ITorManager or None _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() @m.setTrace() @@ -44,7 +45,7 @@ class Boss(object): self._R = Receive(self._side, self._timing) self._RC = RendezvousConnector(self._url, self._appid, self._side, self._reactor, self._journal, - self._timing) + self._tor_manager, self._timing) self._L = Lister() self._C = Code(self._timing) self._T = Terminator() diff --git a/src/wormhole/_interfaces.py b/src/wormhole/_interfaces.py index e9df8c5..565924c 100644 --- a/src/wormhole/_interfaces.py +++ b/src/wormhole/_interfaces.py @@ -27,6 +27,8 @@ class ITerminator(Interface): class ITiming(Interface): pass +class ITorManager(Interface): + pass class IJournal(Interface): # TODO: this needs to be public pass diff --git a/src/wormhole/_rendezvous.py b/src/wormhole/_rendezvous.py index 1789333..7566a66 100644 --- a/src/wormhole/_rendezvous.py +++ b/src/wormhole/_rendezvous.py @@ -69,6 +69,7 @@ class RendezvousConnector(object): _side = attrib(validator=instance_of(type(u""))) _reactor = attrib() _journal = attrib(validator=provides(_interfaces.IJournal)) + _tor_manager = attrib() # TODO: ITorManager or None _timing = attrib(validator=provides(_interfaces.ITiming)) def __attrs_post_init__(self): @@ -88,7 +89,8 @@ class RendezvousConnector(object): self._trace(old_state="", input=what, new_state="") def _make_endpoint(self, hostname, port): - # TODO: Tor goes here + if self._tor_manager: + return self._tor_manager.get_endpoint_for(hostname, port) return endpoints.HostnameEndpoint(self._reactor, hostname, port) def wire(self, boss, nameplate, mailbox, code, lister, terminator): diff --git a/src/wormhole/tor_manager.py b/src/wormhole/tor_manager.py index 85834bc..b74b207 100644 --- a/src/wormhole/tor_manager.py +++ b/src/wormhole/tor_manager.py @@ -1,6 +1,7 @@ from __future__ import print_function, unicode_literals import sys, re import six +from zope.interface import implementer from twisted.internet.defer import inlineCallbacks, returnValue from twisted.internet.error import ConnectError from twisted.internet.endpoints import clientFromString @@ -14,9 +15,12 @@ except ImportError: TorClientEndpoint = None DEFAULT_VALUE = "DEFAULT_VALUE" import ipaddress +from . import _interfaces from .timing import DebugTiming from .transit import allocate_tcp_port + +@implementer(_interfaces.ITorManager) class TorManager: def __init__(self, reactor, launch_tor=False, tor_control_port=None, timing=None, stderr=sys.stderr): diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 7dec829..887cf4e 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -276,7 +276,8 @@ def create(appid, relay_url, reactor, delegate=None, journal=None, w = _DelegatedWormhole(delegate) else: w = _DeferredWormhole() - b = Boss(w, side, relay_url, appid, welcome_handler, reactor, journal, timing) + b = Boss(w, side, relay_url, appid, welcome_handler, reactor, journal, + tor_manager, timing) w._set_boss(b) b.start() return w