Versions in this module Expand all Collapse all v1 v1.10.0 Dec 13, 2023 v1.9.3 Dec 12, 2023 v1.9.2 Dec 12, 2023 v1.9.1 Dec 12, 2023 v1.6.0 Dec 12, 2023 v1.2.0 Dec 5, 2023 Changes in this version + var DefaultLimits = ScalingLimitConfig + var InfiniteLimits = ConcreteLimitConfig + func IsConnScope(name string) bool + func IsSpan(name string) bool + func IsStreamScope(name string) bool + func IsSystemScope(name string) bool + func IsTransientScope(name string) bool + func MustRegisterWith(reg prometheus.Registerer) + func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager, error) + func ParseProtocolScopeName(name string) string + func PeerStrInScopeName(name string) string + type Allowlist struct + func GetAllowlist(rcmgr network.ResourceManager) *Allowlist + func (al *Allowlist) Add(ma multiaddr.Multiaddr) error + func (al *Allowlist) Allowed(ma multiaddr.Multiaddr) bool + func (al *Allowlist) AllowedPeerAndMultiaddr(peerID peer.ID, ma multiaddr.Multiaddr) bool + func (al *Allowlist) Remove(ma multiaddr.Multiaddr) error + type BaseLimit struct + Conns int + ConnsInbound int + ConnsOutbound int + FD int + Memory int64 + Streams int + StreamsInbound int + StreamsOutbound int + func (l *BaseLimit) Apply(l2 BaseLimit) + func (l BaseLimit) GetConnLimit(dir network.Direction) int + func (l BaseLimit) GetConnTotalLimit() int + func (l BaseLimit) GetFDLimit() int + func (l BaseLimit) GetMemoryLimit() int64 + func (l BaseLimit) GetStreamLimit(dir network.Direction) int + func (l BaseLimit) GetStreamTotalLimit() int + func (l BaseLimit) ToResourceLimits() ResourceLimits + type BaseLimitIncrease struct + Conns int + ConnsInbound int + ConnsOutbound int + FDFraction float64 + Memory int64 + Streams int + StreamsInbound int + StreamsOutbound int + func (l *BaseLimitIncrease) Apply(l2 BaseLimitIncrease) + type ConcreteLimitConfig struct + func (cfg ConcreteLimitConfig) ToPartialLimitConfig() PartialLimitConfig + type ErrMemoryLimitExceeded struct + func (e *ErrMemoryLimitExceeded) Error() string + func (e *ErrMemoryLimitExceeded) Unwrap() error + type ErrStreamOrConnLimitExceeded struct + func (e *ErrStreamOrConnLimitExceeded) Error() string + func (e *ErrStreamOrConnLimitExceeded) Unwrap() error + type Limit interface + GetConnLimit func(network.Direction) int + GetConnTotalLimit func() int + GetFDLimit func() int + GetMemoryLimit func() int64 + GetStreamLimit func(network.Direction) int + GetStreamTotalLimit func() int + type LimitVal int + const BlockAllLimit + const DefaultLimit + const Unlimited + func (l *LimitVal) UnmarshalJSON(b []byte) error + func (l LimitVal) Build(defaultVal int) int + func (l LimitVal) MarshalJSON() ([]byte, error) + type LimitVal64 int64 + const BlockAllLimit64 + const DefaultLimit64 + const Unlimited64 + func (l *LimitVal64) UnmarshalJSON(b []byte) error + func (l LimitVal64) Build(defaultVal int64) int64 + func (l LimitVal64) MarshalJSON() ([]byte, error) + type Limiter interface + GetAllowlistedSystemLimits func() Limit + GetAllowlistedTransientLimits func() Limit + GetConnLimits func() Limit + GetPeerLimits func(p peer.ID) Limit + GetProtocolLimits func(proto protocol.ID) Limit + GetProtocolPeerLimits func(proto protocol.ID) Limit + GetServiceLimits func(svc string) Limit + GetServicePeerLimits func(svc string) Limit + GetStreamLimits func(p peer.ID) Limit + GetSystemLimits func() Limit + GetTransientLimits func() Limit + func NewDefaultLimiterFromJSON(in io.Reader) (Limiter, error) + func NewFixedLimiter(conf ConcreteLimitConfig) Limiter + func NewLimiterFromJSON(in io.Reader, defaults ConcreteLimitConfig) (Limiter, error) + type MetricsReporter interface + AllowConn func(dir network.Direction, usefd bool) + AllowMemory func(size int) + AllowPeer func(p peer.ID) + AllowProtocol func(proto protocol.ID) + AllowService func(svc string) + AllowStream func(p peer.ID, dir network.Direction) + BlockConn func(dir network.Direction, usefd bool) + BlockMemory func(size int) + BlockPeer func(p peer.ID) + BlockProtocol func(proto protocol.ID) + BlockProtocolPeer func(proto protocol.ID, p peer.ID) + BlockService func(svc string) + BlockServicePeer func(svc string, p peer.ID) + BlockStream func(p peer.ID, dir network.Direction) + type Option func(*resourceManager) error + func WithAllowlistedMultiaddrs(mas []multiaddr.Multiaddr) Option + func WithMetrics(reporter MetricsReporter) Option + func WithMetricsDisabled() Option + func WithTrace(path string) Option + func WithTraceReporter(reporter TraceReporter) Option + type PartialLimitConfig struct + AllowlistedSystem ResourceLimits + AllowlistedTransient ResourceLimits + Conn ResourceLimits + Peer map[peer.ID]ResourceLimits + PeerDefault ResourceLimits + Protocol map[protocol.ID]ResourceLimits + ProtocolDefault ResourceLimits + ProtocolPeer map[protocol.ID]ResourceLimits + ProtocolPeerDefault ResourceLimits + Service map[string]ResourceLimits + ServiceDefault ResourceLimits + ServicePeer map[string]ResourceLimits + ServicePeerDefault ResourceLimits + Stream ResourceLimits + System ResourceLimits + Transient ResourceLimits + func (cfg *PartialLimitConfig) Apply(c PartialLimitConfig) + func (cfg *PartialLimitConfig) MarshalJSON() ([]byte, error) + func (cfg PartialLimitConfig) Build(defaults ConcreteLimitConfig) ConcreteLimitConfig + type ResourceLimits struct + Conns LimitVal + ConnsInbound LimitVal + ConnsOutbound LimitVal + FD LimitVal + Memory LimitVal64 + Streams LimitVal + StreamsInbound LimitVal + StreamsOutbound LimitVal + func (l *ResourceLimits) Apply(l2 ResourceLimits) + func (l *ResourceLimits) Build(defaults Limit) BaseLimit + func (l *ResourceLimits) IsDefault() bool + func (l *ResourceLimits) ToMaybeNilPtr() *ResourceLimits + type ResourceManagerStat struct + Peers map[peer.ID]network.ScopeStat + Protocols map[protocol.ID]network.ScopeStat + Services map[string]network.ScopeStat + System network.ScopeStat + Transient network.ScopeStat + type ResourceManagerState interface + ListPeers func() []peer.ID + ListProtocols func() []protocol.ID + ListServices func() []string + Stat func() ResourceManagerStat + type ResourceScopeLimiter interface + Limit func() Limit + SetLimit func(Limit) + type ScalingLimitConfig struct + AllowlistedSystemBaseLimit BaseLimit + AllowlistedSystemLimitIncrease BaseLimitIncrease + AllowlistedTransientBaseLimit BaseLimit + AllowlistedTransientLimitIncrease BaseLimitIncrease + ConnBaseLimit BaseLimit + ConnLimitIncrease BaseLimitIncrease + PeerBaseLimit BaseLimit + PeerLimitIncrease BaseLimitIncrease + PeerLimits map[peer.ID]baseLimitConfig + ProtocolBaseLimit BaseLimit + ProtocolLimitIncrease BaseLimitIncrease + ProtocolLimits map[protocol.ID]baseLimitConfig + ProtocolPeerBaseLimit BaseLimit + ProtocolPeerLimitIncrease BaseLimitIncrease + ProtocolPeerLimits map[protocol.ID]baseLimitConfig + ServiceBaseLimit BaseLimit + ServiceLimitIncrease BaseLimitIncrease + ServiceLimits map[string]baseLimitConfig + ServicePeerBaseLimit BaseLimit + ServicePeerLimitIncrease BaseLimitIncrease + ServicePeerLimits map[string]baseLimitConfig + StreamBaseLimit BaseLimit + StreamLimitIncrease BaseLimitIncrease + SystemBaseLimit BaseLimit + SystemLimitIncrease BaseLimitIncrease + TransientBaseLimit BaseLimit + TransientLimitIncrease BaseLimitIncrease + func (cfg *ScalingLimitConfig) AddPeerLimit(p peer.ID, base BaseLimit, inc BaseLimitIncrease) + func (cfg *ScalingLimitConfig) AddProtocolLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease) + func (cfg *ScalingLimitConfig) AddProtocolPeerLimit(proto protocol.ID, base BaseLimit, inc BaseLimitIncrease) + func (cfg *ScalingLimitConfig) AddServiceLimit(svc string, base BaseLimit, inc BaseLimitIncrease) + func (cfg *ScalingLimitConfig) AddServicePeerLimit(svc string, base BaseLimit, inc BaseLimitIncrease) + func (cfg *ScalingLimitConfig) AutoScale() ConcreteLimitConfig + func (cfg *ScalingLimitConfig) Scale(memory int64, numFD int) ConcreteLimitConfig + type StatsTraceReporter struct + func NewStatsTraceReporter() (StatsTraceReporter, error) + func (r StatsTraceReporter) ConsumeEvent(evt TraceEvt) + type TraceEvt struct + ConnsIn int + ConnsOut int + Delta int64 + DeltaIn int + DeltaOut int + FD int + Limit interface{} + Memory int64 + Name string + Priority uint8 + Scope *scopeClass + StreamsIn int + StreamsOut int + Time string + Type TraceEvtTyp + type TraceEvtTyp string + const TraceAddConnEvt + const TraceAddStreamEvt + const TraceBlockAddConnEvt + const TraceBlockAddStreamEvt + const TraceBlockReserveMemoryEvt + const TraceCreateScopeEvt + const TraceDestroyScopeEvt + const TraceReleaseMemoryEvt + const TraceRemoveConnEvt + const TraceRemoveStreamEvt + const TraceReserveMemoryEvt + const TraceStartEvt + type TraceReporter interface + ConsumeEvent func(TraceEvt)