def create_dest(reactor, cli_config): txi2p = _import_txi2p() if not txi2p: raise ValueError("Cannot create I2P Destination without txi2p. " "Please 'pip install tahoe-lafs[i2p]' to fix this.") tahoe_config_i2p = {} # written into tahoe.cfg:[i2p] private_dir = os.path.abspath( os.path.join(cli_config["basedir"], "private")) stdout = cli_config.stdout if cli_config["i2p-launch"]: raise NotImplementedError("--i2p-launch is under development.") else: print("connecting to I2P (to allocate .i2p address)..", file=stdout) sam_port = yield _connect_to_i2p(reactor, cli_config, txi2p) print("I2P connection established", file=stdout) tahoe_config_i2p["sam.port"] = sam_port external_port = 3457 # TODO: pick this randomly? there's no contention. privkeyfile = os.path.join(private_dir, "i2p_dest.privkey") sam_endpoint = clientFromString(reactor, sam_port) print("allocating .i2p address...", file=stdout) dest = yield txi2p.generateDestination(reactor, privkeyfile, 'SAM', sam_endpoint) print(".i2p address allocated", file=stdout) escaped_sam_port = sam_port.replace(':', '\:') i2p_port = "i2p:%s:%d:api=SAM:apiEndpoint=%s" % \ (privkeyfile, external_port, escaped_sam_port) i2p_location = "i2p:%s:%d" % (dest.host, external_port) # in addition to the "how to launch/connect-to i2p" keys above, we also # record information about the I2P service into tahoe.cfg. # * "port" is the random "public Destination port" (integer), which # (when combined with the .i2p address) should match "i2p_location" # (which will be added to tub.location) # * "private_key_file" points to the on-disk copy of the private key # material (although we always write it to the same place) tahoe_config_i2p["dest"] = "true" tahoe_config_i2p["dest.port"] = str(external_port) tahoe_config_i2p["dest.private_key_file"] = os.path.join( "private", "i2p_dest.privkey") # tahoe_config_i2p: this is a dictionary of keys/values to add to the # "[i2p]" section of tahoe.cfg, which tells the new node how to launch # I2P in the right way. # i2p_port: a server endpoint string, it will be added to tub.port= # i2p_location: a foolscap connection hint, "i2p:B32_ADDR:PORT" # We assume/require that the Node gives us the same data_directory= # at both create-node and startup time. The data directory is not # recorded in tahoe.cfg returnValue((tahoe_config_i2p, i2p_port, i2p_location))
def create_dest(reactor, cli_config): txi2p = _import_txi2p() if not txi2p: raise ValueError("Cannot create I2P Destination without txi2p. " "Please 'pip install tahoe-lafs[i2p]' to fix this.") tahoe_config_i2p = {} # written into tahoe.cfg:[i2p] private_dir = os.path.abspath(os.path.join(cli_config["basedir"], "private")) stdout = cli_config.stdout if cli_config["i2p-launch"]: raise NotImplementedError("--i2p-launch is under development.") else: print("connecting to I2P (to allocate .i2p address)..", file=stdout) sam_port = yield _connect_to_i2p(reactor, cli_config, txi2p) print("I2P connection established", file=stdout) tahoe_config_i2p["sam.port"] = sam_port external_port = 3457 # TODO: pick this randomly? there's no contention. privkeyfile = os.path.join(private_dir, "i2p_dest.privkey") sam_endpoint = clientFromString(reactor, sam_port) print("allocating .i2p address...", file=stdout) dest = yield txi2p.generateDestination(reactor, privkeyfile, 'SAM', sam_endpoint) print(".i2p address allocated", file=stdout) escaped_sam_port = sam_port.replace(':', '\:') i2p_port = "i2p:%s:%d:api=SAM:apiEndpoint=%s" % \ (privkeyfile, external_port, escaped_sam_port) i2p_location = "i2p:%s:%d" % (dest.host, external_port) # in addition to the "how to launch/connect-to i2p" keys above, we also # record information about the I2P service into tahoe.cfg. # * "port" is the random "public Destination port" (integer), which # (when combined with the .i2p address) should match "i2p_location" # (which will be added to tub.location) # * "private_key_file" points to the on-disk copy of the private key # material (although we always write it to the same place) tahoe_config_i2p["dest"] = "true" tahoe_config_i2p["dest.port"] = str(external_port) tahoe_config_i2p["dest.private_key_file"] = os.path.join("private", "i2p_dest.privkey") # tahoe_config_i2p: this is a dictionary of keys/values to add to the # "[i2p]" section of tahoe.cfg, which tells the new node how to launch # I2P in the right way. # i2p_port: a server endpoint string, it will be added to tub.port= # i2p_location: a foolscap connection hint, "i2p:B32_ADDR:PORT" # We assume/require that the Node gives us the same data_directory= # at both create-node and startup time. The data directory is not # recorded in tahoe.cfg returnValue((tahoe_config_i2p, i2p_port, i2p_location))