# NOISY-DEBUG: print("DEBUG: EXIT!")
+def is_instance_registered(domain: str) -> bool:
+ # NOISY-DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+ # Default is not registered
+ registered = False
+
+ try:
+ cursor.execute(
+ "SELECT rowid FROM instances WHERE domain = ? LIMIT 1", [domain]
+ )
+
+ # Check condition
+ registered = cursor.fetchone() != None
+ except BaseException as e:
+ print("ERROR: failed SQL query:", blocker, blocked, reason, block_level, first_added, last_seen, e)
+ sys.exit(255)
+
+ # NOISY-DEBUG: print("DEBUG: registered='{registered}' - EXIT!")
+ return registered
+
def add_instance(domain: str, origin: str, originator: str):
# NOISY-DEBUG: print("DEBUG: domain,origin:", domain, origin, originator)
if not validators.domain(domain):
# NOISY-DEBUG: print("DEBUG: Looked up domain:", blocked)
# NOISY-DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
- fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [blocked]
- )
-
- if fba.cursor.fetchone() == None:
+ if not fba.is_instance_registered(blocked):
# NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked, blocker)
fba.add_instance(blocked, blocker, argv[0])
fba.cursor.execute(
- "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
(
blocker,
blocked,
fba.connection.commit()
except Exception as e:
- print("error:", e, blocker, software)
+ print(f"ERROR: blocker='{blocker}',software='{software}',exception='{e}'")
elif software == "mastodon":
print("INFO: blocker:", blocker)
try:
blocked = searchres[0]
fba.cursor.execute(
- "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
(
blocker,
blocked if blocked.count("*") <= 1 else blocked_hash,
else:
fba.update_last_seen(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level)
- if reason != '':
+ if reason != "":
# NOISY-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)
fba.connection.commit()
except Exception as e:
- print("error:", e, blocker, software)
+ print(f"ERROR: blocker='{blocker}',software='{software}',exception='{e}'")
elif software == "friendica" or software == "misskey" or software == "bookwyrm" or software == "takahe":
print("INFO: blocker:", blocker)
try:
blocked = searchres[0]
# NOISY-DEBUG: print("DEBUG: AFTER-blocked:", blocked)
- fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [blocked]
- )
-
- if fba.cursor.fetchone() == None:
+ if not fba.is_instance_registered(blocked):
# NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker)
fba.add_instance(blocked, blocker)
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ?",
(blocker, blocked),
)
+
if fba.cursor.fetchone() == None:
fba.block_instance(blocker, blocked, reason, block_level)
fba.connection.commit()
except Exception as e:
- print("error:", e, blocker, software)
+ print(f"ERROR: blocker='{blocker}',software='{software}',exception='{e}'")
elif software == "gotosocial":
print("INFO: blocker:", blocker)
try:
if searchres != None:
blocked = searchres[0]
- fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [blocked]
- )
-
- if fba.cursor.fetchone() == None:
- # NOISY-DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, reason)
- fba.update_block_reason(reason, blocker, blocked, block_level)
+ if not fba.is_instance_registered(blocked):
+ # NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked, blocker)
+ fba.add_instance(blocked, blocker)
fba.cursor.execute(
- "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
(
blocker,
blocked,
)
if fba.cursor.fetchone() == None:
+ # NOISY-DEBUG: print(f"DEBUG: blocker='{blocker}' is blocking '{blocked}' for unknown reason at this point")
fba.block_instance(blocker, blocked, "unknown", "reject")
blockdict.append(
for entry in blockdict:
if entry["blocked"] == blocked:
+ # NOISY-DEBUG: print(f"DEBUG: Setting block reason for blocked='{blocked}':'{peer['public_comment']}'")
entry["reason"] = peer["public_comment"]
fba.connection.commit()
except Exception as e:
- print("error:", e, blocker, software)
+ print(f"ERROR: blocker='{blocker}',software='{software}',exception='{e}'")
else:
print("WARNING: Unknown software:", blocker, software)
def fetch_instances(domain: str, origin: str, software: str):
# NOISY-DEBUG: print("DEBUG: domain,origin,software:", domain, origin, software)
- fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [domain]
- )
-
- if fba.cursor.fetchone() == None:
+ if not fba.is_instance_registered(domain):
# NOISY-DEBUG: print("DEBUG: Adding new domain:", domain, origin)
fba.add_instance(domain, origin, sys.argv[0])
# NOISY-DEBUG: print("DEBUG: Handling instance:", instance)
try:
- fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [instance]
- )
-
- if fba.cursor.fetchone() == None:
+ if not fba.is_instance_registered(instance):
# NOISY-DEBUG: print("DEBUG: Adding new instance:", instance, domain)
fba.add_instance(instance, domain, sys.argv[0])
-
- fba.connection.commit()
-
except BaseException as e:
print(f"ERROR: instance='{instance}',exception:'{e}'")
continue