Пример #1
0
def create_introducer_clients(config, main_tub):
    """
    Read, validate and parse any 'introducers.yaml' configuration.

    :returns: a list of IntroducerClient instances
    """
    # we return this list
    introducer_clients = []

    introducers_yaml_filename = config.get_private_path("introducers.yaml")
    introducers_filepath = FilePath(introducers_yaml_filename)

    try:
        with introducers_filepath.open() as f:
            introducers_yaml = yamlutil.safe_load(f)
            if introducers_yaml is None:
                raise EnvironmentError(
                    EPERM,
                    "Can't read '{}'".format(introducers_yaml_filename),
                    introducers_yaml_filename,
                )
            introducers = introducers_yaml.get("introducers", {})
            log.msg("found {} introducers in private/introducers.yaml".format(
                len(introducers), ))
    except EnvironmentError as e:
        if e.errno != ENOENT:
            raise
        introducers = {}

    if "default" in introducers.keys():
        raise ValueError(
            "'default' introducer furl cannot be specified in introducers.yaml;"
            " please fix impossible configuration.")

    # read furl from tahoe.cfg
    tahoe_cfg_introducer_furl = config.get_config("client", "introducer.furl",
                                                  None)
    if tahoe_cfg_introducer_furl == "None":
        raise ValueError("tahoe.cfg has invalid 'introducer.furl = None':"
                         " to disable it, use 'introducer.furl ='"
                         " or omit the key entirely")
    if tahoe_cfg_introducer_furl:
        introducers[u'default'] = {'furl': tahoe_cfg_introducer_furl}

    for petname, introducer in introducers.items():
        introducer_cache_filepath = FilePath(
            config.get_private_path(
                "introducer_{}_cache.yaml".format(petname)))
        ic = IntroducerClient(
            main_tub,
            introducer['furl'].encode("ascii"),
            config.nickname,
            str(allmydata.__full_version__),
            str(_Client.OLDEST_SUPPORTED_VERSION),
            node.get_app_versions(),
            partial(_sequencer, config),
            introducer_cache_filepath,
        )
        introducer_clients.append(ic)
    return introducer_clients
Пример #2
0
    def test_application_versions(self):
        """
        Application versions should all have the same type, the native string.

        This test is due to the Foolscap limitations, if Foolscap is fixed or
        removed it can be deleted.
        """
        app_types = set(type(o) for o in get_app_versions())
        self.assertEqual(app_types, {native_str})
Пример #3
0
def create_introducer_clients(config, main_tub):
    """
    Read, validate and parse any 'introducers.yaml' configuration.

    :returns: a list of IntroducerClient instances
    """
    # we return this list
    introducer_clients = []

    introducers_yaml_filename = config.get_private_path("introducers.yaml")
    introducers_filepath = FilePath(introducers_yaml_filename)

    try:
        with introducers_filepath.open() as f:
            introducers_yaml = yamlutil.safe_load(f)
            if introducers_yaml is None:
                raise EnvironmentError(
                    EPERM,
                    "Can't read '{}'".format(introducers_yaml_filename),
                    introducers_yaml_filename,
                )
            introducers = introducers_yaml.get("introducers", {})
            log.msg(
                "found {} introducers in private/introducers.yaml".format(
                    len(introducers),
                )
            )
    except EnvironmentError as e:
        if e.errno != ENOENT:
            raise
        introducers = {}

    if "default" in introducers.keys():
        raise ValueError(
            "'default' introducer furl cannot be specified in introducers.yaml;"
            " please fix impossible configuration."
        )

    # read furl from tahoe.cfg
    tahoe_cfg_introducer_furl = config.get_config("client", "introducer.furl", None)
    if tahoe_cfg_introducer_furl == "None":
        raise ValueError(
            "tahoe.cfg has invalid 'introducer.furl = None':"
            " to disable it, use 'introducer.furl ='"
            " or omit the key entirely"
        )
    if tahoe_cfg_introducer_furl:
        introducers[u'default'] = {'furl':tahoe_cfg_introducer_furl}

    for petname, introducer in introducers.items():
        introducer_cache_filepath = FilePath(config.get_private_path("introducer_{}_cache.yaml".format(petname)))
        ic = IntroducerClient(
            main_tub,
            introducer['furl'].encode("ascii"),
            config.nickname,
            str(allmydata.__full_version__),
            str(_Client.OLDEST_SUPPORTED_VERSION),
            node.get_app_versions(),
            partial(_sequencer, config),
            introducer_cache_filepath,
        )
        introducer_clients.append(ic)
    return introducer_clients