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
6d7f974b
Commit
6d7f974b
authored
Mar 04, 2019
by
Matt Joiner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Export CommonPrefixLen
parent
b2a6f3f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
8 deletions
+8
-8
bucket.go
bucket.go
+1
-1
table.go
table.go
+3
-3
table_test.go
table_test.go
+3
-3
util.go
util.go
+1
-1
No files found.
bucket.go
View file @
6d7f974b
...
...
@@ -94,7 +94,7 @@ func (b *Bucket) Split(cpl int, target ID) *Bucket {
e
:=
b
.
list
.
Front
()
for
e
!=
nil
{
peerID
:=
ConvertPeerID
(
e
.
Value
.
(
peer
.
ID
))
peerCPL
:=
c
ommonPrefixLen
(
peerID
,
target
)
peerCPL
:=
C
ommonPrefixLen
(
peerID
,
target
)
if
peerCPL
>
cpl
{
cur
:=
e
out
.
PushBack
(
e
.
Value
)
...
...
table.go
View file @
6d7f974b
...
...
@@ -60,7 +60,7 @@ func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m pstore
// Update adds or moves the given peer to the front of its respective bucket
func
(
rt
*
RoutingTable
)
Update
(
p
peer
.
ID
)
(
evicted
peer
.
ID
,
err
error
)
{
peerID
:=
ConvertPeerID
(
p
)
cpl
:=
c
ommonPrefixLen
(
peerID
,
rt
.
local
)
cpl
:=
C
ommonPrefixLen
(
peerID
,
rt
.
local
)
rt
.
tabLock
.
Lock
()
defer
rt
.
tabLock
.
Unlock
()
...
...
@@ -117,7 +117,7 @@ func (rt *RoutingTable) Remove(p peer.ID) {
rt
.
tabLock
.
Lock
()
defer
rt
.
tabLock
.
Unlock
()
peerID
:=
ConvertPeerID
(
p
)
cpl
:=
c
ommonPrefixLen
(
peerID
,
rt
.
local
)
cpl
:=
C
ommonPrefixLen
(
peerID
,
rt
.
local
)
bucketID
:=
cpl
if
bucketID
>=
len
(
rt
.
Buckets
)
{
...
...
@@ -166,7 +166,7 @@ func (rt *RoutingTable) NearestPeer(id ID) peer.ID {
// NearestPeers returns a list of the 'count' closest peers to the given ID
func
(
rt
*
RoutingTable
)
NearestPeers
(
id
ID
,
count
int
)
[]
peer
.
ID
{
cpl
:=
c
ommonPrefixLen
(
id
,
rt
.
local
)
cpl
:=
C
ommonPrefixLen
(
id
,
rt
.
local
)
rt
.
tabLock
.
RLock
()
...
...
table_test.go
View file @
6d7f974b
...
...
@@ -32,7 +32,7 @@ func TestBucket(t *testing.T) {
llist
:=
b
.
list
for
e
:=
llist
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
p
:=
ConvertPeerID
(
e
.
Value
.
(
peer
.
ID
))
cpl
:=
c
ommonPrefixLen
(
p
,
localID
)
cpl
:=
C
ommonPrefixLen
(
p
,
localID
)
if
cpl
>
0
{
t
.
Fatalf
(
"Split failed. found id with cpl > 0 in 0 bucket"
)
}
...
...
@@ -41,7 +41,7 @@ func TestBucket(t *testing.T) {
rlist
:=
spl
.
list
for
e
:=
rlist
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
p
:=
ConvertPeerID
(
e
.
Value
.
(
peer
.
ID
))
cpl
:=
c
ommonPrefixLen
(
p
,
localID
)
cpl
:=
C
ommonPrefixLen
(
p
,
localID
)
if
cpl
==
0
{
t
.
Fatalf
(
"Split failed. found id with cpl == 0 in non 0 bucket"
)
}
...
...
@@ -144,7 +144,7 @@ func TestTableEldestPreferred(t *testing.T) {
// generate size + 1 peers to saturate a bucket
peers
:=
make
([]
peer
.
ID
,
15
)
for
i
:=
0
;
i
<
15
;
{
if
p
:=
tu
.
RandPeerIDFatal
(
t
);
c
ommonPrefixLen
(
ConvertPeerID
(
local
),
ConvertPeerID
(
p
))
==
0
{
if
p
:=
tu
.
RandPeerIDFatal
(
t
);
C
ommonPrefixLen
(
ConvertPeerID
(
local
),
ConvertPeerID
(
p
))
==
0
{
peers
[
i
]
=
p
i
++
}
...
...
util.go
View file @
6d7f974b
...
...
@@ -34,7 +34,7 @@ func xor(a, b ID) ID {
return
ID
(
u
.
XOR
(
a
,
b
))
}
func
c
ommonPrefixLen
(
a
,
b
ID
)
int
{
func
C
ommonPrefixLen
(
a
,
b
ID
)
int
{
return
ks
.
ZeroPrefixLen
(
u
.
XOR
(
a
,
b
))
}
...
...
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