package libp2p
import (
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/p2p/host/autonat"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
circuit "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
relayv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay"
"github.com/libp2p/go-libp2p/p2p/protocol/holepunch"
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
)
func SetDefaultServiceLimits (config *rcmgr .ScalingLimitConfig ) {
config .AddServiceLimit (
identify .ServiceName ,
rcmgr .BaseLimit {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 128 , Memory : 4 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 128 , Memory : 4 << 20 },
)
config .AddServicePeerLimit (
identify .ServiceName ,
rcmgr .BaseLimit {StreamsInbound : 16 , StreamsOutbound : 16 , Streams : 32 , Memory : 1 << 20 },
rcmgr .BaseLimitIncrease {},
)
for _ , id := range [...]protocol .ID {identify .ID , identify .IDPush } {
config .AddProtocolLimit (
id ,
rcmgr .BaseLimit {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 128 , Memory : 4 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 128 , Memory : 4 << 20 },
)
config .AddProtocolPeerLimit (
id ,
rcmgr .BaseLimit {StreamsInbound : 16 , StreamsOutbound : 16 , Streams : 32 , Memory : 32 * (256 <<20 + 16 <<10 )},
rcmgr .BaseLimitIncrease {},
)
}
addServiceAndProtocolLimit (config ,
ping .ServiceName , ping .ID ,
rcmgr .BaseLimit {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 64 , Memory : 4 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 64 , Memory : 4 << 20 },
)
addServicePeerAndProtocolPeerLimit (
config ,
ping .ServiceName , ping .ID ,
rcmgr .BaseLimit {StreamsInbound : 2 , StreamsOutbound : 3 , Streams : 4 , Memory : 32 * (256 <<20 + 16 <<10 )},
rcmgr .BaseLimitIncrease {},
)
addServiceAndProtocolLimit (config ,
autonat .ServiceName , autonat .AutoNATProto ,
rcmgr .BaseLimit {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 64 , Memory : 4 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 4 , StreamsOutbound : 4 , Streams : 4 , Memory : 2 << 20 },
)
addServicePeerAndProtocolPeerLimit (
config ,
autonat .ServiceName , autonat .AutoNATProto ,
rcmgr .BaseLimit {StreamsInbound : 2 , StreamsOutbound : 2 , Streams : 2 , Memory : 1 << 20 },
rcmgr .BaseLimitIncrease {},
)
addServiceAndProtocolLimit (config ,
holepunch .ServiceName , holepunch .Protocol ,
rcmgr .BaseLimit {StreamsInbound : 32 , StreamsOutbound : 32 , Streams : 64 , Memory : 4 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 8 , StreamsOutbound : 8 , Streams : 16 , Memory : 4 << 20 },
)
addServicePeerAndProtocolPeerLimit (config ,
holepunch .ServiceName , holepunch .Protocol ,
rcmgr .BaseLimit {StreamsInbound : 2 , StreamsOutbound : 2 , Streams : 2 , Memory : 1 << 20 },
rcmgr .BaseLimitIncrease {},
)
config .AddServiceLimit (
relayv2 .ServiceName ,
rcmgr .BaseLimit {StreamsInbound : 256 , StreamsOutbound : 256 , Streams : 256 , Memory : 16 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 256 , StreamsOutbound : 256 , Streams : 256 , Memory : 16 << 20 },
)
config .AddServicePeerLimit (
relayv2 .ServiceName ,
rcmgr .BaseLimit {StreamsInbound : 64 , StreamsOutbound : 64 , Streams : 64 , Memory : 1 << 20 },
rcmgr .BaseLimitIncrease {},
)
for _ , proto := range [...]protocol .ID {circuit .ProtoIDv2Hop , circuit .ProtoIDv2Stop } {
config .AddProtocolLimit (
proto ,
rcmgr .BaseLimit {StreamsInbound : 640 , StreamsOutbound : 640 , Streams : 640 , Memory : 16 << 20 },
rcmgr .BaseLimitIncrease {StreamsInbound : 640 , StreamsOutbound : 640 , Streams : 640 , Memory : 16 << 20 },
)
config .AddProtocolPeerLimit (
proto ,
rcmgr .BaseLimit {StreamsInbound : 128 , StreamsOutbound : 128 , Streams : 128 , Memory : 32 << 20 },
rcmgr .BaseLimitIncrease {},
)
}
}
func addServiceAndProtocolLimit(config *rcmgr .ScalingLimitConfig , service string , proto protocol .ID , limit rcmgr .BaseLimit , increase rcmgr .BaseLimitIncrease ) {
config .AddServiceLimit (service , limit , increase )
config .AddProtocolLimit (proto , limit , increase )
}
func addServicePeerAndProtocolPeerLimit(config *rcmgr .ScalingLimitConfig , service string , proto protocol .ID , limit rcmgr .BaseLimit , increase rcmgr .BaseLimitIncrease ) {
config .AddServicePeerLimit (service , limit , increase )
config .AddProtocolPeerLimit (proto , limit , increase )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .