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