"detection_mode": {},
# Found nodeinfo URL
"nodeinfo_url": {},
- # Where to fetch peers (other instances)
- "get_peers_url": {},
}
language_mapping = {
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: EXIT!")
+def has_pending_nodeinfos(domain: str) -> bool:
+ # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+ has_pending = False
+ for key in nodeinfos:
+ # DEBUG: print(f"DEBUG: key='{key}',domain='{domain}',nodeinfos[key]='{nodeinfos[key]}'")
+ if domain in nodeinfos[key]:
+ has_pending = True
+ break
+
+ # DEBUG: print(f"DEBUG: has_pending='{has_pending}' - EXIT!")
+ return has_pending
+
def update_nodeinfos(domain: str):
# DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
sql_string = ''
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',sql='{sql}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',sql='{sql}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain)
# DEBUG: print("DEBUG: EXIT!")
+def log_error(domain: str, res: any):
+ # DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
+ try:
+ # DEBUG: print("DEBUG: BEFORE res[]:", type(res))
+ if isinstance(res, BaseException) or isinstance(res, json.JSONDecodeError):
+ res = str(res)
+
+ # DEBUG: print("DEBUG: AFTER res[]:", type(res))
+ if type(res) is str:
+ cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, 999, ?, ?)",[
+ domain,
+ res,
+ time.time()
+ ])
+ else:
+ cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, ?, ?, ?)",[
+ domain,
+ res.status_code,
+ res.reason,
+ time.time()
+ ])
+
+ # Cleanup old entries
+ # DEBUG: print(f"DEBUG: Purging old records (distance: {config['error_log_cleanup'])")
+ cursor.execute("DELETE FROM error_log WHERE created < ?", [time.time() - config["error_log_cleanup"]])
+ except BaseException as e:
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
+ sys.exit(255)
+
+ # DEBUG: print("DEBUG: EXIT!")
+
def update_last_error(domain: str, res: any):
# DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
try:
# DEBUG: print("DEBUG: Did not update any rows:", domain)
pending_errors[domain] = res
+ log_error(domain, res)
+
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: EXIT!")
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
connection.commit()
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
connection.commit()
# DEBUG: print("DEBUG: EXIT!")
def get_peers(domain: str, software: str) -> list:
- # DEBUG: print("DEBUG: Getting peers for domain:", domain, software)
+ # DEBUG: print(f"DEBUG: domain='{domain}',software='{software}' - CALLED!")
peers = list()
if software == "misskey":
# DEBUG: print(f"DEBUG: domain='{domain}' is misskey, sending API POST request ...")
-
offset = 0
step = config["misskey_offset"]
+
# iterating through all "suspended" (follow-only in its terminology)
# instances page-by-page, since that troonware doesn't support
# sending them all at once
print(f"WARNING: post_json_api() returned error: {fetched['error']['message']}")
update_last_error(domain, fetched["error"]["message"])
break
+
for row in fetched:
# DEBUG: print(f"DEBUG: row():{len(row)}")
if not "host" in row:
# DEBUG: print(f"DEBUG: Adding peer: '{row['host']}'")
peers.append(row["host"])
+ #print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
update_last_instance_fetch(domain)
# DEBUG: print("DEBUG: Returning peers[]:", type(peers))
update_last_error(domain, res)
except BaseException as e:
- print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'")
+ print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
+ #print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
update_last_instance_fetch(domain)
# DEBUG: print("DEBUG: Returning peers[]:", type(peers))
start = start + 100
except BaseException as e:
- print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'")
+ print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
- update_last_instance_fetch(domain)
+ #print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
+ update_last_instance_fetch(domain)
- # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
- return peers
+ # DEBUG: print("DEBUG: Returning peers[]:", type(peers))
+ return peers
# DEBUG: print(f"DEBUG: Fetching get_peers_url='{get_peers_url}' from '{domain}' ...")
try:
else:
# DEBUG: print("DEBUG: Querying API was successful:", domain, len(data))
peers = data
- nodeinfos["get_peers_url"][domain] = get_peers_url
except BaseException as e:
print("WARNING: Some error during get():", domain, e)
update_last_error(domain, e)
+ #print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
update_last_instance_fetch(domain)
# DEBUG: print("DEBUG: Returning peers[]:", type(peers))
if not res.ok or res.status_code >= 400:
print(f"WARNING: Cannot query JSON API: domain='{domain}',path='{path}',parameter()={len(parameter)},res.status_code='{res.status_code}',data[]='{type(data)}'")
update_last_error(domain, res)
- else:
- update_last_nodeinfo(domain)
except BaseException as e:
print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(e)}]:'{str(e)}'")
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: reason='{reason}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',sql='{sql}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: reason='{reason}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',sql='{sql}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: EXIT!")
print("WARNING: Did not update any rows:", domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: last_seen='{last_seen}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: last_seen='{last_seen}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: EXIT!")
)
except BaseException as e:
- print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',first_seen='{first_seen}',last_seen='{last_seen}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',first_seen='{first_seen}',last_seen='{last_seen}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
# DEBUG: print("DEBUG: EXIT!")
def is_instance_registered(domain: str) -> bool:
# DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
if not is_cache_initialized("is_registered"):
- print(f"DEBUG: Cache for {__name__} not initialized, fetching all rows ...")
+ # DEBUG: print(f"DEBUG: Cache for 'is_registered' not initialized, fetching all rows ...")
try:
cursor.execute("SELECT domain FROM instances")
set_cache_key("is_registered", domain, True)
- for key in nodeinfos:
- # DEBUG: print(f"DEBUG: key='{key}',domain='{domain}',nodeinfos[key]={nodeinfos[key]}")
- if domain in nodeinfos[key]:
- # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
- update_nodeinfos(domain)
- remove_pending_error(domain)
- break
+ if has_pending_nodeinfos(domain):
+ # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
+ update_nodeinfos(domain)
+ remove_pending_error(domain)
if domain in pending_errors:
# DEBUG: print("DEBUG: domain has pending error being updated:", domain)
remove_pending_error(domain)
except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'")
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
sys.exit(255)
else:
# DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
offset = 0
break
+ #print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
+ update_last_instance_fetch(domain)
+
# DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))
return {
"reject" : blocks["blocked"],