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:
2026-11-19 00:54:48 +01:00
co-authored by Claude Sonnet 5.5
parent 2e105ef353
commit 59973cbf43
8 changed files with 452 additions and 31 deletions
+5 -2
View File
@@ -73,6 +73,7 @@ type sim struct {
msgDiff int
discover time.Duration
antiEnt time.Duration
antiPeers int
rng *rand.Rand
extra []libp2p.Option // transport conditions (latency, connection loss)
timeout time.Duration
@@ -91,7 +92,8 @@ func main() {
reports := flag.Int("reports", 3, "abuse reports to publish")
churn := flag.Float64("churn", 0.2, "fraction of nodes that go offline while listings are published, then come back")
discover := flag.Duration("discover", 5*time.Second, "how often nodes look for region peers (a real node: 1m)")
antiEntropy := flag.Duration("anti-entropy", 30*time.Minute, "anti-entropy interval (a real node: 30m)")
antiEntropy := flag.Duration("anti-entropy", 10*time.Minute, "anti-entropy interval (a real node: 10m)")
antiPeers := flag.Int("anti-entropy-peers", 3, "peers asked per anti-entropy round (a real node: 3)")
timeout := flag.Duration("timeout", 60*time.Second, "how long to wait for each thing to spread")
latency := flag.Duration("latency", 0, "delay added to every write on connections a node dials (one direction), with up to 50% jitter")
lifetime := flag.Duration("lifetime", 0, "mean lifetime of a dialed connection before it is cut (0: never); redials and resyncs follow")
@@ -109,7 +111,7 @@ func main() {
s := &sim{
ctx: context.Background(), difficulty: 8, msgDiff: 6,
discover: *discover, antiEnt: *antiEntropy,
discover: *discover, antiEnt: *antiEntropy, antiPeers: *antiPeers,
rng: rand.New(rand.NewPCG(*seed, 7)), timeout: *timeout, seedConns: *seedConns,
}
var conditions *netConditions
@@ -355,6 +357,7 @@ func (s *sim) start(n *simNode) error {
RedialInterval: 2 * time.Second,
DiscoverInterval: s.discover,
AntiEntropyInterval: s.antiEnt,
AntiEntropyPeers: s.antiPeers,
RelayBootDelay: 10 * time.Minute,
Logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
Bandwidth: n.bw,