From 4d8052ebac46c60299373f20a01a37cf9cf36074 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 20 Nov 2023 08:42:02 +0100 Subject: [PATCH] Continued: - handle empty peer list differently than fetching none - added alias 'mbin' for software 'kbin' --- fba/helpers/software.py | 3 +++ fba/http/federation.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fba/helpers/software.py b/fba/helpers/software.py index 7e79e75..badb887 100644 --- a/fba/helpers/software.py +++ b/fba/helpers/software.py @@ -86,6 +86,9 @@ def alias(software: str) -> str: elif software == "gitdab": logger.debug("Setting forgejo: software='%s'", software) software = "forgejo" + elif software == "mbin": + logger.debug("Setting kbin: software='%s'", software) + software = "kbin" elif "gnu social" in software: logger.debug("Setting gnusocial: software='%s'", software) software = "gnusocial" diff --git a/fba/http/federation.py b/fba/http/federation.py index 27fcad3..1aa79b1 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -107,7 +107,7 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: instances.set_total_peers(domain, peerlist) logger.debug("peerlist[]='%s'", type(peerlist)) - if peerlist is None or len(peerlist) == 0: + if peerlist is None: logger.warning("Cannot fetch peers: domain='%s',software='%s'", domain, software) if instances.has_pending(domain): @@ -120,6 +120,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: _DEPTH = _DEPTH - 1 logger.debug("EXIT!") return + elif len(peerlist) == 0: + logger.debug("domain='%s',software='%s' has an empty peer list returned - EXIT!", domain, software) + return logger.info("Checking %d instance(s) from domain='%s',software='%s',depth=%d ...", len(peerlist), domain, software, _DEPTH) for instance in peerlist: @@ -129,11 +132,11 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path: continue logger.debug("instance='%s' - BEFORE!", instance) - instance = tidyup.domain(instance) + instance = tidyup.domain(instance) if isinstance(instance, str) and instance != "" else None logger.debug("instance='%s' - AFTER!", instance) - if instance == "": - logger.warning("Empty instance after tidyup.domain(), domain='%s'", domain) + if instance is None or instance == "": + logger.warning("instance='%s' is empty after tidyup.domain(), domain='%s'", instance, domain) continue elif ".." in instance: logger.warning("instance='%s' contains double-dot, removing ...", instance) @@ -183,6 +186,8 @@ def fetch_peers(domain: str, software: str, origin: str) -> list: if not isinstance(software, str) and software is not None: raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'") + elif isinstance(software, str) and software == "": + raise ValueError("Parameter 'software' is empty") elif software_helper.is_relay(software): raise ValueError(f"domain='{domain}' is of software='{software}' and isn't supported here.") elif not isinstance(origin, str) and origin is not None: -- 2.39.5