go-libp2p-peerstore/pstoreds/peerstore.go
2018-09-04 18:07:44 +01:00

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
}