From 143b061584527141ef99c0a0e51d20a2a9d57683 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 21 Jun 2023 07:45:50 +0200 Subject: [PATCH] Continued: - variable 'peer' can be a dict with "domain" as a key where the domain name is stored --- fba/http/federation.py | 52 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/fba/http/federation.py b/fba/http/federation.py index c61bea5..13fc60a 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -636,28 +636,38 @@ def add_peers(rows: dict) -> list: peers = list() for key in ["linked", "allowed", "blocked"]: # DEBUG: print(f"DEBUG: Checking key='{key}'") - if key in rows and rows[key] is not None: - # DEBUG: print(f"DEBUG: Adding {len(rows[key])} peer(s) to peers list ...") - for peer in rows[key]: - # DEBUG: print(f"DEBUG: peer='{peer}' - BEFORE!") - peer = tidyup.domain(peer) + if key not in rows or rows[key] is None: + print(f"WARNING: Cannot find key='{key}' or it is NoneType - SKIPPED!") + continue - # DEBUG: print(f"DEBUG: peer='{peer}' - AFTER!") - if not validators.domain(peer): - print(f"WARNING: peer='{peer}' is not a valid domain - SKIPPED!") - continue - elif peer.endswith(".arpa"): - print(f"WARNING: peer='{peer}' is a domain for reversed IP addresses -SKIPPED!") - continue - elif peer.endswith(".tld"): - print(f"WARNING: peer='{peer}' is a fake domain - SKIPPED!") - continue - elif blacklist.is_blacklisted(peer): - # DEBUG: print(f"DEBUG: peer='{peer}' is blacklisted - SKIPPED!") - continue - - # DEBUG: print(f"DEBUG: Adding peer='{peer}' ...") - peers.append(peer) + # DEBUG: print(f"DEBUG: Adding {len(rows[key])} peer(s) to peers list ...") + for peer in rows[key]: + # DEBUG: print(f"DEBUG: peer='{peer}' - BEFORE!") + if isinstance(peer, dict) and "domain" in peer: + # DEBUG: print(f"DEBUG: peer[domain]='{peer['domain']}'") + peer = tidyup.domain(peer["domain"]) + elif isinstance(peer, str): + # DEBUG: print(f"DEBUG: peer='{peer}'") + peer = tidyup.domain(peer) + else: + raise ValueError(f"peer[]='{type(peer)}' is not supported,key='{key}'") + + # DEBUG: print(f"DEBUG: peer='{peer}' - AFTER!") + if not validators.domain(peer): + print(f"WARNING: peer='{peer}' is not a valid domain - SKIPPED!") + continue + elif peer.endswith(".arpa"): + print(f"WARNING: peer='{peer}' is a domain for reversed IP addresses -SKIPPED!") + continue + elif peer.endswith(".tld"): + print(f"WARNING: peer='{peer}' is a fake domain - SKIPPED!") + continue + elif blacklist.is_blacklisted(peer): + # DEBUG: print(f"DEBUG: peer='{peer}' is blacklisted - SKIPPED!") + continue + + # DEBUG: print(f"DEBUG: Adding peer='{peer}' ...") + peers.append(peer) # DEBUG: print(f"DEBUG: peers()={len(peers)} - EXIT!") return peers -- 2.39.5