p2p: peer exchange to find a region without the DHT, region-tagged peer cache, faster anti-entropy
A node with too few peers in a followed region asks its connected peers who they know there (sync kind "peers"); a peer answers even from another region, since gossip tells it which topics its connections subscribe to. Peers of the region are dialed, others only while the region has none. The peer cache records the regions a peer was seen in and a restart redials those first. Anti-entropy now runs every 10 minutes (plus or minus a fifth) with 3 peers per round instead of every 30 with one. Simulator: a newcomer whose remembered peers were all in another region got 0 of 114 listings with the seeds down, now 56 of 56; repair median at the same interval 25.9 s to 5.7 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+12
-1
@@ -74,7 +74,7 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch" || req.Kind == "reports") {
|
||||
if n.oldSync && (req.Kind == "digest" || req.Kind == "inventory" || req.Kind == "fetch" || req.Kind == "reports" || req.Kind == "peers") {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
@@ -187,6 +187,17 @@ func (n *Node) handleSync(s network.Stream) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
case "peers":
|
||||
if !listing.ValidRegion(req.Region) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
for _, pl := range n.peersFor(s.Conn().RemotePeer(), req.Region) {
|
||||
if !write(json.Marshal(pl)) {
|
||||
_ = s.Reset()
|
||||
return
|
||||
}
|
||||
}
|
||||
case "inventory":
|
||||
if !listing.ValidRegion(req.Region) {
|
||||
_ = s.Reset()
|
||||
|
||||
Reference in New Issue
Block a user