Skip to content

Commit

Permalink
Merge pull request #6629 from ipfs/feat/close-peerstore
Browse files Browse the repository at this point in the history
fix: close peerstore on stop
  • Loading branch information
Stebalien committed Sep 9, 2019
2 parents 3cbd163 + 9f1f958 commit 7555786
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
)
}

Expand All @@ -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),
)
Expand Down
20 changes: 20 additions & 0 deletions core/node/libp2p/peerstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
}

0 comments on commit 7555786

Please sign in to comment.