mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-10 22:43:52 +00:00
implement+test I2P setup
Note that many of the Foolscap handler-creation functions are still stubbed out, so Tahoe won't be able to honor the full range of config syntax until foolscap support is complete.
This commit is contained in:
parent
15e5ca0e99
commit
bc079a71eb
@ -215,8 +215,33 @@ class Node(service.MultiService):
|
||||
return tor.default_socks()
|
||||
|
||||
def _make_i2p_handler(self):
|
||||
# TODO: parse [i2p] config, build handler to match
|
||||
return None
|
||||
enabled = self.get_config("i2p", "enable", True, boolean=True)
|
||||
if not enabled:
|
||||
return None
|
||||
try:
|
||||
from foolscap.connections import i2p
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
samport = self.get_config("i2p", "sam.port", None)
|
||||
launch = self.get_config("i2p", "launch", False, boolean=True)
|
||||
configdir = self.get_config("i2p", "i2p.configdir", None)
|
||||
|
||||
if samport:
|
||||
if launch:
|
||||
raise ValueError("tahoe.cfg [i2p] must not set both "
|
||||
"sam.port and launch")
|
||||
ep = endpoints.clientFromString(reactor, samport)
|
||||
return i2p.sam_endpoint(ep)
|
||||
|
||||
if launch:
|
||||
executable = self.get_config("i2p", "i2p.executable", None)
|
||||
return i2p.launch(i2p_configdir=configdir, i2p_binary=executable)
|
||||
|
||||
if configdir:
|
||||
return i2p.local_i2p(configdir)
|
||||
|
||||
return i2p.default(reactor)
|
||||
|
||||
def init_connections(self):
|
||||
# We store handlers for everything. None means we were unable to
|
||||
|
@ -103,6 +103,92 @@ class Tor(unittest.TestCase):
|
||||
self.assertIsInstance(ep, endpoints.TCP4ClientEndpoint)
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
class I2P(unittest.TestCase):
|
||||
def test_disabled(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nenable = false\n")
|
||||
h = n._make_i2p_handler()
|
||||
self.assertEqual(h, None)
|
||||
|
||||
def test_default(self):
|
||||
n = FakeNode(BASECONFIG)
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.default",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
self.assertEqual(f.mock_calls, [mock.call(reactor)])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_samport(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nsam.port = tcp:localhost:1234\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.sam_endpoint",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
self.assertEqual(len(f.mock_calls), 1)
|
||||
ep = f.mock_calls[0][1][0]
|
||||
self.assertIsInstance(ep, endpoints.TCP4ClientEndpoint)
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_samport_and_launch(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\n" +
|
||||
"sam.port = tcp:localhost:1234\n"
|
||||
+"launch = true\n")
|
||||
e = self.assertRaises(ValueError, n._make_i2p_handler)
|
||||
self.assertIn("must not set both sam.port and launch", str(e))
|
||||
|
||||
def test_launch(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nlaunch = true\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.launch",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
exp = mock.call(i2p_configdir=None, i2p_binary=None)
|
||||
self.assertEqual(f.mock_calls, [exp])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_launch_executable(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nlaunch = true\n" +
|
||||
"i2p.executable = i2p\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.launch",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
exp = mock.call(i2p_configdir=None, i2p_binary="i2p")
|
||||
self.assertEqual(f.mock_calls, [exp])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_launch_configdir(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nlaunch = true\n" +
|
||||
"i2p.configdir = cfg\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.launch",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
exp = mock.call(i2p_configdir="cfg", i2p_binary=None)
|
||||
self.assertEqual(f.mock_calls, [exp])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_launch_configdir_and_executable(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\nlaunch = true\n" +
|
||||
"i2p.executable = i2p\n" +
|
||||
"i2p.configdir = cfg\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.launch",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
exp = mock.call(i2p_configdir="cfg", i2p_binary="i2p")
|
||||
self.assertEqual(f.mock_calls, [exp])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_configdir(self):
|
||||
n = FakeNode(BASECONFIG+"[i2p]\ni2p.configdir = cfg\n")
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.i2p.local_i2p",
|
||||
return_value=h1) as f:
|
||||
h = n._make_i2p_handler()
|
||||
self.assertEqual(f.mock_calls, [mock.call("cfg")])
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
class Connections(unittest.TestCase):
|
||||
def test_default(self):
|
||||
n = FakeNode(BASECONFIG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user