From d8e851538edce95a64505d7138dacb843d70f4aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 2 Jun 2023 16:31:44 +0200 Subject: [PATCH] Continued: - more debug lines added - also fixed maybe bad function calls - debug messages improved --- fba.py | 15 ++++++++------- fetch_blocks.py | 34 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/fba.py b/fba.py index 0b58c53..a31bd74 100644 --- a/fba.py +++ b/fba.py @@ -444,8 +444,8 @@ def update_instance_data(domain: str): try: # DEBUG: print("DEBUG: Executing SQL:", sql_string) cursor.execute(sql_string, fields) - # DEBUG: print(f"DEBUG: Success! (rowcount={cursor.rowcount })") + # DEBUG: print(f"DEBUG: Success! (rowcount={cursor.rowcount })") if cursor.rowcount == 0: print(f"WARNING: Did not update any rows: domain='{domain}',fields()={len(fields)} - EXIT!") return @@ -1051,7 +1051,7 @@ def update_block_reason(reason: str, blocker: str, blocked: str, block_level: st # DEBUG: print("DEBUG: Updating block reason:", reason, blocker, blocked, block_level) try: cursor.execute( - "UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''", + "UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason IN ('','unknown') LIMIT 1", ( reason, time.time(), @@ -1063,7 +1063,7 @@ def update_block_reason(reason: str, blocker: str, blocked: str, block_level: st # DEBUG: print(f"DEBUG: cursor.rowcount={cursor.rowcount}") if cursor.rowcount == 0: - print("WARNING: Did not update any rows:", blocker, blocked) + # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',reason='{reason}' - EXIT!") return except BaseException as e: @@ -1076,7 +1076,7 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): # DEBUG: print("DEBUG: Updating last_seen for:", blocker, blocked, block_level) try: cursor.execute( - "UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?", + "UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1", ( time.time(), blocker, @@ -1085,12 +1085,13 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): ) ) + # DEBUG: print(f"DEBUG: cursor.rowcount={cursor.rowcount}") if cursor.rowcount == 0: - print("WARNING: Did not update any rows:", domain) + # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' - EXIT!") return except BaseException as e: - print(f"ERROR: failed SQL query: last_seen='{last_seen}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(e)}]:'{str(e)}'") + print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(e)}]:'{str(e)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -1114,7 +1115,7 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str): elif is_blacklisted(blocked): raise Exception(f"blocked='{blocked}' is blacklisted but function invoked") - print("INFO: New block:", blocker, blocked, reason, block_level) + print(f"INFO: New block: blocker='{blocker}',blocked='{blocked}', reason='{reason}', block_level='{block_level}'") try: cursor.execute( "INSERT INTO blocks (blocker, blocked, reason, block_level, first_seen, last_seen) VALUES(?, ?, ?, ?, ?, ?)", diff --git a/fetch_blocks.py b/fetch_blocks.py index 612b84f..d2649c0 100755 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -78,6 +78,7 @@ for blocker, software, origin, nodeinfo_url in rows: print("WARNING: block_level is now empty!") continue + # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...") for blocked in blocks: # DEBUG: print("DEBUG: BEFORE blocked:", blocked) blocked = fba.tidyup(blocked) @@ -133,7 +134,7 @@ for blocker, software, origin, nodeinfo_url in rows: "reason" : None }) else: - # DEBUG: print("DEBUG: Updating last_seen:", blocker, blocked, block_level) + print(f"DEBUG: Updating block last seen for blocker='{blocker}',blocked='{blocked}' ...") fba.update_last_seen(blocker, blocked, block_level) fba.connection.commit() @@ -155,6 +156,7 @@ for blocker, software, origin, nodeinfo_url in rows: print("WARNING: block_level is now empty!") continue + # DEBUG: print(f"DEBUG: Checking {len(info.items())} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...") for blocked, reason in info.items(): # DEBUG: print("DEBUG: BEFORE blocked:", blocked) blocked = fba.tidyup(blocked) @@ -239,12 +241,16 @@ for blocker, software, origin, nodeinfo_url in rows: # DEBUG: print("DEBUG: severity,domain,hash,comment:", block['severity'], block['domain'], block['digest'], block['comment']) if block['severity'] == 'suspend': + # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...") json['reject'].append(entry) elif block['severity'] == 'silence': + # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...") json['followers_only'].append(entry) elif block['severity'] == 'reject_media': + # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...") json['media_removal'].append(entry) elif block['severity'] == 'reject_reports': + # DEBUG: print(f"DEBUG: Adding entry='{entry}' with severity='{block['severity']}' ...") json['report_removal'].append(entry) else: print("WARNING: Unknown severity:", block['severity'], block['domain']) @@ -261,6 +267,7 @@ for blocker, software, origin, nodeinfo_url in rows: print("WARNING: block_level is empty, blocker:", blocker) continue + # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...") for instance in blocks: blocked, blocked_hash, reason = instance.values() # DEBUG: print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason) @@ -308,18 +315,21 @@ for blocker, software, origin, nodeinfo_url in rows: # DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker) fba.add_instance(blocked, blocker, origin, nodeinfo_url) + blocking = blocked if blocked.count("*") <= 1 else blocked_hash + # DEBUG: print(f"DEBUG: blocking='{blocking}',blocked='{blocked}',blocked_hash='{blocked_hash}'") + fba.cursor.execute( "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1", ( blocker, - blocked if blocked.count("*") <= 1 else blocked_hash, + blocking, block_level ), ) if fba.cursor.fetchone() == None: # DEBUG: print("DEBUG: Blocking:", blocker, blocked, block_level) - fba.block_instance(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, reason, block_level) + fba.block_instance(blocker, blocking, reason, block_level) if block_level == "reject": blockdict.append( @@ -328,11 +338,9 @@ for blocker, software, origin, nodeinfo_url in rows: "reason" : reason }) else: - fba.update_last_seen(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level) - - if reason != "": - # DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason) - fba.update_block_reason(reason, blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level) + # DEBUG: print(f"DEBUG: Updating block last seen and reason for blocker='{blocker}',blocking='{blocking}' ...") + fba.update_last_seen(blocker, blocking, block_level) + fba.update_block_reason(reason, blocker, blocking, block_level) fba.connection.commit() except Exception as e: @@ -360,6 +368,7 @@ for blocker, software, origin, nodeinfo_url in rows: print("WARNING: block_level is empty, blocker:", blocker) continue + # DEBUG: print(f"DEBUG: Checking {len(blocks)} entries from blocker='{blocker}',software='{software}',block_level='{block_level}' ...") for instance in blocks: blocked, reason = instance.values() # DEBUG: print("DEBUG: BEFORE blocked:", blocked) @@ -415,8 +424,8 @@ for blocker, software, origin, nodeinfo_url in rows: fba.add_instance(blocked, blocker, origin, nodeinfo_url) fba.cursor.execute( - "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? LIMIT 1", - (blocker, blocked), + "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1", + (blocker, blocked, block_level), ) if fba.cursor.fetchone() == None: @@ -429,10 +438,8 @@ for blocker, software, origin, nodeinfo_url in rows: "reason" : reason }) else: + print(f"DEBUG: Updating block last seen and reason for blocker='{blocker}',blocked='{blocked}' ...") fba.update_last_seen(blocker, blocked, block_level) - - if reason != '': - # DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason) fba.update_block_reason(reason, blocker, blocked, block_level) fba.connection.commit() @@ -507,6 +514,7 @@ for blocker, software, origin, nodeinfo_url in rows: "reason" : None }) else: + print(f"DEBUG: Updating block last seen for blocker='{blocker}',blocked='{blocked}' ...") fba.update_last_seen(blocker, blocked, "reject") if "public_comment" in peer: -- 2.39.5