]> git.mxchange.org Git - fba.git/blobdiff - fba/networks/misskey.py
Continued:
[fba.git] / fba / networks / misskey.py
index 045b5061c807fa4547802e26edcef8243e4b31b5..e7c7053c78b988ec0d6f8da31328d86129277433 100644 (file)
@@ -17,6 +17,7 @@
 import json
 import logging
 
+from fba.helpers import blacklist
 from fba.helpers import config
 from fba.helpers import dicts as dict_helper
 from fba.helpers import domain as domain_helper
@@ -34,6 +35,11 @@ def fetch_peers(domain: str) -> list:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
+    if blacklist.is_blacklisted(domain):
+        raise Exception(f"domain='{domain}' is blacklisted but function is invoked.")
+    elif not instances.is_registered(domain):
+        raise Exception(f"domain='{domain}' is not registered but function is invoked.")
+
     logger.debug("domain='%s' is misskey, sending API POST request ...", domain)
     peers  = list()
     offset = 0
@@ -78,7 +84,7 @@ def fetch_peers(domain: str) -> list:
             instances.set_last_error(domain, fetched)
             break
         elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
-            logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+            logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
             instances.set_last_error(domain, fetched["json"]["error"]["message"])
             break
 
@@ -128,14 +134,16 @@ def fetch_blocks(domain: str) -> list:
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
 
-    if not instances.is_registered(domain):
+    if blacklist.is_blacklisted(domain):
+        raise Exception(f"domain='{domain}' is blacklisted but function is invoked.")
+    elif 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()
 
     try:
-        logger.debug("Checking CSRF for domain='%s'", domain)
+        logger.debug("Checking CSRF for domain='%s' ...", domain)
         headers = csrf.determine(domain, dict())
     except network.exceptions as exception:
         logger.warning("Exception '%s' during checking CSRF (fetch_blocks,%s)", type(exception), __name__)
@@ -152,6 +160,7 @@ def fetch_blocks(domain: str) -> list:
     # instances page-by-page since it doesn't support sending them all at once
     logger.debug("Fetching misskey blocks from domain='%s'", domain)
     while True:
+        logger.debug("offset=%d", offset)
         try:
             logger.debug("Fetching offset=%d from domain='%s' ...", offset, domain)
             if offset == 0:
@@ -178,7 +187,7 @@ def fetch_blocks(domain: str) -> list:
                 instances.set_last_error(domain, fetched)
                 break
             elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
-                logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+                logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
                 instances.set_last_error(domain, fetched["json"]["error"]["message"])
                 break
 
@@ -196,21 +205,22 @@ def fetch_blocks(domain: str) -> list:
                 offset = offset + step
 
             count = 0
+            logger.debug("Checking %d row(s) of instances ...", len(rows))
             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"] == "":
+                elif instance["host"] in [None, ""]:
                     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"])
-
                 logger.debug("blocked[%s]='%s' - AFTER!", type(blocked), blocked)
-                if blocked is None or blocked == "":
+
+                if blocked in [None, ""]:
                     logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
                     continue
                 elif not domain_helper.is_wanted(blocked):
@@ -239,6 +249,7 @@ def fetch_blocks(domain: str) -> list:
 
     while True:
         # Fetch blocked (full suspended) instances
+        logger.debug("offset=%d", offset)
         try:
             if offset == 0:
                 logger.debug("Sending JSON API request to domain='%s',step=%d,offset=%d", domain, step, offset)
@@ -264,7 +275,7 @@ def fetch_blocks(domain: str) -> list:
                 instances.set_last_error(domain, fetched)
                 break
             elif isinstance(fetched["json"], dict) and "error" in fetched["json"] and "message" in fetched["json"]["error"]:
-                logger.warning("post_json_api() returned error: '%s'", fetched['error']['message'])
+                logger.warning("post_json_api() returned error: '%s'", fetched["json"]["error"]["message"])
                 instances.set_last_error(domain, fetched["json"]["error"]["message"])
                 break
 
@@ -282,13 +293,14 @@ def fetch_blocks(domain: str) -> list:
                 offset = offset + step
 
             count = 0
+            logger.debug("Checking %d row(s) of instances ...", len(rows))
             for instance in rows:
                 # Is it there?
                 logger.debug("instance[]='%s'", type(instance))
-                blocked = tidyup.domain(instance["host"])
+                blocked = tidyup.domain(instance["host"]) if instance["host"] != "" else None
+                logger.debug("blocked='%s' - AFTER!", blocked)
 
-                logger.debug("blocked='%s'", blocked)
-                if blocked is None or blocked == "":
+                if blocked in [None, ""]:
                     logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"])
                     continue
                 elif not domain_helper.is_wanted(blocked):