Skip to content

Commit

Permalink
PR: Switch to mem peer store
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Sep 25, 2023
1 parent 153232b commit 38a3a65
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions net/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/ipfs/boxo/ipns"
ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
libp2p "github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
dualdht "github.com/libp2p/go-libp2p-kad-dht/dual"
Expand All @@ -39,7 +38,7 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"
"github.com/multiformats/go-multiaddr"
"github.com/textileio/go-libp2p-pubsub-rpc/finalizer"

Expand Down Expand Up @@ -82,15 +81,13 @@ func NewNode(

fin := finalizer.NewFinalizer()

// create our peerstore from the underlying defra rootstore
// prefixed with "p2p"
rootstore := db.Root()
pstore := namespace.Wrap(rootstore, ds.NewKey("/db"))
peerstore, err := pstoreds.NewPeerstore(ctx, pstore, pstoreds.DefaultOpts())
memPeerStore, err := pstoremem.NewPeerstore()
if err != nil {
return nil, fin.Cleanup(err)
}
fin.Add(peerstore)

fin.Add(memPeerStore)

hostKey, err := getHostKey(options.DataPath)
if err != nil {
Expand All @@ -104,7 +101,7 @@ func NewNode(
libp2p.DefaultTransports,
libp2p.Identity(hostKey),
libp2p.ListenAddrs(options.ListenAddrs...),
libp2p.Peerstore(peerstore),
libp2p.Peerstore(memPeerStore),
libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
// Delete this line and uncomment the next 6 lines once we remove batchable datastore support.
// var store ds.Batching
Expand Down

0 comments on commit 38a3a65

Please sign in to comment.