go-libp2p-peerstore/pstoreds/peerstore.go

23 lines
556 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"
2018-09-05 01:07:44 +08:00
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
)
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
2018-09-01 01:35:23 +08:00
func NewPeerstore(ctx context.Context, ds datastore.TxnDatastore) (pstore.Peerstore, error) {
addrBook, err := NewAddrBook(ctx, ds, time.Second)
if err != nil {
return nil, err
}
ps := pstore.NewPeerstore(pstoremem.NewKeyBook(), addrBook, pstoremem.NewPeerMetadata())
return ps, nil
}