Skip to content

Commit

Permalink
deprecate go-libp2p-core and use go-libp2p instead (#109)
Browse files Browse the repository at this point in the history

Co-authored-by: ShengTao <[email protected]>
  • Loading branch information
nisainan and ShengTao authored Sep 1, 2022
1 parent c4260ac commit 03c1432
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 236 deletions.
2 changes: 1 addition & 1 deletion bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"container/list"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)

// PeerInfo holds all related information for a peer in the K-Bucket.
Expand Down
2 changes: 1 addition & 1 deletion bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p/core/test"

"github.com/stretchr/testify/require"
)
Expand Down
6 changes: 4 additions & 2 deletions generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
}

printf := func(s string, args ...interface{}) {
_, err := fmt.Fprintf(f, s, args...)
_, err = fmt.Fprintf(f, s, args...)
if err != nil {
panic(err)
}
Expand All @@ -66,5 +66,7 @@ func main() {
printf("%d,", j)
}
printf("\n}")
f.Close()
if err = f.Close(); err != nil {
panic(err)
}
}
53 changes: 29 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
module github.com/libp2p/go-libp2p-kbucket

go 1.18

require (
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-log v1.0.4
github.com/libp2p/go-cidranger v1.1.0
github.com/libp2p/go-libp2p-asn-util v0.0.0-20200825225859-85005c6cf052
github.com/libp2p/go-libp2p-core v0.6.1
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/minio/sha256-simd v0.1.1
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multihash v0.0.14
github.com/stretchr/testify v1.5.1
github.com/libp2p/go-libp2p v0.22.0
github.com/libp2p/go-libp2p-asn-util v0.2.0
github.com/minio/sha256-simd v1.0.0
github.com/multiformats/go-multiaddr v0.6.0
github.com/multiformats/go-multihash v0.2.1
github.com/stretchr/testify v1.8.0
)

require (
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/ipfs/go-cid v0.0.7 // indirect
github.com/ipfs/go-log/v2 v2.0.5 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/libp2p/go-openssl v0.0.7 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/ipfs/go-cid v0.2.0 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-openssl v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.0.3 // indirect
github.com/multiformats/go-base32 v0.0.4 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.0.3 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.14.1 // indirect
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)

