Exemplo n.º 1
0
    def web_agent(self, pool=None, socks_endpoint=None):
        """
        :param socks_endpoint: If ``None`` (the default), a suitable
            SOCKS port is chosen from our config (or added). If supplied,
            should be a Deferred which fires an IStreamClientEndpoint
            (e.g. the return-value from
            :meth:`txtorcon.TorConfig.socks_endpoint`) or an immediate
            IStreamClientEndpoint You probably don't need to mess with
            this.

        :param pool: passed on to the Agent (as ``pool=``)
        """
        # local import since not all platforms have this
        from txtorcon import web

        if socks_endpoint is None:
            socks_endpoint = _create_socks_endpoint(self._reactor,
                                                    self._protocol)
        if not isinstance(socks_endpoint, Deferred):
            if not IStreamClientEndpoint.providedBy(socks_endpoint):
                raise ValueError(
                    "'socks_endpoint' should be a Deferred or an IStreamClient"
                    "Endpoint (got '{}')".format(type(socks_endpoint)))
        return web.tor_agent(
            self._reactor,
            socks_endpoint,
            pool=pool,
        )
Exemplo n.º 2
0
    def web_agent(self, pool=None, socks_endpoint=None):
        """
        :param socks_endpoint: If ``None`` (the default), a suitable
            SOCKS port is chosen from our config (or added). If supplied,
            should be a Deferred which fires an IStreamClientEndpoint
            (e.g. the return-value from
            :meth:`txtorcon.TorConfig.socks_endpoint`) or an immediate
            IStreamClientEndpoint You probably don't need to mess with
            this.

        :param pool: passed on to the Agent (as ``pool=``)
        """
        # local import since not all platforms have this
        from txtorcon import web

        if socks_endpoint is None:
            socks_endpoint = _create_socks_endpoint(self._reactor, self._protocol)
        if not isinstance(socks_endpoint, Deferred):
            if not IStreamClientEndpoint.providedBy(socks_endpoint):
                raise ValueError(
                    "'socks_endpoint' should be a Deferred or an IStreamClient"
                    "Endpoint (got '{}')".format(type(socks_endpoint))
                )
        return web.tor_agent(
            self._reactor,
            socks_endpoint,
            pool=pool,
        )
Exemplo n.º 3
0
 def _default_socks_endpoint(self):
     """
     Returns a Deferred that fires with our default SOCKS endpoint
     (which might mean setting one up in our attacked Tor if it
     doesn't have one)
     """
     if self._socks_endpoint is None:
         self._socks_endpoint = yield _create_socks_endpoint(self._reactor, self._protocol)
     returnValue(self._socks_endpoint)
Exemplo n.º 4
0
    def test_unix_socket_with_options(self):
        reactor = Mock()
        cp = Mock()
        cp.get_conf = Mock(return_value=defer.succeed(
            {'SocksPort': ['unix:/tmp/boom SomeOption']}))

        ep = yield _create_socks_endpoint(reactor, cp)

        self.assertTrue(isinstance(ep, UNIXClientEndpoint))
        self.assertEqual("/tmp/boom", ep._path)
Exemplo n.º 5
0
    def test_nothing_exists(self):
        reactor = Mock()
        cp = Mock()
        cp.get_conf = Mock(return_value=defer.succeed(dict()))

        with patch(u'txtorcon.endpoints.available_tcp_port', return_value=9999):
            ep = yield _create_socks_endpoint(reactor, cp)

        self.assertTrue(isinstance(ep, TCP4ClientEndpoint))
        # internal details, but ...
        self.assertEqual(ep._port, 9999)
Exemplo n.º 6
0
    def test_explicit_socks(self):
        reactor = Mock()
        cp = Mock()
        cp.get_conf = Mock(return_value=defer.succeed(
            {'SocksPort': ['9050', '9150', 'unix:/tmp/boom']}))

        ep = yield _create_socks_endpoint(reactor,
                                          cp,
                                          socks_config='unix:/tmp/boom')

        self.assertTrue(isinstance(ep, UNIXClientEndpoint))
Exemplo n.º 7
0
    def test_explicit_socks(self):
        reactor = Mock()
        cp = Mock()
        cp.get_conf = Mock(
            return_value=defer.succeed({
                'SocksPort': ['9050', '9150', 'unix:/tmp/boom']
            })
        )

        ep = yield _create_socks_endpoint(reactor, cp, socks_config='unix:/tmp/boom')

        self.assertTrue(isinstance(ep, UNIXClientEndpoint))
Exemplo n.º 8
0
    def test_unix_socket_with_options(self):
        reactor = Mock()
        cp = Mock()
        cp.get_conf = Mock(
            return_value=defer.succeed({
                'SocksPort': ['unix:/tmp/boom SomeOption']
            })
        )

        ep = yield _create_socks_endpoint(reactor, cp)

        self.assertTrue(isinstance(ep, UNIXClientEndpoint))
        self.assertEqual("/tmp/boom", ep._path)