]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 21 Jun 2023 05:45:50 +0000 (07:45 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 21 Jun 2023 05:45:50 +0000 (07:45 +0200)
- variable 'peer' can be a dict with "domain" as a key where the domain name
  is stored

fba/http/federation.py

index c61bea5188b81b6b175311147dd6a2efc299bf29..13fc60a8ebcd10b99b12d54b300b888ca55526c5 100644 (file)
@@ -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