dep: switch to core (#80)

* dep: switch to core

Specifically, remove go-libp2p-{crypto,peer} deps.

* catch a few more usages of deprecated packages.
This commit is contained in:
Steven Allen 2019-05-31 06:51:16 -07:00 committed by Raúl Kripalani
parent aeb6adb266
commit 0b5b389640
28 changed files with 71 additions and 75 deletions

2
go.mod
View File

@ -9,8 +9,6 @@ require (
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-buffer-pool v0.0.1
github.com/libp2p/go-libp2p-core v0.0.1
github.com/libp2p/go-libp2p-crypto v0.1.0
github.com/libp2p/go-libp2p-peer v0.2.0
github.com/multiformats/go-base32 v0.0.3
github.com/multiformats/go-multiaddr v0.0.2
github.com/multiformats/go-multiaddr-net v0.0.1

4
go.sum
View File

@ -70,10 +70,6 @@ github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg
github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8=
github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I=
github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco=
github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ=
github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI=
github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY=
github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw=

View File

@ -4,8 +4,8 @@ import (
"sync"
"time"
moved "github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
core "github.com/libp2p/go-libp2p-core/peerstore"
)
// LatencyEWMASmooting governs the decay of the EWMA (the speed
@ -14,7 +14,7 @@ import (
var LatencyEWMASmoothing = 0.1
// Deprecated: use github.com/libp2p/go-libp2p-core/peerstore.Metrics instead.
type Metrics = moved.Metrics
type Metrics = core.Metrics
type metrics struct {
latmap map[peer.ID]time.Duration

View File

@ -7,14 +7,14 @@ import (
"testing"
"time"
"github.com/libp2p/go-libp2p-peer/test"
"github.com/libp2p/go-libp2p-core/test"
)
func TestLatencyEWMAFun(t *testing.T) {
t.Skip("run it for fun")
m := NewMetrics()
id, err := testutil.RandPeerID()
id, err := test.RandPeerID()
if err != nil {
t.Fatal(err)
}
@ -41,7 +41,7 @@ func TestLatencyEWMAFun(t *testing.T) {
func TestLatencyEWMA(t *testing.T) {
m := NewMetrics()
id, err := testutil.RandPeerID()
id, err := test.RandPeerID()
if err != nil {
t.Fatal(err)
}

View File

@ -4,8 +4,8 @@ import (
"encoding/json"
proto "github.com/gogo/protobuf/proto"
peer "github.com/libp2p/go-libp2p-peer"
pt "github.com/libp2p/go-libp2p-peer/test"
peer "github.com/libp2p/go-libp2p-core/peer"
pt "github.com/libp2p/go-libp2p-core/test"
ma "github.com/multiformats/go-multiaddr"
)

View File

@ -4,23 +4,24 @@ import (
"fmt"
"io"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var _ Peerstore = (*peerstore)(nil)
var _ pstore.Peerstore = (*peerstore)(nil)
type peerstore struct {
Metrics
pstore.Metrics
KeyBook
AddrBook
ProtoBook
PeerMetadata
pstore.KeyBook
pstore.AddrBook
pstore.ProtoBook
pstore.PeerMetadata
}
// NewPeerstore creates a data structure that stores peer data, backed by the
// supplied implementations of KeyBook, AddrBook and PeerMetadata.
func NewPeerstore(kb KeyBook, ab AddrBook, pb ProtoBook, md PeerMetadata) Peerstore {
func NewPeerstore(kb pstore.KeyBook, ab pstore.AddrBook, pb pstore.ProtoBook, md pstore.PeerMetadata) pstore.Peerstore {
return &peerstore{
KeyBook: kb,
AddrBook: ab,
@ -67,22 +68,22 @@ func (ps *peerstore) Peers() peer.IDSlice {
return pps
}
func (ps *peerstore) PeerInfo(p peer.ID) PeerInfo {
return PeerInfo{
func (ps *peerstore) PeerInfo(p peer.ID) peer.AddrInfo {
return peer.AddrInfo{
ID: p,
Addrs: ps.AddrBook.Addrs(p),
}
}
func PeerInfos(ps Peerstore, peers peer.IDSlice) []PeerInfo {
pi := make([]PeerInfo, len(peers))
func PeerInfos(ps pstore.Peerstore, peers peer.IDSlice) []peer.AddrInfo {
pi := make([]peer.AddrInfo, len(peers))
for i, p := range peers {
pi[i] = ps.PeerInfo(p)
}
return pi
}
func PeerInfoIDs(pis []PeerInfo) peer.IDSlice {
func PeerInfoIDs(pis []peer.AddrInfo) peer.IDSlice {
ps := make(peer.IDSlice, len(pis))
for i, pi := range pis {
ps[i] = pi.ID

View File

@ -11,8 +11,8 @@ import (
query "github.com/ipfs/go-datastore/query"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
pb "github.com/libp2p/go-libp2p-peerstore/pb"
pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem"

View File

@ -9,7 +9,7 @@ import (
ds "github.com/ipfs/go-datastore"
query "github.com/ipfs/go-datastore/query"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
pb "github.com/libp2p/go-libp2p-peerstore/pb"
b32 "github.com/multiformats/go-base32"

View File

@ -5,7 +5,7 @@ import (
"time"
query "github.com/ipfs/go-datastore/query"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
test "github.com/libp2p/go-libp2p-peerstore/test"
ma "github.com/multiformats/go-multiaddr"
)

View File

@ -11,7 +11,7 @@ import (
badger "github.com/ipfs/go-ds-badger"
leveldb "github.com/ipfs/go-ds-leveldb"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
pt "github.com/libp2p/go-libp2p-peerstore/test"
)

View File

@ -9,9 +9,9 @@ import (
ds "github.com/ipfs/go-datastore"
query "github.com/ipfs/go-datastore/query"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
ic "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
// Public and private keys are stored under the following db key pattern:

View File

@ -10,8 +10,8 @@ import (
ds "github.com/ipfs/go-datastore"
pool "github.com/libp2p/go-buffer-pool"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
// Metadata is stored under the following db key pattern:

View File

@ -9,7 +9,8 @@ import (
ds "github.com/ipfs/go-datastore"
query "github.com/ipfs/go-datastore/query"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
peerstore "github.com/libp2p/go-libp2p-core/peerstore"
pstore "github.com/libp2p/go-libp2p-peerstore"
)
@ -47,7 +48,7 @@ func DefaultOpts() Options {
}
// NewPeerstore creates a peerstore backed by the provided persistent datastore.
func NewPeerstore(ctx context.Context, store ds.Batching, opts Options) (pstore.Peerstore, error) {
func NewPeerstore(ctx context.Context, store ds.Batching, opts Options) (peerstore.Peerstore, error) {
addrBook, err := NewAddrBook(ctx, store, opts)
if err != nil {
return nil, err

View File

@ -4,9 +4,9 @@ import (
"fmt"
"sync"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
type protoSegment struct {

View File

@ -7,10 +7,10 @@ import (
"time"
logging "github.com/ipfs/go-log"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
addr "github.com/libp2p/go-libp2p-peerstore/addr"
)

View File

@ -3,7 +3,7 @@ package pstoremem
import (
"testing"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
pt "github.com/libp2p/go-libp2p-peerstore/test"
)

View File

@ -4,10 +4,10 @@ import (
"errors"
"sync"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
ic "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
type memoryKeyBook struct {

View File

@ -3,8 +3,8 @@ package pstoremem
import (
"sync"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var internKeys = map[string]bool{

View File

@ -3,9 +3,9 @@ package pstoremem
import (
"sync"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
type protoSegment struct {

View File

@ -5,7 +5,7 @@ import (
"math/big"
"sync"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
ks "github.com/whyrusleeping/go-keyspace"
)

View File

@ -1,6 +1,6 @@
package queue
import "github.com/libp2p/go-libp2p-peer"
import "github.com/libp2p/go-libp2p-core/peer"
// PeerQueue maintains a set of peers ordered according to a metric.
// Implementations of PeerQueue could order peers based on distances along

View File

@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
mh "github.com/multiformats/go-multihash"
)

View File

@ -4,7 +4,7 @@ import (
"context"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/peer"
)
var log = logging.Logger("peerqueue")

View File

@ -4,7 +4,7 @@ import (
"testing"
"time"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var addressBookSuite = map[string]func(book pstore.AddrBook) func(*testing.T){

View File

@ -6,7 +6,7 @@ import (
"sort"
"testing"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var peerstoreBenchmarks = map[string]func(pstore.Peerstore, chan *peerpair) func(*testing.B){

View File

@ -4,11 +4,11 @@ import (
"sort"
"testing"
ic "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
pt "github.com/libp2p/go-libp2p-peer/test"
ic "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
pt "github.com/libp2p/go-libp2p-core/test"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var keyBookSuite = map[string]func(kb pstore.KeyBook) func(*testing.T){
@ -41,7 +41,7 @@ func testKeybookPrivKey(kb pstore.KeyBook) func(t *testing.T) {
t.Error("expected peers to be empty on init")
}
priv, _, err := pt.RandTestKeyPair(512)
priv, _, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
t.Error(err)
}
@ -76,7 +76,7 @@ func testKeyBookPubKey(kb pstore.KeyBook) func(t *testing.T) {
t.Error("expected peers to be empty on init")
}
_, pub, err := pt.RandTestKeyPair(512)
_, pub, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
t.Error(err)
}
@ -114,12 +114,12 @@ func testKeyBookPeers(kb pstore.KeyBook) func(t *testing.T) {
var peers peer.IDSlice
for i := 0; i < 10; i++ {
// Add a public key.
_, pub, _ := pt.RandTestKeyPair(512)
_, pub, _ := pt.RandTestKeyPair(ic.RSA, 512)
p1, _ := peer.IDFromPublicKey(pub)
kb.AddPubKey(p1, pub)
// Add a private key.
priv, _, _ := pt.RandTestKeyPair(512)
priv, _, _ := pt.RandTestKeyPair(ic.RSA, 512)
p2, _ := peer.IDFromPrivateKey(priv)
kb.AddPrivKey(p2, priv)
@ -192,7 +192,7 @@ func BenchmarkKeyBook(b *testing.B, factory KeyBookFactory) {
func benchmarkPubKey(kb pstore.KeyBook) func(*testing.B) {
return func(b *testing.B) {
_, pub, err := pt.RandTestKeyPair(512)
_, pub, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
b.Error(err)
}
@ -216,7 +216,7 @@ func benchmarkPubKey(kb pstore.KeyBook) func(*testing.B) {
func benchmarkAddPubKey(kb pstore.KeyBook) func(*testing.B) {
return func(b *testing.B) {
_, pub, err := pt.RandTestKeyPair(512)
_, pub, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
b.Error(err)
}
@ -235,7 +235,7 @@ func benchmarkAddPubKey(kb pstore.KeyBook) func(*testing.B) {
func benchmarkPrivKey(kb pstore.KeyBook) func(*testing.B) {
return func(b *testing.B) {
priv, _, err := pt.RandTestKeyPair(512)
priv, _, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
b.Error(err)
}
@ -259,7 +259,7 @@ func benchmarkPrivKey(kb pstore.KeyBook) func(*testing.B) {
func benchmarkAddPrivKey(kb pstore.KeyBook) func(*testing.B) {
return func(b *testing.B) {
priv, _, err := pt.RandTestKeyPair(512)
priv, _, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
b.Error(err)
}
@ -279,7 +279,7 @@ func benchmarkAddPrivKey(kb pstore.KeyBook) func(*testing.B) {
func benchmarkPeersWithKeys(kb pstore.KeyBook) func(*testing.B) {
return func(b *testing.B) {
for i := 0; i < 10; i++ {
priv, pub, err := pt.RandTestKeyPair(512)
priv, pub, err := pt.RandTestKeyPair(ic.RSA, 512)
if err != nil {
b.Error(err)
}

View File

@ -8,11 +8,11 @@ import (
"testing"
"time"
crypto "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p-core/peerstore"
)
var peerstoreSuite = map[string]func(pstore.Peerstore) func(*testing.T){

View File

@ -5,8 +5,8 @@ import (
"fmt"
"testing"
peer "github.com/libp2p/go-libp2p-peer"
pt "github.com/libp2p/go-libp2p-peer/test"
peer "github.com/libp2p/go-libp2p-core/peer"
pt "github.com/libp2p/go-libp2p-core/test"
ma "github.com/multiformats/go-multiaddr"
)