Skip to content

Commit

Permalink
dep: switch to core (#80)
Browse files Browse the repository at this point in the history
* dep: switch to core

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

* catch a few more usages of deprecated packages.
  • Loading branch information
Stebalien authored and raulk committed May 31, 2019
1 parent fd88712 commit 73b10b9
Show file tree
Hide file tree
Showing 26 changed files with 71 additions and 69 deletions.
6 changes: 3 additions & 3 deletions p2p/host/peerstore/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions p2p/host/peerstore/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pb/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
27 changes: 14 additions & 13 deletions p2p/host/peerstore/peerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoreds/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/addr_book_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/addr_book_gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions p2p/host/peerstore/pstoreds/keybook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoreds/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions p2p/host/peerstore/pstoreds/peerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoreds/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoremem/inmem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions p2p/host/peerstore/pstoremem/keybook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoremem/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/peerstore/pstoremem/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/queue/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/queue/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/queue/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/test/addr_book_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/test/benchmarks_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Loading

0 comments on commit 73b10b9

Please sign in to comment.