Skip to content

Commit

Permalink
fix: close peerstore on stop
Browse files Browse the repository at this point in the history
fixes #6627
  • Loading branch information
Stebalien committed Sep 6, 2019
1 parent 06153e0 commit 40f6ecf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,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 +173,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 40f6ecf

Please sign in to comment.