mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-27 13:30:11 +08:00
Merge branch 'master' into txndatastore
This commit is contained in:
commit
1b410c7294
@ -1 +1 @@
|
||||
1.5.0: QmXkA9vNhpuTjHRedDioHj39oBEtt72JfEtQFPECUxHXx4
|
||||
2.0.0: Qmda4cPRvSRyox3SqgJN6DfSZGU5TtHufPTp9uXjFj71X6
|
||||
|
@ -2,13 +2,12 @@ package peerstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
ic "github.com/libp2p/go-libp2p-crypto"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
|
@ -77,6 +77,6 @@
|
||||
"license": "MIT",
|
||||
"name": "go-libp2p-peerstore",
|
||||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "1.5.0"
|
||||
"version": "2.0.0"
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
)
|
||||
|
||||
var _ Peerstore = (*peerstore)(nil)
|
||||
|
@ -5,16 +5,16 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/golang-lru"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
"github.com/ipfs/go-datastore/query"
|
||||
query "github.com/ipfs/go-datastore/query"
|
||||
logging "github.com/ipfs/go-log"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
|
||||
bd "github.com/dgraph-io/badger"
|
||||
|
||||
"github.com/ipfs/go-datastore"
|
||||
"github.com/ipfs/go-ds-badger"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
badger "github.com/ipfs/go-ds-badger"
|
||||
|
||||
"github.com/libp2p/go-libp2p-peerstore"
|
||||
"github.com/libp2p/go-libp2p-peerstore/test"
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
pt "github.com/libp2p/go-libp2p-peerstore/test"
|
||||
)
|
||||
|
||||
func BenchmarkBaselineBadgerDatastorePutEntry(b *testing.B) {
|
||||
@ -25,7 +25,7 @@ func BenchmarkBaselineBadgerDatastorePutEntry(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
txn := bds.NewTransaction(false)
|
||||
|
||||
key := datastore.RawKey(fmt.Sprintf("/key/%d", i))
|
||||
key := ds.RawKey(fmt.Sprintf("/key/%d", i))
|
||||
txn.Put(key, []byte(fmt.Sprintf("/value/%d", i)))
|
||||
|
||||
txn.Commit()
|
||||
@ -38,9 +38,9 @@ func BenchmarkBaselineBadgerDatastoreGetEntry(b *testing.B) {
|
||||
defer closer()
|
||||
|
||||
txn := bds.NewTransaction(false)
|
||||
keys := make([]datastore.Key, 1000)
|
||||
keys := make([]ds.Key, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
key := datastore.RawKey(fmt.Sprintf("/key/%d", i))
|
||||
key := ds.RawKey(fmt.Sprintf("/key/%d", i))
|
||||
txn.Put(key, []byte(fmt.Sprintf("/value/%d", i)))
|
||||
keys[i] = key
|
||||
}
|
||||
@ -118,14 +118,14 @@ func BenchmarkBaselineBadgerDirectGetEntry(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestBadgerDsPeerstore(t *testing.T) {
|
||||
test.TestPeerstore(t, peerstoreFactory(t, DefaultOpts()))
|
||||
pt.TestPeerstore(t, peerstoreFactory(t, DefaultOpts()))
|
||||
}
|
||||
|
||||
func TestBadgerDsAddrBook(t *testing.T) {
|
||||
opts := DefaultOpts()
|
||||
opts.TTLInterval = 100 * time.Microsecond
|
||||
|
||||
test.TestAddrBook(t, addressBookFactory(t, opts))
|
||||
pt.TestAddrBook(t, addressBookFactory(t, opts))
|
||||
}
|
||||
|
||||
func BenchmarkBadgerDsPeerstore(b *testing.B) {
|
||||
@ -135,11 +135,11 @@ func BenchmarkBadgerDsPeerstore(b *testing.B) {
|
||||
cacheless := DefaultOpts()
|
||||
cacheless.CacheSize = 0
|
||||
|
||||
test.BenchmarkPeerstore(b, peerstoreFactory(b, caching), "Caching")
|
||||
test.BenchmarkPeerstore(b, peerstoreFactory(b, cacheless), "Cacheless")
|
||||
pt.BenchmarkPeerstore(b, peerstoreFactory(b, caching), "Caching")
|
||||
pt.BenchmarkPeerstore(b, peerstoreFactory(b, cacheless), "Cacheless")
|
||||
}
|
||||
|
||||
func badgerStore(t testing.TB) (datastore.TxnDatastore, func()) {
|
||||
func badgerStore(t testing.TB) (ds.TxnDatastore, func()) {
|
||||
dataPath, err := ioutil.TempDir(os.TempDir(), "badger")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -155,8 +155,8 @@ func badgerStore(t testing.TB) (datastore.TxnDatastore, func()) {
|
||||
return ds, closer
|
||||
}
|
||||
|
||||
func peerstoreFactory(tb testing.TB, opts PeerstoreOpts) test.PeerstoreFactory {
|
||||
return func() (peerstore.Peerstore, func()) {
|
||||
func peerstoreFactory(tb testing.TB, opts PeerstoreOpts) pt.PeerstoreFactory {
|
||||
return func() (pstore.Peerstore, func()) {
|
||||
ds, closeFunc := badgerStore(tb)
|
||||
|
||||
ps, err := NewPeerstore(context.Background(), ds, opts)
|
||||
@ -168,8 +168,8 @@ func peerstoreFactory(tb testing.TB, opts PeerstoreOpts) test.PeerstoreFactory {
|
||||
}
|
||||
}
|
||||
|
||||
func addressBookFactory(tb testing.TB, opts PeerstoreOpts) test.AddrBookFactory {
|
||||
return func() (peerstore.AddrBook, func()) {
|
||||
func addressBookFactory(tb testing.TB, opts PeerstoreOpts) pt.AddrBookFactory {
|
||||
return func() (pstore.AddrBook, func()) {
|
||||
ds, closeDB := badgerStore(tb)
|
||||
|
||||
mgr, err := NewAddrBook(context.Background(), ds, opts)
|
||||
|
@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/ipfs/go-datastore"
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||
)
|
||||
|
||||
// Configuration object for the peerstore.
|
||||
@ -35,8 +35,8 @@ func DefaultOpts() PeerstoreOpts {
|
||||
}
|
||||
|
||||
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
|
||||
func NewPeerstore(ctx context.Context, ds datastore.TxnDatastore, opts PeerstoreOpts) (pstore.Peerstore, error) {
|
||||
addrBook, err := NewAddrBook(ctx, ds, opts)
|
||||
func NewPeerstore(ctx context.Context, store ds.TxnDatastore, opts PeerstoreOpts) (pstore.Peerstore, error) {
|
||||
addrBook, err := NewAddrBook(ctx, store, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ import (
|
||||
"time"
|
||||
|
||||
logging "github.com/ipfs/go-log"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
"github.com/libp2p/go-libp2p-peerstore/addr"
|
||||
addr "github.com/libp2p/go-libp2p-peerstore/addr"
|
||||
)
|
||||
|
||||
var log = logging.Logger("peerstore")
|
||||
|
@ -4,29 +4,29 @@ import (
|
||||
"testing"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
"github.com/libp2p/go-libp2p-peerstore/test"
|
||||
pt "github.com/libp2p/go-libp2p-peerstore/test"
|
||||
)
|
||||
|
||||
func TestInMemoryPeerstore(t *testing.T) {
|
||||
test.TestPeerstore(t, func() (pstore.Peerstore, func()) {
|
||||
pt.TestPeerstore(t, func() (pstore.Peerstore, func()) {
|
||||
return NewPeerstore(), nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestInMemoryAddrBook(t *testing.T) {
|
||||
test.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
||||
pt.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
||||
return NewAddrBook(), nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestInMemoryKeyBook(t *testing.T) {
|
||||
test.TestKeyBook(t, func() (pstore.KeyBook, func()) {
|
||||
pt.TestKeyBook(t, func() (pstore.KeyBook, func()) {
|
||||
return NewKeyBook(), nil
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkInMemoryPeerstore(b *testing.B) {
|
||||
test.BenchmarkPeerstore(b, func() (pstore.Peerstore, func()) {
|
||||
pt.BenchmarkPeerstore(b, func() (pstore.Peerstore, func()) {
|
||||
return NewPeerstore(), nil
|
||||
}, "InMem")
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
ic "github.com/libp2p/go-libp2p-crypto"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
)
|
||||
|
@ -3,8 +3,7 @@ package pstoremem
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
pt "github.com/libp2p/go-libp2p-peer/test"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p-crypto"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
crypto "github.com/libp2p/go-libp2p-crypto"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||
|
Loading…
Reference in New Issue
Block a user