Beispiel #1
0
    def _make_i2p_handler(self):
        enabled = self.get_config("i2p", "enabled", True, boolean=True)
        if not enabled:
            return None
        i2p = _import_i2p()
        if not i2p:
            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)
Beispiel #2
0
 def test_sam_endpoint(self):
     with mock.patch("foolscap.connections.i2p.SAMI2PStreamClientEndpoint") as sep:
         sep.new = n = mock.Mock()
         n.return_value = expected_ep = object()
         my_ep = endpoints.HostnameEndpoint(reactor, "localhost", 1234)
         h = i2p.sam_endpoint(my_ep)
         res = yield h.hint_to_endpoint("i2p:fppym.b32.i2p", reactor)
     self.assertEqual(len(n.mock_calls), 1)
     args = n.mock_calls[0][1]
     got_sep, got_host, got_portnum = args
     self.assertIdentical(got_sep, my_ep)
     self.failUnlessEqual(got_host, "fppym.b32.i2p")
     self.failUnlessEqual(got_portnum, None)
     ep, host = res
     self.assertIdentical(ep, expected_ep)
     self.assertEqual(host, "fppym.b32.i2p")
Beispiel #3
0
 def test_sam_endpoint(self):
     with mock.patch(
             "foolscap.connections.i2p.SAMI2PStreamClientEndpoint") as sep:
         sep.new = n = mock.Mock()
         n.return_value = expected_ep = object()
         my_ep = FakeHostnameEndpoint(reactor, "localhost", 1234)
         h = i2p.sam_endpoint(my_ep, misc_kwarg="foo")
         res = yield h.hint_to_endpoint("i2p:fppym.b32.i2p", reactor,
                                        discard_status)
     self.assertEqual(len(n.mock_calls), 1)
     args = n.mock_calls[0][1]
     got_sep, got_host, got_portnum = args
     self.assertIdentical(got_sep, my_ep)
     self.failUnlessEqual(got_host, "fppym.b32.i2p")
     self.failUnlessEqual(got_portnum, None)
     kwargs = n.mock_calls[0][2]
     self.failUnlessEqual(kwargs, {"misc_kwarg": "foo"})
     ep, host = res
     self.assertIdentical(ep, expected_ep)
     self.assertEqual(host, "fppym.b32.i2p")
    elif which == "tor-launch":
        data_directory = None
        if len(sys.argv) > 2:
            data_directory = os.path.abspath(sys.argv[2])
        h = tor.launch(data_directory)
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("tor", h)
    furl = "pb://%s@tor:%s:%d/calculator" % (TUBID, ONION, ONIONPORT)
elif which in ("i2p-default", "i2p-sam"):
    from foolscap.connections import i2p

    if which == "i2p-default":
        h = i2p.default(reactor)
    else:
        sam_ep = clientFromString(reactor, sys.argv[2])
        h = i2p.sam_endpoint(sam_ep)
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("i2p", h)
    furl = "pb://%s@i2p:%s:%d/calculator" % (TUBID, I2P, I2PPORT)
else:
    print "run as 'check-connections-client.py [tcp|socks|tor-default|tor-socks|tor-control|tor-launch|i2p-default|i2p-sam]'"
    sys.exit(1)
print "using %s: %s" % (which, furl)


class Observer(Referenceable):
    def remote_event(self, msg):
        pass


@inlineCallbacks
        h = tor.control_endpoint(control_ep)
    elif which == "tor-launch":
        data_directory = None
        if len(sys.argv) > 2:
            data_directory = os.path.abspath(sys.argv[2])
        h = tor.launch(data_directory)
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("tor", h)
    furl = "pb://%s@tor:%s:%d/calculator" % (TUBID, ONION, ONIONPORT)
elif which in ("i2p-default", "i2p-sam"):
    from foolscap.connections import i2p
    if which == "i2p-default":
        h = i2p.default(reactor)
    else:
        sam_ep = clientFromString(reactor, sys.argv[2])
        h = i2p.sam_endpoint(sam_ep)
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("i2p", h)
    furl = "pb://%s@i2p:%s:%d/calculator" % (TUBID, I2P, I2PPORT)
else:
    print "run as 'check-connections-client.py [tcp|socks|tor-default|tor-socks|tor-control|tor-launch|i2p-default|i2p-sam]'"
    sys.exit(1)
print "using %s: %s" % (which, furl)


class Observer(Referenceable):
    def remote_event(self, msg):
        pass


@inlineCallbacks