reenable TorManager

This commit is contained in:
Brian Warner 2017-03-04 13:07:31 +01:00
parent 4234e79161
commit 9ca657a7c6
5 changed files with 13 additions and 3 deletions

View File

@ -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()

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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