go 1.18
278 changes: 97 additions & 181 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions peerdiversity/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"sync"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/libp2p/go-cidranger"
asnutil "github.com/libp2p/go-libp2p-asn-util"
Expand Down Expand Up @@ -153,7 +153,7 @@ func (f *Filter) TryAdd(p peer.ID) bool {
// don't allow peers for which we can't determine addresses.
addrs := f.pgm.PeerAddresses(p)
if len(addrs) == 0 {
dfLog.Debugw("no addresses found for peer", "appKey", f.logKey, "peer", p.Pretty())
dfLog.Debugw("no addresses found for peer", "appKey", f.logKey, "peer", p)
return false
}

Expand Down
4 changes: 2 additions & 2 deletions peerdiversity/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"testing"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"

ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -227,7 +227,7 @@ type mockAsnStore struct {
reply string
}

func (m *mockAsnStore) AsnForIPv6(ip net.IP) (string, error) {
func (m *mockAsnStore) AsnForIPv6(net.IP) (string, error) {
return m.reply, nil
}

Expand Down
4 changes: 2 additions & 2 deletions sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"container/list"
"sort"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)

// A helper struct to sort peers by their distance to the local node
Expand Down Expand Up @@ -46,7 +46,7 @@ func (pds *peerDistanceSorter) sort() {
sort.Sort(pds)
}

// Sort the given peers by their ascending distance from the target. A new slice is returned.
// SortClosestPeers Sort the given peers by their ascending distance from the target. A new slice is returned.
func SortClosestPeers(peers []peer.ID, target ID) []peer.ID {
sorter := peerDistanceSorter{
peers: make([]peerDistance, 0, len(peers)),
Expand Down
20 changes: 10 additions & 10 deletions table.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package kbucket implements a kademlia 'k-bucket' routing table.
// Package kbucket implements a kademlia 'k-bucket' routing table.
package kbucket

import (
Expand All @@ -8,8 +8,8 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"

"github.com/libp2p/go-libp2p-kbucket/peerdiversity"

Expand Down Expand Up @@ -92,7 +92,7 @@ func (rt *RoutingTable) Close() error {
return nil
}

// NPeersForCPL returns the number of peers we have for a given Cpl
// NPeersForCpl returns the number of peers we have for a given Cpl
func (rt *RoutingTable) NPeersForCpl(cpl uint) int {
rt.tabLock.RLock()
defer rt.tabLock.RUnlock()
Expand Down Expand Up @@ -127,7 +127,7 @@ func (rt *RoutingTable) NPeersForCpl(cpl uint) int {
// whose LastSuccessfulOutboundQuery is above the maximum allowed threshold in that bucket with the new peer.
// If no such peer exists in that bucket, we do NOT add the peer to the Routing Table and return error "ErrPeerRejectedNoCapacity".

// It returns a boolean value set to true if the peer was newly added to the Routing Table, false otherwise.
// TryAddPeer returns a boolean value set to true if the peer was newly added to the Routing Table, false otherwise.
// It also returns any error that occurred while adding the peer to the Routing Table. If the error is not nil,
// the boolean value will ALWAYS be false i.e. the peer wont be added to the Routing Table it it's not already there.
//
Expand All @@ -151,11 +151,11 @@ func (rt *RoutingTable) addPeer(p peer.ID, queryPeer bool, isReplaceable bool) (
}

// peer already exists in the Routing Table.
if peer := bucket.getPeer(p); peer != nil {
if peerInfo := bucket.getPeer(p); peerInfo != nil {
// if we're querying the peer first time after adding it, let's give it a
// usefulness bump. This will ONLY happen once.
if peer.LastUsefulAt.IsZero() && queryPeer {
peer.LastUsefulAt = lastUsefulAt
if peerInfo.LastUsefulAt.IsZero() && queryPeer {
peerInfo.LastUsefulAt = lastUsefulAt
}
return false, nil
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (rt *RoutingTable) GetPeerInfos() []PeerInfo {
return pis
}

// UpdateLastSuccessfulOutboundQuery updates the LastSuccessfulOutboundQueryAt time of the peer.
// UpdateLastSuccessfulOutboundQueryAt updates the LastSuccessfulOutboundQueryAt time of the peer.
// Returns true if the update was successful, false otherwise.
func (rt *RoutingTable) UpdateLastSuccessfulOutboundQueryAt(p peer.ID, t time.Time) bool {
rt.tabLock.Lock()
Expand Down Expand Up @@ -475,7 +475,7 @@ func (rt *RoutingTable) Print() {

for e := b.list.Front(); e != nil; e = e.Next() {
p := e.Value.(*PeerInfo).Id
fmt.Printf("\t\t- %s %s\n", p.Pretty(), rt.metrics.LatencyEWMA(p).String())
fmt.Printf("\t\t- %s %s\n", p.String(), rt.metrics.LatencyEWMA(p).String())
}
}
rt.tabLock.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion table_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"

mh "github.com/multiformats/go-multihash"
)
Expand Down
6 changes: 3 additions & 3 deletions table_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/test"

pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p/p2p/host/peerstore"

"github.com/stretchr/testify/require"
)
Expand Down
6 changes: 3 additions & 3 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/test"

"github.com/libp2p/go-libp2p-kbucket/peerdiversity"
pstore "github.com/libp2p/go-libp2p-peerstore"
pstore "github.com/libp2p/go-libp2p/p2p/host/peerstore"

ma "github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package kbucket

import (
"errors"
"github.com/minio/sha256-simd"

"github.com/libp2p/go-libp2p-core/peer"
ks "github.com/libp2p/go-libp2p-kbucket/keyspace"
"github.com/libp2p/go-libp2p/core/peer"

u "github.com/ipfs/go-ipfs-util"
"github.com/minio/sha256-simd"
)

// Returned if a routing table query returns no results. This is NOT expected
// ErrLookupFailure is returned if a routing table query returns no results. This is NOT expected
// behaviour
var ErrLookupFailure = errors.New("failed to find any peer in table")

Expand Down
2 changes: 1 addition & 1 deletion util_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kbucket

import (
"github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p/core/test"
"github.com/stretchr/testify/require"
"testing"
)
Expand Down

0 comments on commit 03c1432

Please sign in to comment.