tor_manager: pass endpoints to txtorcon.connect(), not descriptors
This was breaking any uses of --tor-control-port=: the client would always fall back to using the default SOCKS port.
This commit is contained in:
parent
be166b483c
commit
ed420e0001
|
@ -51,13 +51,17 @@ class Tor(unittest.TestCase):
|
||||||
reactor = object()
|
reactor = object()
|
||||||
my_tor = X() # object() didn't like providedBy()
|
my_tor = X() # object() didn't like providedBy()
|
||||||
tcp = "port"
|
tcp = "port"
|
||||||
|
ep = object()
|
||||||
connect_d = defer.Deferred()
|
connect_d = defer.Deferred()
|
||||||
stderr = io.StringIO()
|
stderr = io.StringIO()
|
||||||
with mock.patch("wormhole.tor_manager.txtorcon.connect",
|
with mock.patch("wormhole.tor_manager.txtorcon.connect",
|
||||||
side_effect=connect_d) as connect:
|
side_effect=connect_d) as connect:
|
||||||
|
with mock.patch("wormhole.tor_manager.clientFromString",
|
||||||
|
side_effect=[ep]) as sfs:
|
||||||
d = get_tor(reactor, tor_control_port=tcp, stderr=stderr)
|
d = get_tor(reactor, tor_control_port=tcp, stderr=stderr)
|
||||||
|
self.assertEqual(sfs.mock_calls, [mock.call(reactor, tcp)])
|
||||||
self.assertNoResult(d)
|
self.assertNoResult(d)
|
||||||
self.assertEqual(connect.mock_calls, [mock.call(reactor, tcp)])
|
self.assertEqual(connect.mock_calls, [mock.call(reactor, ep)])
|
||||||
connect_d.callback(my_tor)
|
connect_d.callback(my_tor)
|
||||||
tor = self.successResultOf(d)
|
tor = self.successResultOf(d)
|
||||||
self.assertIs(tor, my_tor)
|
self.assertIs(tor, my_tor)
|
||||||
|
@ -67,13 +71,17 @@ class Tor(unittest.TestCase):
|
||||||
def test_connect_fails(self):
|
def test_connect_fails(self):
|
||||||
reactor = object()
|
reactor = object()
|
||||||
tcp = "port"
|
tcp = "port"
|
||||||
|
ep = object()
|
||||||
connect_d = defer.Deferred()
|
connect_d = defer.Deferred()
|
||||||
stderr = io.StringIO()
|
stderr = io.StringIO()
|
||||||
with mock.patch("wormhole.tor_manager.txtorcon.connect",
|
with mock.patch("wormhole.tor_manager.txtorcon.connect",
|
||||||
side_effect=connect_d) as connect:
|
side_effect=connect_d) as connect:
|
||||||
|
with mock.patch("wormhole.tor_manager.clientFromString",
|
||||||
|
side_effect=[ep]) as sfs:
|
||||||
d = get_tor(reactor, tor_control_port=tcp, stderr=stderr)
|
d = get_tor(reactor, tor_control_port=tcp, stderr=stderr)
|
||||||
|
self.assertEqual(sfs.mock_calls, [mock.call(reactor, tcp)])
|
||||||
self.assertNoResult(d)
|
self.assertNoResult(d)
|
||||||
self.assertEqual(connect.mock_calls, [mock.call(reactor, tcp)])
|
self.assertEqual(connect.mock_calls, [mock.call(reactor, ep)])
|
||||||
|
|
||||||
connect_d.errback(ConnectError())
|
connect_d.errback(ConnectError())
|
||||||
tor = self.successResultOf(d)
|
tor = self.successResultOf(d)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import sys
|
||||||
from attr import attrs, attrib
|
from attr import attrs, attrib
|
||||||
from zope.interface.declarations import directlyProvides
|
from zope.interface.declarations import directlyProvides
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
|
from twisted.internet.endpoints import clientFromString
|
||||||
try:
|
try:
|
||||||
import txtorcon
|
import txtorcon
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -86,6 +87,9 @@ def get_tor(reactor, launch_tor=False, tor_control_port=None,
|
||||||
# If tor_control_port is None (the default), txtorcon
|
# If tor_control_port is None (the default), txtorcon
|
||||||
# will look through a list of usual places. If it is set,
|
# will look through a list of usual places. If it is set,
|
||||||
# it will look only in the place we tell it to.
|
# it will look only in the place we tell it to.
|
||||||
|
if tor_control_port is not None:
|
||||||
|
tor_control_port = clientFromString(reactor,
|
||||||
|
tor_control_port)
|
||||||
tor = yield txtorcon.connect(reactor, tor_control_port)
|
tor = yield txtorcon.connect(reactor, tor_control_port)
|
||||||
print(" using Tor via control port", file=stderr)
|
print(" using Tor via control port", file=stderr)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user