if software == "misskey":
# DEBUG: print(f"DEBUG: domain='{domain}' is misskey, sending API POST request ...")
- counter = 0
+ 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
while True:
- if counter == 0:
+ # DEBUG: print(f"DEBUG: Fetching offset='{offset}' from '{domain}' ...")
+ if offset == 0:
fetched = post_json_api(domain, "/api/federation/instances", json.dumps({
"sort" : "+pubAt",
"host" : None,
"sort" : "+pubAt",
"host" : None,
"limit" : step,
- "offset": counter - 1
+ "offset": offset - 1
}), {"Origin": domain})
# DEBUG: print("DEBUG: fetched():", len(fetched))
if len(fetched) == 0:
# DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
-
- # DEBUG: print("DEBUG: Raising counter by step:", step)
- counter = counter + step
+ elif len(fetched) != config["misskey_offset"]:
+ print(f"WARNING: Fetched '{len(fetched)}' row(s) but expected: '{config['misskey_offset']}'")
+ offset = offset + (config["misskey_offset"] - len(fetched))
+ else:
+ # DEBUG: print("DEBUG: Raising offset by step:", step)
+ offset = offset + step
# Check records
for row in fetched:
# DEBUG: print(f"DEBUG: row():{len(row)}")
- if "host" in row:
+ if "host" in row and is_blacklisted(row["host"]):
+ print(f"WARNING: row[host]='{row['host']}' is blacklisted. domain='{domain}'")
+ elif "host" in row:
# DEBUG: print(f"DEBUG: Adding peer: '{row['host']}'")
peers.append(row["host"])
+ else:
+ print(f"WARNING: row()={len(row)} does not contain element 'host': {row},domain='{domain}'")
# DEBUG: print("DEBUG: Returning peers[]:", type(peers))
return peers
data = res.json()
except BaseException as e:
- print("WARNING: Some error during post():", domain, path, parameter, e)
+ print(f"WARNING: Some error during post(): domain='{domain},path='{path}',parameter()={len(parameter)},exception:'{e}'")
# DEBUG: print("DEBUG: Returning data():", len(data))
return data
# DEBUG: print("DEBUG: Fetching nodeinfo from domain:", domain)
nodeinfo = fetch_wellknown_nodeinfo(domain)
- # DEBUG: print("DEBUG:nodeinfo:", len(nodeinfo))
+ # DEBUG: print("DEBUG: nodeinfo:", len(nodeinfo))
if len(nodeinfo) > 0:
# DEBUG: print("DEBUG: Returning auto-discovered nodeinfo:", len(nodeinfo))
return {}
for line in blocklist.find("table").find_all("tr")[1:]:
+ # DEBUG: print(f"DEBUG: line='{line}'")
blocks.append({
"domain": tidyup(line.find_all("td")[0].text),
"reason": tidyup(line.find_all("td")[1].text)
"blocked" : []
}
- counter = 0
+ offset = 0
step = config["misskey_offset"]
while True:
# iterating through all "suspended" (follow-only in its terminology)
# instances page-by-page, since that troonware doesn't support
# sending them all at once
try:
- if counter == 0:
- # DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain, "/api/federation/instances", json.dumps({
+ print(f"DEBUG: Fetching offset='{offset}' from '{domain}' ...")
+ if offset == 0:
+ # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+ fetched = post_json_api(domain, "/api/federation/instances", json.dumps({
"sort" : "+pubAt",
"host" : None,
"suspended": True,
"limit" : step
}), {"Origin": domain})
else:
- # DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain, "/api/federation/instances", json.dumps({
+ # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+ fetched = post_json_api(domain, "/api/federation/instances", json.dumps({
"sort" : "+pubAt",
"host" : None,
"suspended": True,
"limit" : step,
- "offset" : counter - 1
+ "offset" : offset - 1
}), {"Origin": domain})
- # DEBUG: print("DEBUG: doc():", len(doc))
- if len(doc) == 0:
+ print("DEBUG: fetched():", len(fetched))
+ if len(fetched) == 0:
# DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
+ elif len(fetched) != config["misskey_offset"]:
+ print(f"WARNING: Fetched '{len(fetched)}' row(s) but expected: '{config['misskey_offset']}'")
+ offset = offset + (config["misskey_offset"] - len(fetched))
+ else:
+ # DEBUG: print("DEBUG: Raising offset by step:", step)
+ offset = offset + step
- for instance in doc:
+ for instance in fetched:
# just in case
if instance["isSuspended"]:
blocks["suspended"].append(
}
)
- if len(doc) < step:
- # DEBUG: print("DEBUG: End of request:", len(doc), step)
- break
-
- # DEBUG: print("DEBUG: Raising counter by step:", step)
- counter = counter + step
-
except BaseException as e:
print("WARNING: Caught error, exiting loop:", domain, e)
update_last_error(domain, e)
- counter = 0
+ offset = 0
break
while True:
# same shit, different asshole ("blocked" aka full suspend)
try:
- if counter == 0:
- # DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain,"/api/federation/instances", json.dumps({
+ if offset == 0:
+ # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+ fetched = post_json_api(domain,"/api/federation/instances", json.dumps({
"sort" : "+pubAt",
"host" : None,
"blocked": True,
"limit" : step
}), {"Origin": domain})
else:
- # DEBUG: print("DEBUG: Sending JSON API request to domain,step,counter:", domain, step, counter)
- doc = post_json_api(domain,"/api/federation/instances", json.dumps({
+ # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+ fetched = post_json_api(domain,"/api/federation/instances", json.dumps({
"sort" : "+pubAt",
"host" : None,
"blocked": True,
"limit" : step,
- "offset" : counter-1
+ "offset" : offset-1
}), {"Origin": domain})
- # DEBUG: print("DEBUG: doc():", len(doc))
- if len(doc) == 0:
+ print("DEBUG: fetched():", len(fetched))
+ if len(fetched) == 0:
# DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
break
+ elif len(fetched) != config["misskey_offset"]:
+ print(f"WARNING: Fetched '{len(fetched)}' row(s) but expected: '{config['misskey_offset']}'")
+ offset = offset + (config["misskey_offset"] - len(fetched))
+ else:
+ # DEBUG: print("DEBUG: Raising offset by step:", step)
+ offset = offset + step
- for instance in doc:
+ for instance in fetched:
if instance["isBlocked"]:
blocks["blocked"].append({
"domain": tidyup(instance["host"]),
"reason": None
})
- if len(doc) < step:
- # DEBUG: print("DEBUG: End of request:", len(doc), step)
- break
-
- # DEBUG: print("DEBUG: Raising counter by step:", step)
- counter = counter + step
-
except BaseException as e:
print("ERROR: Exception during POST:", domain, e)
update_last_error(domain, e)
- counter = 0
+ offset = 0
break
# DEBUG: print("DEBUG: Returning for domain,blocked(),suspended():", domain, len(blocks["blocked"]), len(blocks["suspended"]))