package p2p import ( "github.com/libp2p/go-libp2p" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" ) // DefaultPublicConns is how many inbound connections a --public node accepts // unless told otherwise. libp2p's own cap scales with the machine's memory // (about 190 on 16 GB, fewer in a small container), which strands newcomers // once a bootstrap node has that many peers: the simulator showed 12 of 200 // nodes and 212 of 400 never finding a single peer. A connection costs a few // tens of kilobytes, so 1000 fits a 512 MiB pod. const DefaultPublicConns = 1000 // connectionLimits is libp2p's resource manager with the connection caps set // to conns inbound (and twice that in total, which includes the node's own // dials). Everything else keeps libp2p's defaults, scaled to the machine. func connectionLimits(conns int) (libp2p.Option, error) { limits := rcmgr.DefaultLimits libp2p.SetDefaultServiceLimits(&limits) cfg := rcmgr.PartialLimitConfig{ System: rcmgr.ResourceLimits{Conns: rcmgr.LimitVal(2 * conns), ConnsInbound: rcmgr.LimitVal(conns)}, Transient: rcmgr.ResourceLimits{Conns: rcmgr.LimitVal(conns), ConnsInbound: rcmgr.LimitVal(conns)}, } mgr, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(cfg.Build(limits.AutoScale()))) if err != nil { return nil, err } return libp2p.ResourceManager(mgr), nil }