[node] every node uses persistent DHT storage

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1450/head
Leo Chen 5 years ago
parent 80b325fa1a
commit b765b8ba4b
  1. 1
      .gitignore
  2. 5
      api/service/networkinfo/service.go

1
.gitignore vendored

@ -78,3 +78,4 @@ db-127.0.0.1-*
# dht storage
.dht
.dht-*

@ -13,6 +13,7 @@ import (
msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
badger "github.com/ipfs/go-ds-badger"
libp2pdis "github.com/libp2p/go-libp2p-discovery"
libp2pdht "github.com/libp2p/go-libp2p-kad-dht"
peerstore "github.com/libp2p/go-libp2p-peerstore"
@ -56,11 +57,13 @@ const (
func New(h p2p.Host, rendezvous p2p.GroupID, peerChan chan p2p.Peer, bootnodes utils.AddrList) *Service {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), connectionTimeout)
dht, err := libp2pdht.New(ctx, h.GetP2PHost())
dataStore, err := badger.NewDatastore(fmt.Sprintf(".dht-%s-%s", h.GetSelfPeer().IP, h.GetSelfPeer().Port), nil)
if err != nil {
panic(err)
}
dht := libp2pdht.NewDHT(ctx, h.GetP2PHost(), dataStore)
return &Service{
Host: h,
dht: dht,

Loading…
Cancel
Save