go-libp2p-peerstore/pstoreds/peerstore.go

23 lines
538 B
Go
Raw Normal View History

2018-09-02 19:03:02 +08:00
package pstoreds
import (
"context"
"time"
2018-09-02 19:10:55 +08:00
"github.com/ipfs/go-datastore"
2018-08-30 23:24:09 +08:00
pstore "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-peerstore/mem"
)
// 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(mem.NewKeyBook(), addrBook, mem.NewPeerMetadata())
return ps, nil
}