Skip to content

Commit dca6313

Browse files
committed
chore(p2p): use fallback defaults from lib
1 parent 8087723 commit dca6313

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

rolling-shutter/p2p/p2p.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import (
44
"context"
55
"fmt"
66
"sync"
7-
"time"
87

98
"github.com/libp2p/go-libp2p"
109
dht "github.com/libp2p/go-libp2p-kad-dht"
1110
pubsub "github.com/libp2p/go-libp2p-pubsub"
1211
"github.com/libp2p/go-libp2p/core/host"
1312
"github.com/libp2p/go-libp2p/core/peer"
1413
"github.com/libp2p/go-libp2p/p2p/discovery/routing"
14+
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
1515
rhost "github.com/libp2p/go-libp2p/p2p/host/routed"
16-
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
1716
"github.com/multiformats/go-multiaddr"
1817
"github.com/pkg/errors"
1918
"github.com/rs/zerolog/log"
@@ -51,7 +50,6 @@ type Notifee interface {
5150
type P2PNode struct {
5251
config p2pNodeConfig
5352

54-
connmngr *connmgr.BasicConnMgr
5553
mux sync.Mutex
5654
host host.Host
5755
dht *dht.IpfsDHT
@@ -74,7 +72,6 @@ type p2pNodeConfig struct {
7472
func NewP2PNode(config p2pNodeConfig) *P2PNode {
7573
p := P2PNode{
7674
config: config,
77-
connmngr: nil,
7875
host: nil,
7976
pubSub: nil,
8077
gossipRooms: make(map[string]*gossipRoom),
@@ -149,7 +146,7 @@ func (p *P2PNode) init(ctx context.Context) error {
149146
if p.host != nil {
150147
return errors.New("Cannot create host on p2p with existing host")
151148
}
152-
p2pHost, hashTable, connectionManager, err := createHost(ctx, p.config)
149+
p2pHost, hashTable, err := createHost(ctx, p.config)
153150
if err != nil {
154151
return err
155152
}
@@ -160,7 +157,6 @@ func (p *P2PNode) init(ctx context.Context) error {
160157

161158
p.host = p2pHost
162159
p.dht = hashTable
163-
p.connmngr = connectionManager
164160
p.pubSub = p2pPubSub
165161
log.Info().Str("address", p.p2pAddress()).Msg("created libp2p host")
166162
return nil
@@ -169,24 +165,22 @@ func (p *P2PNode) init(ctx context.Context) error {
169165
func createHost(
170166
ctx context.Context,
171167
config p2pNodeConfig,
172-
) (host.Host, *dht.IpfsDHT, *connmgr.BasicConnMgr, error) {
168+
) (host.Host, *dht.IpfsDHT, error) {
173169
var err error
174170

175-
connectionManager, err := connmgr.NewConnManager(
176-
160, // Lowwater
177-
192, // HighWater,
178-
connmgr.WithGracePeriod(time.Minute),
179-
)
180-
if err != nil {
181-
return nil, nil, nil, err
182-
}
171+
// NOTE:
172+
// Upon initialization, we are seeing log warnings:
173+
// "rcmgr limit conflicts with connmgr limit: conn manager high watermark limit: 192, exceeds the system connection limit of: 1"
174+
//
175+
// This was a bug in the check function, reading the wrong config value to check against:
176+
// https://github.com/libp2p/go-libp2p/issues/2628
183177

184178
options := []libp2p.Option{
185179
libp2p.Identity(&config.PrivKey.Key),
186180
libp2p.ListenAddrs(config.ListenAddrs...),
187-
libp2p.DefaultTransports,
188-
libp2p.DefaultSecurity,
189-
libp2p.ConnectionManager(connectionManager),
181+
// libp2p.DefaultTransports,
182+
// libp2p.DefaultSecurity,
183+
// libp2p.ConnectionManager(connectionManager),
190184
libp2p.ProtocolVersion(protocolVersion),
191185
}
192186

@@ -204,23 +198,23 @@ func createHost(
204198

205199
p2pHost, err := libp2p.New(options...)
206200
if err != nil {
207-
return nil, nil, nil, err
201+
return nil, nil, err
208202
}
209203

210204
if config.DisableRoutingDHT {
211-
return p2pHost, nil, connectionManager, err
205+
return p2pHost, nil, err
212206
}
213207

214208
opts := dhtRoutingOptions(config.Environment, config.BootstrapPeers...)
215209
idht, err := dht.New(ctx, p2pHost, opts...)
216210
if err != nil {
217-
return nil, nil, nil, err
211+
return nil, nil, err
218212
}
219213
// the wrapped host will try to query the routing table (dht)/
220214
// whenever it doesn't have the full routed address for a peer id
221215
routedHost := rhost.Wrap(p2pHost, idht)
222216

223-
return routedHost, idht, connectionManager, nil
217+
return routedHost, idht, nil
224218
}
225219

226220
func createPubSub(

0 commit comments

Comments
 (0)