]> git.mxchange.org Git - fba.git/blobdiff - fba/networks/misskey.py
Continued:
[fba.git] / fba / networks / misskey.py
index ec35833e1599f20bd859ae31bdb1ddf0d50ddeb5..045b5061c807fa4547802e26edcef8243e4b31b5 100644 (file)
 import json
 import logging
 
-from fba import csrf
-from fba import utils
-
 from fba.helpers import config
 from fba.helpers import dicts as dict_helper
 from fba.helpers import domain as domain_helper
 from fba.helpers import tidyup
 
+from fba.http import csrf
 from fba.http import network
 
 from fba.models import instances
@@ -86,7 +84,7 @@ def fetch_peers(domain: str) -> list:
 
         rows = fetched["json"]
 
-        logger.debug("rows(%d)[]='%s'", len(rows), type(rows))
+        logger.debug("rows(%d)[]='%s',step=%d", len(rows), type(rows), step)
         if len(rows) == 0:
             logger.debug("Returned zero bytes, domain='%s' - BREAK!", domain)
             break
@@ -97,7 +95,7 @@ def fetch_peers(domain: str) -> list:
             logger.debug("Raising offset by step=%d", step)
             offset = offset + step
 
-        already = 0
+        added = 0
         logger.debug("rows(%d))[]='%s'", len(rows), type(rows))
         for row in rows:
             logger.debug("row()=%d", len(row))
@@ -107,19 +105,20 @@ def fetch_peers(domain: str) -> list:
             elif not isinstance(row["host"], str):
                 logger.warning("row[host][]='%s' is not of type 'str' - SKIPPED!", type(row['host']))
                 continue
-            elif not utils.is_domain_wanted(row["host"]):
-                logger.debug("row[host]='%s' is not wanted, domain='%s' - SKIPPED!", row['host'], domain)
-                continue
             elif row["host"] in peers:
                 logger.debug("Not adding row[host]='%s', already found - SKIPPED!", row['host'])
-                already = already + 1
+                continue
+            elif not domain_helper.is_wanted(row["host"]):
+                logger.debug("row[host]='%s' is not wanted - SKIPPED!", row["host"])
                 continue
 
             logger.debug("Adding peer: row[host]='%s'", row['host'])
+            added = added + 1
             peers.append(row["host"])
 
-        if already == len(rows):
-            logger.debug("Host returned same set of %d instance(s) - BREAK!", already)
+        logger.debug("added=%d,rows()=%d", added, len(rows))
+        if added == 0:
+            logger.debug("Host returned already added (%d) peers - BREAK!", len(rows))
             break
 
     logger.debug("peers()=%d - EXIT!", len(peers))
@@ -129,6 +128,9 @@ def fetch_blocks(domain: str) -> list:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
+    if not instances.is_registered(domain):
+        raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
     # No CSRF by default, you don't have to add network.api_headers by yourself here
     headers = tuple()
 
@@ -197,8 +199,24 @@ def fetch_blocks(domain: str) -> list:
             for instance in rows:
                 # Is it there?
                 logger.debug("instance[]='%s'", type(instance))
+                if "host" not in instance:
+                    logger.warning("instance(%d)='%s' has no key 'host' - SKIPPED!", len(instance), instance)
+                    continue
+                elif instance["host"] is None or instance["host"] == "":
+                    logger.debug("instance[host]='%s' is None or empty - SKIPPED!", instance["host"])
+                    continue
+
+                logger.debug("instance[host]='%s' - BEFORE!", instance["host"])
                 blocked = tidyup.domain(instance["host"])
-                if "isSuspended" in instance and instance["isSuspended"] and not dict_helper.has_key(blocklist, "blocked", blocked):
+
+                logger.debug("blocked[%s]='%s' - AFTER!", type(blocked), blocked)
+                if blocked is None or blocked == "":
+                    logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
+                    continue
+                elif not domain_helper.is_wanted(blocked):
+                    logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked)
+                    continue
+                elif "isSuspended" in instance and instance["isSuspended"] and not dict_helper.has_key(blocklist, "blocked", blocked):
                     count = count + 1
                     logger.debug("Appending blocker='%s',blocked='%s',block_level='suspended'", domain, blocked)
                     blocklist.append({
@@ -268,7 +286,15 @@ def fetch_blocks(domain: str) -> list:
                 # Is it there?
                 logger.debug("instance[]='%s'", type(instance))
                 blocked = tidyup.domain(instance["host"])
-                if "isBlocked" in instance and instance["isBlocked"] and not dict_helper.has_key(blocklist, "blocked", blocked):
+
+                logger.debug("blocked='%s'", blocked)
+                if blocked is None or blocked == "":
+                    logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
+                    continue
+                elif not domain_helper.is_wanted(blocked):
+                    logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked)
+                    continue
+                elif "isBlocked" in instance and instance["isBlocked"] and not dict_helper.has_key(blocklist, "blocked", blocked):
                     count = count + 1
                     logger.debug("Appending blocker='%s',blocked='%s',block_level='reject'", domain, blocked)
                     blocklist.append({