mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-10 01:00:41 +08:00
expose BaseLimitIncrease.Apply
This commit is contained in:
parent
df93b499a4
commit
7ceb0b850c
56
limit.go
56
limit.go
@ -58,7 +58,7 @@ func readLimiterConfigFromJSON(in io.Reader, defaults LimitConfig) (LimitConfig,
|
||||
if err := json.NewDecoder(in).Decode(&cfg); err != nil {
|
||||
return LimitConfig{}, err
|
||||
}
|
||||
cfg.apply(defaults)
|
||||
cfg.Apply(defaults)
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@ -86,19 +86,8 @@ type BaseLimit struct {
|
||||
Memory int64
|
||||
}
|
||||
|
||||
// BaseLimitIncrease is the increase per GB of system memory.
|
||||
type BaseLimitIncrease struct {
|
||||
Streams int
|
||||
StreamsInbound int
|
||||
StreamsOutbound int
|
||||
Conns int
|
||||
ConnsInbound int
|
||||
ConnsOutbound int
|
||||
Memory int64
|
||||
FDFraction float64
|
||||
}
|
||||
|
||||
// Apply overwrites all zero-valued limits with the values of l2
|
||||
// Must not use a pointer receiver.
|
||||
func (l *BaseLimit) Apply(l2 BaseLimit) {
|
||||
if l.Streams == 0 {
|
||||
l.Streams = l2.Streams
|
||||
@ -126,6 +115,47 @@ func (l *BaseLimit) Apply(l2 BaseLimit) {
|
||||
}
|
||||
}
|
||||
|
||||
// BaseLimitIncrease is the increase per GB of system memory.
|
||||
type BaseLimitIncrease struct {
|
||||
Streams int
|
||||
StreamsInbound int
|
||||
StreamsOutbound int
|
||||
Conns int
|
||||
ConnsInbound int
|
||||
ConnsOutbound int
|
||||
Memory int64
|
||||
FDFraction float64
|
||||
}
|
||||
|
||||
// Apply overwrites all zero-valued limits with the values of l2
|
||||
// Must not use a pointer receiver.
|
||||
func (l *BaseLimitIncrease) Apply(l2 BaseLimitIncrease) {
|
||||
if l.Streams == 0 {
|
||||
l.Streams = l2.Streams
|
||||
}
|
||||
if l.StreamsInbound == 0 {
|
||||
l.StreamsInbound = l2.StreamsInbound
|
||||
}
|
||||
if l.StreamsOutbound == 0 {
|
||||
l.StreamsOutbound = l2.StreamsOutbound
|
||||
}
|
||||
if l.Conns == 0 {
|
||||
l.Conns = l2.Conns
|
||||
}
|
||||
if l.ConnsInbound == 0 {
|
||||
l.ConnsInbound = l2.ConnsInbound
|
||||
}
|
||||
if l.ConnsOutbound == 0 {
|
||||
l.ConnsOutbound = l2.ConnsOutbound
|
||||
}
|
||||
if l.Memory == 0 {
|
||||
l.Memory = l2.Memory
|
||||
}
|
||||
if l.FDFraction == 0 {
|
||||
l.FDFraction = l2.FDFraction
|
||||
}
|
||||
}
|
||||
|
||||
func (l *BaseLimit) GetStreamLimit(dir network.Direction) int {
|
||||
if dir == network.DirInbound {
|
||||
return l.StreamsInbound
|
||||
|
@ -124,7 +124,7 @@ type LimitConfig struct {
|
||||
Stream BaseLimit `json:",omitempty"`
|
||||
}
|
||||
|
||||
func (cfg *LimitConfig) apply(c LimitConfig) {
|
||||
func (cfg *LimitConfig) Apply(c LimitConfig) {
|
||||
cfg.System.Apply(c.System)
|
||||
cfg.Transient.Apply(c.Transient)
|
||||
cfg.ServiceDefault.Apply(c.ServiceDefault)
|
||||
|
Loading…
Reference in New Issue
Block a user