Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endpoint factory #241

Open
meejah opened this issue Jul 22, 2017 · 0 comments
Open

endpoint factory #241

meejah opened this issue Jul 22, 2017 · 0 comments

Comments

@meejah
Copy link
Owner

meejah commented Jul 22, 2017

Some applications want to set up endpoints (e.g. for Onion services or client connections) before doing any "async stuff". This means they can't yet have a Tor instance, because that needs to do async-stuff.

I'm considering a design like this: you create a "factory that can create endpoints" using something like connect_later or launch_later (which take the same options as connect or launch). The object returned from either of those two functions would have methods to create the various endpoints that are possible (e.g. create_onion, stream_via or similar).

You would then get out an instance implementing IStreamServerEndpoint which would first launch (or connect to) tor and then do the other thing you asked for (e.g. create a new onion service).

@implementer(IStreamServerEndpoint)
class _LaunchTorEndpoint(object):
    @inlineCallbacks
    def listen(self, factory):
         # general idea; details omitted:
         tor = yield txtorcon.launch(*self._launch_args)
         res = yield self._after_launch(tor)
         returnValue(res)

@implementer(ITorEndpointFactory)
class _LaunchEndpointFactory(object):
    def onion_service(self, *args):
        def post_launch(tor):
             return tor.create_onion_service(*args)
        return _LaunchTorEndpoint(self._launch_args, post_launch)

def launch_later(*args):
    return _LaunchEndpointFactory(args)

def connect_later(*args):
    return _ConnectEndpointFactory(args)  # or something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant