From fd42dda6d006948781bac438e260c36b41c80835 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 6 Sep 2023 04:02:26 +0200 Subject: [PATCH] Continued: - introduced software_helper.is_relay() function to check if given software name is a supported relay software - federation.fetch_instances() will throw an exception if invoked with relay software - also command fetch_instances avoids them --- fba/commands.py | 8 ++++++-- fba/helpers/software.py | 18 ++++++++++++++++++ fba/http/federation.py | 2 ++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 99a2870..b7c967e 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -318,7 +318,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: instances.set_has_obfuscation(blocker, False) # c.s isn't part of oliphant's "hidden" blocklists - if blocker == "chaos.social" or blocklists.has(blocker): + if blocker == "chaos.social" or software_helper.is_relay(software) or blocklists.has(blocker): logger.debug("Skipping blocker='%s', run ./fba.py fetch_cs or fetch_oliphant instead!", blocker) continue @@ -940,6 +940,10 @@ def fetch_instances(args: argparse.Namespace) -> int: origin = row["origin"] software = row["software"] + if software_helper.is_relay(software): + logger.warning("args.domain='%s' is of software type '%s' which is not supported by this command. Please invoke fetch_relays instead.", args.domain, software) + return 102 + # Initial fetch try: logger.info("Fetching instances from args.domain='%s',origin='%s',software='%s' ...", domain, origin, software) @@ -1560,7 +1564,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: # c.s isn't part of oliphant's "hidden" blocklists logger.debug("row[domain]='%s'", row["domain"]) - if row["domain"] != "chaos.social" and not blocklists.has(row["domain"]): + if row["domain"] != "chaos.social" and not software_helper.is_relay(software) and not blocklists.has(row["domain"]): logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", row["domain"], len(blocking)) instances.set_last_blocked(row["domain"]) instances.set_total_blocks(row["domain"], blocking) diff --git a/fba/helpers/software.py b/fba/helpers/software.py index 6464e03..1399c22 100644 --- a/fba/helpers/software.py +++ b/fba/helpers/software.py @@ -21,6 +21,14 @@ from fba.helpers import tidyup logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) +# A list of relay software +relays = [ + "activityrelay", + "aoderelay", + "selective-relay", + "pub-relay" +] + def alias(software: str) -> str: logger.debug("software='%s'- CALLED!", software) @@ -184,3 +192,13 @@ def strip_until(software: str, until: str) -> str: logger.debug("software='%s' - EXIT!", software) return software + +def is_relay(software: str) -> bool: + logger.debug("software='%s'- CALLED!", software) + + if not isinstance(software, str) and software is not None: + raise ValueError(f"software[]='{type(software)}' is not type 'str'") + + found = software in relays + logger.debug("found='%s' - EXIT!", found) + return found diff --git a/fba/http/federation.py b/fba/http/federation.py index e913af2..49f5c52 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -178,6 +178,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 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: raise ValueError(f"Parameter origin[]='{type(origin)}' is not of type 'str'") elif isinstance(origin, str) and origin == "": -- 2.39.5