Closed lukaslueg closed 11 years ago
One thing to bear in bind is APAF and OONI are using this method, AFAIK, so we should keep backwards compatibility ideally for their use-cases (the above looks fine for that).
Also instead of isinstance() it's probably more consistent with Twisted to check if the object implements the correct interface, like "if zope.interface.implements(connection, IStreamClientEndpoint): IStreamClientEndpoint(connection).connect(TorProtocolFactory())". I just made that syntax up for the idea :)
...but yes, I like this! Will make the examples more concise.
I've created a new branch buildtorconnection that changes build_tor_connection() and adds a build_local_tor_connection(). I've changed examples/attach_stream_by_country to use the new function (most of the changes in the example are again pep8 and one bug :-)).
The documentation in torstate was not changed yet.
Should the APAF- and OONI-people have a brief look on that? All the unittests continue to work unchanged and as long as build_tor_connection is not used with keyword-arguments, they are fine.
Yes, it's actually checking IStreamClientEndpoint.providedBy() which should be fine.
Also notice that build_local_tor_connection() can be supplied with a password-argument and such which pass through **kwargs.
Should built_tor_connection and build_local_tor_connection return a reference to the endpoint that might have been created?
endpoint, d = build_local_tor_connection()
# and
_, d = build_tor_connection(endpoint)
endpoint, d = build_tor_connection(('localhost', 9051))
I'd say probably not; any code that wants this can get it from "protocol.transport.addr" (or state.protocol.transport.addr)
closed?
Thanks for the patch, and closing these.
It was discussed to give torstate.build_tor_connection() some refactoring in order to prevent crufty code in clients.
Consider build_tor_connection() accepting various objects as first parameter:
Also consider a new function torstate.build_local_tor_connection() which will try to connect via socket first and by tcp if the control socket is not there.
The argument 'endpoint' in build_tor_connection() is changed to 'connection' to reflect the change.
Any comments?