@cryptotaxi247 / kubo / commits / 9f1f95843

fix: close peerstore on stop

fixes #6627

Steven Allen committed Sep 5, 2019 at 17:13 UTC 9f1f9584321ab210ca2c7dba427786a8367e716f
2 files changed +22 -3
core/node/groups.go
+2 -3
@@ -10,7 +10,6 @@ import (
10 "github.com/ipfs/go-ipfs-config"
11 util "github.com/ipfs/go-ipfs-util"
12 peer "github.com/libp2p/go-libp2p-core/peer"
13 - "github.com/libp2p/go-libp2p-peerstore/pstoremem"
13 pubsub "github.com/libp2p/go-libp2p-pubsub"
14
15 "github.com/ipfs/go-ipfs/core/node/libp2p"
@@ -161,7 +160,7 @@ func Identity(cfg *config.Config) fx.Option {
160 if cfg.Identity.PrivKey == "" {
161 return fx.Options( // No PK (usually in tests)
162 fx.Provide(PeerID(id)),
164 - fx.Provide(pstoremem.NewPeerstore),
163 + fx.Provide(libp2p.Peerstore),
164 )
165 }
166
@@ -173,7 +172,7 @@ func Identity(cfg *config.Config) fx.Option {
172 return fx.Options( // Full identity
173 fx.Provide(PeerID(id)),
174 fx.Provide(PrivateKey(sk)),
176 - fx.Provide(pstoremem.NewPeerstore),
175 + fx.Provide(libp2p.Peerstore),
176
177 fx.Invoke(libp2p.PstoreAddSelfKeys),
178 )
core/node/libp2p/peerstore.go new
+20
@@ -0,0 +1,20 @@
1 +package libp2p
2 +
3 +import (
4 + "context"
5 +
6 + "github.com/libp2p/go-libp2p-core/peerstore"
7 + "github.com/libp2p/go-libp2p-peerstore/pstoremem"
8 + "go.uber.org/fx"
9 +)
10 +
11 +func Peerstore(lc fx.Lifecycle) peerstore.Peerstore {
12 + pstore := pstoremem.NewPeerstore()
13 + lc.Append(fx.Hook{
14 + OnStop: func(ctx context.Context) error {
15 + return pstore.Close()
16 + },
17 + })
18 +
19 + return pstore
20 +}