limits: sync streams, listings per author, inbound connections per IP
A peer may hold 4 sync streams and open 1500 a minute; banned peers get none and cannot redial. A node keeps at most 100 unexpired listings per author (--max-per-author); updates, renewals and deletions of held ones still work. At most 16 inbound connections per public IP or IPv6 /64 (--max-conns-per-ip); local and private addresses are exempt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+14
-1
@@ -116,6 +116,10 @@ type Config struct {
|
||||
// (which scales with memory) for any other; a negative number keeps
|
||||
// libp2p's default even for a Public node.
|
||||
MaxConns int
|
||||
// MaxConnsPerIP is how many inbound connections one public IP address (an
|
||||
// IPv6 /64) may hold; local and private addresses are exempt. Zero means
|
||||
// DefaultConnsPerIP, a negative number no limit.
|
||||
MaxConnsPerIP 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
|
||||
@@ -233,6 +237,12 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
|
||||
}
|
||||
opts = append(opts, limits)
|
||||
}
|
||||
perIP := cfg.MaxConnsPerIP
|
||||
if perIP == 0 {
|
||||
perIP = DefaultConnsPerIP
|
||||
}
|
||||
gate := newIPGate(max(perIP, 0))
|
||||
opts = append(opts, libp2p.ConnectionGater(gate))
|
||||
opts = append(opts, cfg.ExtraOptions...)
|
||||
if cfg.Bandwidth != nil {
|
||||
opts = append(opts, libp2p.BandwidthReporter(cfg.Bandwidth))
|
||||
@@ -274,6 +284,9 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
|
||||
n.Close()
|
||||
return nil, err
|
||||
}
|
||||
h.Network().Notify(gate.notifee())
|
||||
banned := n.guard.banned
|
||||
gate.banned.Store(&banned)
|
||||
n.ps, err = pubsub.NewGossipSub(nctx, h,
|
||||
pubsub.WithMaxMessageSize(listing.MaxSize+4096),
|
||||
pubsub.WithFloodPublish(true),
|
||||
@@ -612,7 +625,7 @@ func (n *Node) subscribeRegion(region string) error {
|
||||
switch out, err := n.cfg.Store.Put(n.ctx, l); {
|
||||
case err == nil:
|
||||
n.noteListing(n.ctx, l, out, "gossip", msg.ReceivedFrom)
|
||||
case errors.Is(err, store.ErrRevoked):
|
||||
case errors.Is(err, store.ErrRevoked), errors.Is(err, store.ErrQuota):
|
||||
default:
|
||||
n.log.Warn("store listing", "err", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user