Unverified 提交 7555786e 作者: Steven Allen 提交者: GitHub

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

fix: close peerstore on stop
......@@ -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 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论