mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2024-12-28 23:50:12 +08:00
normalise import aliases.
This commit is contained in:
parent
08de02b668
commit
1c25f160a1
@ -2,13 +2,12 @@ package peerstore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
ic "github.com/libp2p/go-libp2p-crypto"
|
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"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Peerstore = (*peerstore)(nil)
|
var _ Peerstore = (*peerstore)(nil)
|
||||||
|
@ -5,16 +5,16 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
ds "github.com/ipfs/go-datastore"
|
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"
|
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"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
mh "github.com/multiformats/go-multihash"
|
mh "github.com/multiformats/go-multihash"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("peerstore/ds")
|
var log = logging.Logger("peerstore/ds")
|
||||||
|
@ -7,14 +7,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-datastore"
|
ds "github.com/ipfs/go-datastore"
|
||||||
"github.com/ipfs/go-ds-badger"
|
"github.com/ipfs/go-ds-badger"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
"github.com/libp2p/go-libp2p-peerstore/test"
|
pt "github.com/libp2p/go-libp2p-peerstore/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupBadgerDatastore(t testing.TB) (datastore.Batching, func()) {
|
func setupBadgerDatastore(t testing.TB) (ds.Batching, func()) {
|
||||||
dataPath, err := ioutil.TempDir(os.TempDir(), "badger")
|
dataPath, err := ioutil.TempDir(os.TempDir(), "badger")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -30,8 +30,8 @@ func setupBadgerDatastore(t testing.TB) (datastore.Batching, func()) {
|
|||||||
return ds, closer
|
return ds, closer
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeerstoreFactory(tb testing.TB) test.PeerstoreFactory {
|
func newPeerstoreFactory(tb testing.TB) pt.PeerstoreFactory {
|
||||||
return func() (peerstore.Peerstore, func()) {
|
return func() (pstore.Peerstore, func()) {
|
||||||
ds, closeFunc := setupBadgerDatastore(tb)
|
ds, closeFunc := setupBadgerDatastore(tb)
|
||||||
|
|
||||||
ps, err := NewPeerstore(context.Background(), ds)
|
ps, err := NewPeerstore(context.Background(), ds)
|
||||||
@ -44,11 +44,11 @@ func newPeerstoreFactory(tb testing.TB) test.PeerstoreFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBadgerDsPeerstore(t *testing.T) {
|
func TestBadgerDsPeerstore(t *testing.T) {
|
||||||
test.TestPeerstore(t, newPeerstoreFactory(t))
|
pt.TestPeerstore(t, newPeerstoreFactory(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadgerDsAddrBook(t *testing.T) {
|
func TestBadgerDsAddrBook(t *testing.T) {
|
||||||
test.TestAddrBook(t, func() (peerstore.AddrBook, func()) {
|
pt.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
||||||
ds, closeDB := setupBadgerDatastore(t)
|
ds, closeDB := setupBadgerDatastore(t)
|
||||||
|
|
||||||
mgr, err := NewAddrBook(context.Background(), ds, 100*time.Microsecond)
|
mgr, err := NewAddrBook(context.Background(), ds, 100*time.Microsecond)
|
||||||
@ -65,5 +65,5 @@ func TestBadgerDsAddrBook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBadgerDsPeerstore(b *testing.B) {
|
func BenchmarkBadgerDsPeerstore(b *testing.B) {
|
||||||
test.BenchmarkPeerstore(b, newPeerstoreFactory(b))
|
pt.BenchmarkPeerstore(b, newPeerstoreFactory(b))
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-datastore"
|
ds "github.com/ipfs/go-datastore"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
|
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
|
||||||
func NewPeerstore(ctx context.Context, ds datastore.Batching) (pstore.Peerstore, error) {
|
func NewPeerstore(ctx context.Context, ds ds.Batching) (pstore.Peerstore, error) {
|
||||||
addrBook, err := NewAddrBook(ctx, ds, time.Second)
|
addrBook, err := NewAddrBook(ctx, ds, time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -7,11 +7,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log"
|
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"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
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")
|
var log = logging.Logger("peerstore")
|
||||||
|
@ -4,29 +4,29 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
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) {
|
func TestInMemoryPeerstore(t *testing.T) {
|
||||||
test.TestPeerstore(t, func() (pstore.Peerstore, func()) {
|
pt.TestPeerstore(t, func() (pstore.Peerstore, func()) {
|
||||||
return NewPeerstore(), nil
|
return NewPeerstore(), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInMemoryAddrBook(t *testing.T) {
|
func TestInMemoryAddrBook(t *testing.T) {
|
||||||
test.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
pt.TestAddrBook(t, func() (pstore.AddrBook, func()) {
|
||||||
return NewAddrBook(), nil
|
return NewAddrBook(), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInMemoryKeyBook(t *testing.T) {
|
func TestInMemoryKeyBook(t *testing.T) {
|
||||||
test.TestKeyBook(t, func() (pstore.KeyBook, func()) {
|
pt.TestKeyBook(t, func() (pstore.KeyBook, func()) {
|
||||||
return NewKeyBook(), nil
|
return NewKeyBook(), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkInMemoryPeerstore(b *testing.B) {
|
func BenchmarkInMemoryPeerstore(b *testing.B) {
|
||||||
test.BenchmarkPeerstore(b, func() (pstore.Peerstore, func()) {
|
pt.BenchmarkPeerstore(b, func() (pstore.Peerstore, func()) {
|
||||||
return NewPeerstore(), nil
|
return NewPeerstore(), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
ic "github.com/libp2p/go-libp2p-crypto"
|
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"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
)
|
)
|
||||||
|
@ -3,8 +3,7 @@ package pstoremem
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
pt "github.com/libp2p/go-libp2p-peer/test"
|
pt "github.com/libp2p/go-libp2p-peer/test"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-crypto"
|
crypto "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"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
|
|
||||||
pstore "github.com/libp2p/go-libp2p-peerstore"
|
pstore "github.com/libp2p/go-libp2p-peerstore"
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
pt "github.com/libp2p/go-libp2p-peer/test"
|
pt "github.com/libp2p/go-libp2p-peer/test"
|
||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
)
|
)
|
||||||
@ -42,3 +42,11 @@ func addressProducer(ctx context.Context, b *testing.B, addrs chan *peerpair) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func multiaddr(m string) ma.Multiaddr {
|
||||||
|
maddr, err := ma.NewMultiaddr(m)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return maddr
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user