mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2024-12-28 23:50:12 +08:00
23 lines
556 B
Go
23 lines
556 B
Go
package pstoreds
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
|
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
|
)
|
|
|
|
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
|
|
func NewPeerstore(ctx context.Context, ds datastore.Batching) (pstore.Peerstore, error) {
|
|
addrBook, err := NewAddrBook(ctx, ds, time.Second)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ps := pstore.NewPeerstoreWith(pstoremem.NewKeyBook(), addrBook, pstoremem.NewPeerMetadata())
|
|
return ps, nil
|
|
}
|