def create_client_from_config(config, _client_factory=None): """ Creates a new client instance (a subclass of Node). Most code should probably use `create_client` instead. :returns: Deferred yielding a _Client instance :param config: configuration instance (from read_config()) which encapsulates everything in the "node directory". :param _client_factory: for testing; the class to instantiate instead of _Client """ try: if _client_factory is None: _client_factory = _Client i2p_provider = create_i2p_provider(reactor, config) tor_provider = create_tor_provider(reactor, config) handlers = node.create_connection_handlers(reactor, config, i2p_provider, tor_provider) default_connection_handlers, foolscap_connection_handlers = handlers tub_options = node.create_tub_options(config) main_tub = node.create_main_tub( config, tub_options, default_connection_handlers, foolscap_connection_handlers, i2p_provider, tor_provider, ) control_tub = node.create_control_tub() introducer_clients = create_introducer_clients(config, main_tub) storage_broker = create_storage_farm_broker( config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients) client = _client_factory( config, main_tub, control_tub, i2p_provider, tor_provider, introducer_clients, storage_broker, ) i2p_provider.setServiceParent(client) tor_provider.setServiceParent(client) for ic in introducer_clients: ic.setServiceParent(client) storage_broker.setServiceParent(client) return defer.succeed(client) except Exception: return defer.fail()
def create_client_from_config(config, _client_factory=None): """ Creates a new client instance (a subclass of Node). Most code should probably use `create_client` instead. :returns: Deferred yielding a _Client instance :param config: configuration instance (from read_config()) which encapsulates everything in the "node directory". :param _client_factory: for testing; the class to instantiate instead of _Client """ try: if _client_factory is None: _client_factory = _Client i2p_provider = create_i2p_provider(reactor, config) tor_provider = create_tor_provider(reactor, config) handlers = node.create_connection_handlers(reactor, config, i2p_provider, tor_provider) default_connection_handlers, foolscap_connection_handlers = handlers tub_options = node.create_tub_options(config) main_tub = node.create_main_tub( config, tub_options, default_connection_handlers, foolscap_connection_handlers, i2p_provider, tor_provider, ) control_tub = node.create_control_tub() introducer_clients = create_introducer_clients(config, main_tub) storage_broker = create_storage_farm_broker( config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients ) client = _client_factory( config, main_tub, control_tub, i2p_provider, tor_provider, introducer_clients, storage_broker, ) i2p_provider.setServiceParent(client) tor_provider.setServiceParent(client) for ic in introducer_clients: ic.setServiceParent(client) storage_broker.setServiceParent(client) return defer.succeed(client) except Exception: return Failure()
def create_introducer(basedir=u"."): """ :returns: a Deferred that yields a new _IntroducerNode instance """ try: # see https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2946 from twisted.internet import reactor if not os.path.exists(basedir): create_node_dir(basedir, INTRODUCER_README) config = read_config( basedir, u"client.port", generated_files=["introducer.furl"], _valid_config=_valid_config(), ) i2p_provider = create_i2p_provider(reactor, config) tor_provider = create_tor_provider(reactor, config) default_connection_handlers, foolscap_connection_handlers = create_connection_handlers( reactor, config, i2p_provider, tor_provider) tub_options = create_tub_options(config) # we don't remember these because the Introducer doesn't make # outbound connections. i2p_provider = None tor_provider = None main_tub = create_main_tub( config, tub_options, default_connection_handlers, foolscap_connection_handlers, i2p_provider, tor_provider, ) control_tub = create_control_tub() node = _IntroducerNode( config, main_tub, control_tub, i2p_provider, tor_provider, ) return defer.succeed(node) except Exception: return Failure()
def create_introducer(basedir=u"."): """ :returns: a Deferred that yields a new _IntroducerNode instance """ try: # see https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2946 from twisted.internet import reactor if not os.path.exists(basedir): create_node_dir(basedir, INTRODUCER_README) config = read_config( basedir, u"client.port", generated_files=["introducer.furl"], _valid_config_sections=_valid_config_sections, ) i2p_provider = create_i2p_provider(reactor, config) tor_provider = create_tor_provider(reactor, config) default_connection_handlers, foolscap_connection_handlers = create_connection_handlers(reactor, config, i2p_provider, tor_provider) tub_options = create_tub_options(config) # we don't remember these because the Introducer doesn't make # outbound connections. i2p_provider = None tor_provider = None main_tub = create_main_tub( config, tub_options, default_connection_handlers, foolscap_connection_handlers, i2p_provider, tor_provider, ) control_tub = create_control_tub() node = _IntroducerNode( config, main_tub, control_tub, i2p_provider, tor_provider, ) return defer.succeed(node) except Exception: return Failure()
def create_client_from_config(config, _client_factory=None, _introducer_factory=None): """ Creates a new client instance (a subclass of Node). Most code should probably use `create_client` instead. :returns: Deferred yielding a _Client instance :param config: configuration instance (from read_config()) which encapsulates everything in the "node directory". :param _client_factory: for testing; the class to instantiate instead of _Client :param _introducer_factory: for testing; the class to instantiate instead of IntroducerClient """ if _client_factory is None: _client_factory = _Client i2p_provider = create_i2p_provider(reactor, config) tor_provider = create_tor_provider(reactor, config) handlers = node.create_connection_handlers(reactor, config, i2p_provider, tor_provider) default_connection_handlers, foolscap_connection_handlers = handlers tub_options = node.create_tub_options(config) main_tub = node.create_main_tub( config, tub_options, default_connection_handlers, foolscap_connection_handlers, i2p_provider, tor_provider, ) control_tub = node.create_control_tub() introducer_clients = create_introducer_clients(config, main_tub, _introducer_factory) storage_broker = create_storage_farm_broker(config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients) client = _client_factory( config, main_tub, control_tub, i2p_provider, tor_provider, introducer_clients, storage_broker, ) # Initialize storage separately after creating the client. This is # necessary because we need to pass a reference to the client in to the # storage plugins to allow them to initialize themselves (specifically, # they may want the anonymous IStorageServer implementation so they don't # have to duplicate all of its basic storage functionality). A better way # to do this, eventually, may be to create that implementation first and # then pass it in to both storage plugin creation and the client factory. # This avoids making a partially initialized client object escape the # client factory and removes the circular dependency between these # objects. storage_plugins = yield _StoragePlugins.from_config( client.get_anonymous_storage_server, config, ) client.init_storage(storage_plugins.announceable_storage_servers) i2p_provider.setServiceParent(client) tor_provider.setServiceParent(client) for ic in introducer_clients: ic.setServiceParent(client) storage_broker.setServiceParent(client) defer.returnValue(client)