Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kbucket
Commits
a035114e
Commit
a035114e
authored
Apr 23, 2021
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix staticcheck
parent
b90e3fed
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
5 additions
and
21 deletions
+5
-21
bucket.go
bucket.go
+0
-9
keyspace/xor_test.go
keyspace/xor_test.go
+2
-2
peerdiversity/filter_test.go
peerdiversity/filter_test.go
+0
-2
table.go
table.go
+1
-3
table_test.go
table_test.go
+2
-0
util.go
util.go
+0
-5
No files found.
bucket.go
View file @
a035114e
...
@@ -120,15 +120,6 @@ func (b *bucket) remove(id peer.ID) bool {
...
@@ -120,15 +120,6 @@ func (b *bucket) remove(id peer.ID) bool {
return
false
return
false
}
}
func
(
b
*
bucket
)
moveToFront
(
id
peer
.
ID
)
{
for
e
:=
b
.
list
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
if
e
.
Value
.
(
*
PeerInfo
)
.
Id
==
id
{
b
.
list
.
MoveToFront
(
e
)
}
}
}
func
(
b
*
bucket
)
pushFront
(
p
*
PeerInfo
)
{
func
(
b
*
bucket
)
pushFront
(
p
*
PeerInfo
)
{
b
.
list
.
PushFront
(
p
)
b
.
list
.
PushFront
(
p
)
}
}
...
...
keyspace/xor_test.go
View file @
a035114e
...
@@ -92,11 +92,11 @@ func TestDistancesAndCenterSorting(t *testing.T) {
...
@@ -92,11 +92,11 @@ func TestDistancesAndCenterSorting(t *testing.T) {
return
big
.
NewInt
(
a
)
.
Cmp
(
b
)
return
big
.
NewInt
(
a
)
.
Cmp
(
b
)
}
}
if
0
!=
cmp
(
0
,
keys
[
2
]
.
Distance
(
keys
[
3
]))
{
if
cmp
(
0
,
keys
[
2
]
.
Distance
(
keys
[
3
]))
!=
0
{
t
.
Errorf
(
"distance calculation wrong: %v"
,
keys
[
2
]
.
Distance
(
keys
[
3
]))
t
.
Errorf
(
"distance calculation wrong: %v"
,
keys
[
2
]
.
Distance
(
keys
[
3
]))
}
}
if
0
!=
cmp
(
1
,
keys
[
2
]
.
Distance
(
keys
[
4
]))
{
if
cmp
(
1
,
keys
[
2
]
.
Distance
(
keys
[
4
]))
!=
0
{
t
.
Errorf
(
"distance calculation wrong: %v"
,
keys
[
2
]
.
Distance
(
keys
[
4
]))
t
.
Errorf
(
"distance calculation wrong: %v"
,
keys
[
2
]
.
Distance
(
keys
[
4
]))
}
}
...
...
peerdiversity/filter_test.go
View file @
a035114e
...
@@ -20,8 +20,6 @@ type mockPeerGroupFilter struct {
...
@@ -20,8 +20,6 @@ type mockPeerGroupFilter struct {
peerAddressFunc
func
(
p
peer
.
ID
)
[]
ma
.
Multiaddr
peerAddressFunc
func
(
p
peer
.
ID
)
[]
ma
.
Multiaddr
allowFnc
func
(
g
PeerGroupInfo
)
bool
allowFnc
func
(
g
PeerGroupInfo
)
bool
incrementFunc
func
(
g
PeerGroupInfo
)
dectementFunc
func
(
g
PeerGroupInfo
)
}
}
func
(
m
*
mockPeerGroupFilter
)
Allow
(
g
PeerGroupInfo
)
(
allow
bool
)
{
func
(
m
*
mockPeerGroupFilter
)
Allow
(
g
PeerGroupInfo
)
(
allow
bool
)
{
...
...
table.go
View file @
a035114e
...
@@ -264,9 +264,7 @@ func (rt *RoutingTable) GetPeerInfos() []PeerInfo {
...
@@ -264,9 +264,7 @@ func (rt *RoutingTable) GetPeerInfos() []PeerInfo {
var
pis
[]
PeerInfo
var
pis
[]
PeerInfo
for
_
,
b
:=
range
rt
.
buckets
{
for
_
,
b
:=
range
rt
.
buckets
{
for
_
,
p
:=
range
b
.
peers
()
{
pis
=
append
(
pis
,
b
.
peers
()
...
)
pis
=
append
(
pis
,
p
)
}
}
}
return
pis
return
pis
}
}
...
...
table_test.go
View file @
a035114e
...
@@ -155,8 +155,10 @@ func TestEmptyBucketCollapse(t *testing.T) {
...
@@ -155,8 +155,10 @@ func TestEmptyBucketCollapse(t *testing.T) {
// add peer with cpl 0 and cpl 1 and verify we have two buckets.
// add peer with cpl 0 and cpl 1 and verify we have two buckets.
b
,
err
=
rt
.
TryAddPeer
(
p1
,
true
,
false
)
b
,
err
=
rt
.
TryAddPeer
(
p1
,
true
,
false
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
b
)
require
.
True
(
t
,
b
)
b
,
err
=
rt
.
TryAddPeer
(
p2
,
true
,
false
)
b
,
err
=
rt
.
TryAddPeer
(
p2
,
true
,
false
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
b
)
require
.
True
(
t
,
b
)
rt
.
tabLock
.
Lock
()
rt
.
tabLock
.
Lock
()
require
.
Len
(
t
,
rt
.
buckets
,
2
)
require
.
Len
(
t
,
rt
.
buckets
,
2
)
...
...
util.go
View file @
a035114e
package
kbucket
package
kbucket
import
(
import
(
"bytes"
"errors"
"errors"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peer"
...
@@ -21,10 +20,6 @@ var ErrLookupFailure = errors.New("failed to find any peer in table")
...
@@ -21,10 +20,6 @@ var ErrLookupFailure = errors.New("failed to find any peer in table")
// peer.ID or a util.Key. This unifies the keyspace
// peer.ID or a util.Key. This unifies the keyspace
type
ID
[]
byte
type
ID
[]
byte
func
(
id
ID
)
equal
(
other
ID
)
bool
{
return
bytes
.
Equal
(
id
,
other
)
}
func
(
id
ID
)
less
(
other
ID
)
bool
{
func
(
id
ID
)
less
(
other
ID
)
bool
{
a
:=
ks
.
Key
{
Space
:
ks
.
XORKeySpace
,
Bytes
:
id
}
a
:=
ks
.
Key
{
Space
:
ks
.
XORKeySpace
,
Bytes
:
id
}
b
:=
ks
.
Key
{
Space
:
ks
.
XORKeySpace
,
Bytes
:
other
}
b
:=
ks
.
Key
{
Space
:
ks
.
XORKeySpace
,
Bytes
:
other
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment