auto peer discovery: gossip known peers during sync, discover from_hash automatically

This commit is contained in:
user 2026-06-05 00:43:18 +00:00
parent b39d70dd6c
commit 55a6d22482
4 changed files with 87 additions and 1 deletions

View file

@ -604,6 +604,14 @@ class ForumHandlers:
if r.get("id") and r.get("type") and r.get("author") and r.get("at"):
self.fdb.merge_retraction(r["id"], r["type"], r["author"], r["at"])
# Auto-discover the peer that synced with us and their known peers
from_hash = data.get("from_hash", "")
if from_hash and from_hash not in blocked:
self.fdb.add_known_peer(from_hash)
for peer_hash in data.get("known_peers", []):
if peer_hash and peer_hash != from_hash and peer_hash not in blocked:
self.fdb.add_known_peer(peer_hash)
my_blocks = list(blocked)
my_peer_blocks = self.fdb.get_peer_block_list()
threads, posts, upvote_threads = [], [], []
@ -616,6 +624,8 @@ class ForumHandlers:
retracted = [{"id": cid, "type": ct, "author": ai, "at": ra}
for cid, ct, ai, ra in self.fdb.get_raw_retractions()]
known_peers = [h for h in self.fdb.get_all_known_hashes() if h != from_hash]
return {
"status": 200,
"content_type": "application/json",
@ -625,6 +635,7 @@ class ForumHandlers:
"upvote_threads": upvote_threads,
"blocks": {"mine": my_blocks, "peers": my_peer_blocks},
"retractions": retracted,
"known_peers": known_peers,
}),
"headers": {},
}