Unverified Commit 7555786e authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #6629 from ipfs/feat/close-peerstore

fix: close peerstore on stop
parents 3cbd1633 9f1f9584
......@@ -10,7 +10,6 @@ import (
"github.com/ipfs/go-ipfs-config"
util "github.com/ipfs/go-ipfs-util"
peer "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/ipfs/go-ipfs/core/node/libp2p"
......@@ -161,7 +160,7 @@ func Identity(cfg *config.Config) fx.Option {
if cfg.Identity.PrivKey == "" {
return fx.Options( // No PK (usually in tests)
fx.Provide(PeerID(id)),
fx.Provide(pstoremem.NewPeerstore),
fx.Provide(libp2p.Peerstore),
)
}
......@@ -173,7 +172,7 @@ func Identity(cfg *config.Config) fx.Option {
return fx.Options( // Full identity
fx.Provide(PeerID(id)),
fx.Provide(PrivateKey(sk)),
fx.Provide(pstoremem.NewPeerstore),
fx.Provide(libp2p.Peerstore),
fx.Invoke(libp2p.PstoreAddSelfKeys),
)
......
package libp2p
import (
"context"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
"go.uber.org/fx"
)
func Peerstore(lc fx.Lifecycle) peerstore.Peerstore {
pstore := pstoremem.NewPeerstore()
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return pstore.Close()
},
})
return pstore
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment