예제 #1
0
def create_tub(tub_options,
               default_connection_handlers,
               foolscap_connection_handlers,
               handler_overrides={},
               **kwargs):
    """
    Create a Tub with the right options and handlers. It will be
    ephemeral unless the caller provides certFile= in kwargs

    :param handler_overrides: anything in this will override anything
        in `default_connection_handlers` for just this call.

    :param dict tub_options: every key-value pair in here will be set in
        the new Tub via `Tub.setOption`
    """
    tub = Tub(**kwargs)
    for (name, value) in list(tub_options.items()):
        tub.setOption(name, value)
    handlers = default_connection_handlers.copy()
    handlers.update(handler_overrides)
    tub.removeAllConnectionHintHandlers()
    for hint_type, handler_name in list(handlers.items()):
        handler = foolscap_connection_handlers.get(handler_name)
        if handler:
            tub.addConnectionHintHandler(hint_type, handler)
    return tub
예제 #2
0
 def _create_tub(self, handler_overrides={}, **kwargs):
     # Create a Tub with the right options and handlers. It will be
     # ephemeral unless the caller provides certFile=
     tub = Tub(**kwargs)
     for (name, value) in self.tub_options.items():
         tub.setOption(name, value)
     handlers = self._default_connection_handlers.copy()
     handlers.update(handler_overrides)
     tub.removeAllConnectionHintHandlers()
     for hint_type, handler_name in handlers.items():
         handler = self._foolscap_connection_handlers.get(handler_name)
         if handler:
             tub.addConnectionHintHandler(hint_type, handler)
     return tub
예제 #3
0
 def _create_tub(self, handler_overrides={}, **kwargs):
     # Create a Tub with the right options and handlers. It will be
     # ephemeral unless the caller provides certFile=
     tub = Tub(**kwargs)
     for (name, value) in self.tub_options.items():
         tub.setOption(name, value)
     handlers = self._default_connection_handlers.copy()
     handlers.update(handler_overrides)
     tub.removeAllConnectionHintHandlers()
     for hint_type, handler_name in handlers.items():
         handler = self._foolscap_connection_handlers.get(handler_name)
         if handler:
             tub.addConnectionHintHandler(hint_type, handler)
     return tub
예제 #4
0
def create_tub(tub_options, default_connection_handlers, foolscap_connection_handlers,
               handler_overrides={}, **kwargs):
    """
    Create a Tub with the right options and handlers. It will be
    ephemeral unless the caller provides certFile= in kwargs

    :param handler_overrides: anything in this will override anything
        in `default_connection_handlers` for just this call.

    :param dict tub_options: every key-value pair in here will be set in
        the new Tub via `Tub.setOption`
    """
    tub = Tub(**kwargs)
    for (name, value) in tub_options.items():
        tub.setOption(name, value)
    handlers = default_connection_handlers.copy()
    handlers.update(handler_overrides)
    tub.removeAllConnectionHintHandlers()
    for hint_type, handler_name in handlers.items():
        handler = foolscap_connection_handlers.get(handler_name)
        if handler:
            tub.addConnectionHintHandler(hint_type, handler)
    return tub
예제 #5
0

tub = Tub()

which = sys.argv[1] if len(sys.argv) > 1 else None
if which == "tcp":
    furl = "pb://%s@tcp:%s:%d/calculator" % (TUBID, HOSTNAME, LOCALPORT)
elif which == "socks":
    # "slogin -D 8013 HOSTNAME" starts a SOCKS server on localhost 8013, for
    # which connections will emerge from the other end. Check the server logs
    # to see the peer address of each addObserver call to verify that it is
    # coming from 127.0.0.1 rather than the client host.
    from foolscap.connections import socks

    h = socks.socks_endpoint(HostnameEndpoint(reactor, "localhost", 8013))
    tub.removeAllConnectionHintHandlers()
    tub.addConnectionHintHandler("tcp", h)
    furl = "pb://%s@tcp:localhost:%d/calculator" % (TUBID, LOCALPORT)
elif which in ("tor-default", "tor-socks", "tor-control", "tor-launch"):
    from foolscap.connections import tor

    if which == "tor-default":
        h = tor.default_socks()
    elif which == "tor-socks":
        h = tor.socks_port(int(sys.argv[2]))
    elif which == "tor-control":
        control_ep = clientFromString(reactor, sys.argv[2])
        h = tor.control_endpoint(control_ep)
    elif which == "tor-launch":
        data_directory = None
        if len(sys.argv) > 2:
예제 #6
0
    furl = "pb://%s@tcp:%s:%d/calculator" % (TUBID, HOSTNAME, LOCALPORT)
elif which in ("tor-default", "tor-socks", "tor-control", "tor-launch"):
    from foolscap.connections import tor
    if which == "tor-default":
        h = tor.default_socks()
    elif which == "tor-socks":
        h = tor.socks_port(int(sys.argv[2]))
    elif which == "tor-control":
        control_ep = clientFromString(reactor, sys.argv[2])
        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)
else:
    print("run as 'check-connections-client.py [tcp|tor-default|tor-socks|tor-control|tor-launch]'")
    sys.exit(1)
print("using %s: %s" % (which, furl))

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

@inlineCallbacks
def go():
    tub.startService()
    start = time.time()