Skip to content

config.socks_endpoint fails when having multiple endpoints #345

@javiermatos

Description

@javiermatos

Hi,

I have been running some simple examples for performing http requests with txtorcon and treq. Even a simple script has errors:

from twisted.internet.task import react
from twisted.internet.defer import ensureDeferred
from twisted.internet.endpoints import TCP4ClientEndpoint

import treq
import txtorcon
async def main(reactor):
    tor = await txtorcon.connect(
        reactor,
        control_endpoint=TCP4ClientEndpoint(reactor, '127.0.0.1', 9051),
        password_function=lambda: 'mypass',
    )

    state = await tor.create_state()
    circ = await state.build_circuit()
    await circ.when_built()
    print('  path: {}'.format(' -> '.join([r.ip for r in circ.path])))
    config = await tor.get_config()
    resp = await treq.get(
        'http://httpbin.org/ip',
        agent=circ.web_agent(reactor, config.socks_endpoint(reactor)),
        timeout=3,
    )
    data = await resp.text()
    print(data)
    out = await state.close_circuit(circ)


@react
def _main(reactor):
    return ensureDeferred(main(reactor))

But I get a builtins.AttributeError: 'list' object has no attribute 'startswith' error.

I have noticed that the issue is because of the config.socks_endpoint(reactor). When calling that method, I have self.SocksPort = _ListWrapper[['unix:/run/tor/socks WorldWritable', '9050']], which is a list of list. Then, when that method is calling the _endpoint_from_socksport_line things get even worst, as we are passing a list instead of a socket endpoint.

I have tor service listening on port 9050 (and 9051 for control), and also in unix socket /run/tor/socks (and /run/tor/control for control).

A super ugly and nonsense patch to fix it is just to go to _endpoint_from_socksport_line method and force the socks_config argument (which is a list) to get the second value (which is '9050'). If I try the first value (which is 'unix:/run/tor/socks WorldWritable'), I will get an error too.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions