data = res.json()
except BaseException as e:
- print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception:'{str(e)}'")
+ print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(e)}]:'{str(e)}'")
# DEBUG: print("DEBUG: Returning data():", len(data))
return data
-def fetch_nodeinfo(domain: str) -> list:
- # DEBUG: print("DEBUG: Fetching nodeinfo from domain:", domain)
+def fetch_nodeinfo(domain: str, path: str = None) -> list:
+ # DEBUG: print("DEBUG: Fetching nodeinfo from domain,path:", domain, path)
nodeinfo = fetch_wellknown_nodeinfo(domain)
# DEBUG: print("DEBUG: nodeinfo:", len(nodeinfo))
data = {}
for request in requests:
+ if path != None and path != "" and request != path:
+ print(f"DEBUG: path='{path}' does not match request='{request}' - SKIPPED!")
+ continue
+
try:
# DEBUG: print("DEBUG: Fetching request:", request)
res = reqto.get(request, headers=api_headers, timeout=(config["connection_timeout"], config["read_timeout"]))
# DEBUG: print(f"DEBUG: software='{software}' - EXIT!")
return software
-def determine_software(domain: str) -> str:
- # DEBUG: print("DEBUG: Determining software for domain:", domain)
+def determine_software(domain: str, path: str = None) -> str:
+ # DEBUG: print("DEBUG: Determining software for domain,path:", domain, path)
software = None
# DEBUG: print(f"DEBUG: Fetching nodeinfo from '{domain}' ...")
- data = fetch_nodeinfo(domain)
+ data = fetch_nodeinfo(domain, path)
# DEBUG: print("DEBUG: data[]:", type(data))
if not isinstance(data, dict) or len(data) == 0:
# DEBUG: print(f"DEBUG: registered='{registered}' - EXIT!")
return registered
-def add_instance(domain: str, origin: str, originator: str):
- # DEBUG: print("DEBUG: domain,origin:", domain, origin, originator)
+def add_instance(domain: str, origin: str, originator: str, path: str = None):
+ # DEBUG: print("DEBUG: domain,origin,originator,path:", domain, origin, originator, path)
if not validators.domain(domain.split("/")[0]):
print("WARNING: Bad domain name:", domain)
raise
print("WARNING: Bad origin name:", origin)
raise
- software = determine_software(domain)
+ software = determine_software(domain, path)
# DEBUG: print("DEBUG: Determined software:", software)
print(f"INFO: Adding instance {domain} (origin: {origin})")
import fba
fba.cursor.execute(
- "SELECT domain, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_block"]]
+ "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_block"]]
)
rows = fba.cursor.fetchall()
print(f"INFO: Checking {len(rows)} entries ...")
-for blocker, software in rows:
- # NOISY-DEBUG: print("DEBUG: BEFORE blocker,software:", blocker, software)
+for blocker, software, origin, nodeinfo_url in rows:
+ # NOISY-DEBUG: print("DEBUG: BEFORE blocker,software,origin,nodeinfo_url:", blocker, software, origin, nodeinfo_url)
blockdict = []
blocker = fba.tidyup(blocker)
# NOISY-DEBUG: print("DEBUG: AFTER blocker,software:", blocker, software)
print("INFO: blocker:", blocker)
try:
# Blocks
- json = fba.fetch_nodeinfo(blocker)
+ json = fba.fetch_nodeinfo(blocker, nodeinfo_url)
if json is None:
print("WARNING: Could not fetch nodeinfo from blocker:", blocker)
continue
if blocked.count("*") > 1:
# -ACK!-oma also started obscuring domains without hash
fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
+ "SELECT domain, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
)
searchres = fba.cursor.fetchone()
# NOISY-DEBUG: print("DEBUG: searchres[]:", type(searchres))
if searchres != None:
blocked = searchres[0]
+ nodeinfo_url = searchres[1]
# NOISY-DEBUG: print("DEBUG: Looked up domain:", blocked)
# NOISY-DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
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.add_instance(blocked, blocker, origin, nodeinfo_url)
fba.cursor.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
if fba.cursor.fetchone() == None:
# NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker)
- fba.add_instance(blocked, blocker, argv[0])
+ fba.add_instance(blocked, blocker, origin)
else:
# Doing the hash search for instance names as well to tidy up DB
fba.cursor.execute(
if blocked.count("?") > 0:
# Some obscure them with question marks, not sure if that's dependent on version or not
fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("?", "_")]
+ "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("?", "_")]
)
searchres = fba.cursor.fetchone()
if searchres != None:
blocked = searchres[0]
+ origin = searchres[1]
+ nodeinfo_url = searchres[2]
# NOISY-DEBUG: print("DEBUG: AFTER-blocked:", blocked)
if not fba.is_instance_registered(blocked):
# NOISY-DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker)
- fba.add_instance(blocked, blocker)
+ fba.add_instance(blocked, blocker, origin, nodeinfo_url)
fba.cursor.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ?",
elif blocked.count("*") > 0:
# GTS does not have hashes for obscured domains, so we have to guess it
fba.cursor.execute(
- "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
+ "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
)
searchres = fba.cursor.fetchone()
if searchres != None:
blocked = searchres[0]
+ origin = searchres[1]
+ nodeinfo_url = searchres[2]
if not fba.is_instance_registered(blocked):
# NOISY-DEBUG: print("DEBUG: Domain wasn't found, adding:", blocked, blocker)
- fba.add_instance(blocked, blocker)
+ fba.add_instance(blocked, blocker, origin, nodeinfo_url)
fba.cursor.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
import validators
import fba
-def fetch_instances(domain: str, origin: str, software: str):
- # NOISY-DEBUG: print("DEBUG: domain,origin,software:", domain, origin, software)
+def fetch_instances(domain: str, origin: str, software: str, path: str = None):
+ # NOISY-DEBUG: print("DEBUG: domain,origin,software,path:", domain, origin, software, path)
if not fba.is_instance_registered(domain):
# NOISY-DEBUG: print("DEBUG: Adding new domain:", domain, origin)
- fba.add_instance(domain, origin, sys.argv[0])
+ fba.add_instance(domain, origin, sys.argv[0], path)
# NOISY-DEBUG: print("DEBUG: Fetching instances for domain:", domain, software)
peerlist = fba.get_peers(domain, software)
# Loop through some instances
fba.cursor.execute(
- "SELECT domain,origin,software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
+ "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]]
)
rows = fba.cursor.fetchall()
print("WARNING: domain is blacklisted:", row[0])
continue
- print(f"INFO: Fetching instances for instance '{row[0]}'('{row[2]}') of origin '{row[1]}'")
- fetch_instances(row[0], row[1], row[2])
+ print(f"INFO: Fetching instances for instance '{row[0]}'('{row[2]}') of origin '{row[1]}',nodeinfo_url='{row[3]}'")
+ fetch_instances(row[0], row[1], row[2], row[3])
fba.connection.close()