master
go 24 lines 504 Bytes
Raw
1 package libp2p
2
3 import (
4 "context"
5
6 "github.com/ipfs/kubo/core/shutdown"
7 "github.com/libp2p/go-libp2p/core/peerstore"
8 "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"
9 "go.uber.org/fx"
10 )
11
12 func Peerstore(lc fx.Lifecycle) (peerstore.Peerstore, error) {
13 pstore, err := pstoremem.NewPeerstore()
14 if err != nil {
15 return nil, err
16 }
17 lc.Append(fx.Hook{
18 OnStop: func(ctx context.Context) error {
19 return shutdown.CloseWithCtx(ctx, "peerstore", pstore.Close)
20 },
21 })
22
23 return pstore, nil
24 }