Skip to content

Commit

Permalink
fix(network): set connection limit for the resource manager
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Oct 24, 2023
1 parent 57af41e commit 57f80aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (g *gossipService) onReceiveMessage(m *lp2pps.Message) {
return
}

g.logger.Debug("receiving new gossip message",
g.logger.Trace("receiving new gossip message",
"source", m.GetFrom(), "from", m.ReceivedFrom)
event := &GossipMessage{
Source: m.GetFrom(),
Expand Down
13 changes: 10 additions & 3 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network,
return nil, LibP2PError{Err: err}
}

rmgr, err := lp2prcmgr.NewResourceManager(
lp2prcmgr.NewFixedLimiter(lp2prcmgr.DefaultLimits.AutoScale()),
maxconns := conf.MaxConns
changes := lp2prcmgr.PartialLimitConfig{}
changes.System.ConnsInbound = lp2prcmgr.LimitVal(2 * maxconns)
changes.System.ConnsOutbound = lp2prcmgr.LimitVal(2 * maxconns)
changes.System.Conns = lp2prcmgr.LimitVal(4 * maxconns)
limit := changes.Build(lp2prcmgr.DefaultLimits.AutoScale())

resMgr, err := lp2prcmgr.NewResourceManager(
lp2prcmgr.NewFixedLimiter(limit),
lp2prcmgr.WithTraceReporter(str),
)
if err != nil {
Expand All @@ -116,7 +123,7 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network,
lp2p.Identity(networkKey),
lp2p.ListenAddrStrings(conf.Listens...),
lp2p.UserAgent(version.Agent()),
lp2p.ResourceManager(rmgr),
lp2p.ResourceManager(resMgr),
lp2p.ConnectionManager(connMgr),
)

Expand Down
4 changes: 2 additions & 2 deletions network/notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.C
peerID := conn.RemotePeer()

go func() {
for i := 0; i < 6; i++ {
for i := 0; i < 10; i++ {
// TODO: better way?
// Wait to complete libp2p identify
time.Sleep(200 * time.Millisecond)
time.Sleep(500 * time.Millisecond)

protocols, _ := lp2pn.Peerstore().SupportsProtocols(peerID, n.protocolID)
if len(protocols) > 0 {
Expand Down

0 comments on commit 57f80aa

Please sign in to comment.