[netinfo] limit the number of discovery

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1466/head
Leo Chen 5 years ago
parent 8eeaf1c6c2
commit 83726b2e1d
  1. 5
      api/service/networkinfo/service.go
  2. 1
      go.mod

@ -14,6 +14,7 @@ import (
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
badger "github.com/ipfs/go-ds-badger"
coredis "github.com/libp2p/go-libp2p-core/discovery"
libp2pdis "github.com/libp2p/go-libp2p-discovery"
libp2pdht "github.com/libp2p/go-libp2p-kad-dht"
peerstore "github.com/libp2p/go-libp2p-peerstore"
@ -51,6 +52,8 @@ const (
// register to bootnode every ticker
dhtTicker = 6 * time.Hour
discoveryLimit = 32
)
// New returns role conversion service.
@ -165,7 +168,7 @@ func (s *Service) DoService() {
utils.Logger().Info().Str("Rendezvous", string(s.Rendezvous)).Msg("Successfully announced!")
default:
var err error
s.peerInfo, err = s.discovery.FindPeers(ctx, string(s.Rendezvous))
s.peerInfo, err = s.discovery.FindPeers(ctx, string(s.Rendezvous), coredis.Limit(discoveryLimit))
if err != nil {
utils.Logger().Error().Err(err).Msg("FindPeers")
return

@ -30,6 +30,7 @@ require (
github.com/karalabe/hid v1.0.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/libp2p/go-libp2p v0.3.1
github.com/libp2p/go-libp2p-core v0.2.2
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/libp2p/go-libp2p-discovery v0.1.0
github.com/libp2p/go-libp2p-host v0.1.0

Loading…
Cancel
Save