p2p: a --public node accepts 1000 inbound connections (--max-conns), instead of libp2p's memory-scaled default

The simulator showed libp2p's default cap (about 190 on 16 GB) stranding newcomers
on a bootstrap node: 12 of 200 and 212 of 400 nodes never found a peer. As
shipped, the same networks now form and deliver 100% up to 600 nodes.

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-18 22:46:05 +01:00
co-authored by Claude Sonnet 5.5
parent 130ba5dc65
commit 86668baf5a
10 changed files with 170 additions and 53 deletions
+16
View File
@@ -107,6 +107,11 @@ type Config struct {
// Bandwidth, if set, counts the bytes this node sends and receives (the
// simulator uses it; a real node leaves it nil).
Bandwidth metrics.Reporter
// MaxConns is the number of inbound connections the node accepts. Zero
// means DefaultPublicConns for a Public node and libp2p's own default
// (which scales with memory) for any other; a negative number keeps
// libp2p's default even for a Public node.
MaxConns int
// ExtraOptions are added to the libp2p host's options; the simulator uses
// them to put latency and connection loss on the transport.
ExtraOptions []libp2p.Option
@@ -206,6 +211,17 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
}
opts = append(opts, libp2p.AddrsFactory(func([]ma.Multiaddr) []ma.Multiaddr { return announce }))
}
conns := cfg.MaxConns
if conns == 0 && cfg.Public {
conns = DefaultPublicConns
}
if conns > 0 {
limits, err := connectionLimits(conns)
if err != nil {
return nil, fmt.Errorf("connection limits: %w", err)
}
opts = append(opts, limits)
}
opts = append(opts, cfg.ExtraOptions...)
if cfg.Bandwidth != nil {
opts = append(opts, libp2p.BandwidthReporter(cfg.Bandwidth))