2018-08-29 22:12:41 +08:00
|
|
|
package ds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-08-30 23:24:09 +08:00
|
|
|
"gx/ipfs/QmSpg1CvpXQQow5ernt1gNBXaXV6yxyNqi7XoeerWfzB5w/go-datastore"
|
|
|
|
|
2018-08-29 22:12:41 +08:00
|
|
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
2018-08-30 21:13:27 +08:00
|
|
|
"github.com/libp2p/go-libp2p-peerstore/mem"
|
2018-08-29 22:12:41 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
|
|
|
|
func NewPeerstore(ctx context.Context, ds datastore.Batching) (pstore.Peerstore, error) {
|
2018-08-30 23:43:40 +08:00
|
|
|
addrBook, err := NewAddrBook(ctx, ds, time.Second)
|
2018-08-29 22:12:41 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:43:40 +08:00
|
|
|
ps := pstore.NewPeerstoreWith(mem.NewKeyBook(), addrBook, mem.NewPeerMetadata())
|
2018-08-29 22:12:41 +08:00
|
|
|
return ps, nil
|
|
|
|
}
|