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
155220bb
Commit
155220bb
authored
Aug 29, 2019
by
Aarsh Shah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes as per review
parent
d5e5a484
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
7 deletions
+4
-7
table.go
table.go
+3
-3
table_test.go
table_test.go
+1
-4
No files found.
table.go
View file @
155220bb
...
...
@@ -68,9 +68,9 @@ func (rt *RoutingTable) GetAllBuckets() []*Bucket {
}
// GenRandPeerID generates a random peerID in bucket=bucketID
func
(
rt
*
RoutingTable
)
GenRandPeerID
(
bucketID
int
)
(
peer
.
ID
,
error
)
{
func
(
rt
*
RoutingTable
)
GenRandPeerID
(
bucketID
int
)
peer
.
ID
{
if
bucketID
<
0
{
panic
(
errors
.
New
(
fmt
.
Sprintf
(
"bucketID %d is not non-negative"
,
bucketID
))
)
panic
(
fmt
.
Sprintf
(
"bucketID %d is not non-negative"
,
bucketID
))
}
rt
.
tabLock
.
RLock
()
bucketLen
:=
len
(
rt
.
Buckets
)
...
...
@@ -109,7 +109,7 @@ func (rt *RoutingTable) GenRandPeerID(bucketID int) (peer.ID, error) {
key
:=
keyPrefixMap
[
targetPrefix
]
id
:=
[
34
]
byte
{
mh
.
SHA2_256
,
32
}
binary
.
BigEndian
.
PutUint32
(
id
[
2
:
],
key
)
return
peer
.
ID
(
id
[
:
])
,
nil
return
peer
.
ID
(
id
[
:
])
}
// Returns the bucket for a given ID
...
...
table_test.go
View file @
155220bb
...
...
@@ -75,10 +75,7 @@ func TestGenRandPeerID(t *testing.T) {
// test generate rand peer ID
for
bucketID
:=
0
;
bucketID
<
nBuckets
;
bucketID
++
{
peerID
,
err
:=
rt
.
GenRandPeerID
(
bucketID
)
if
err
!=
nil
||
len
(
peerID
)
==
0
{
t
.
Fatalf
(
"error %+v & peerID %s for bucket %d"
,
err
,
peerID
,
bucketID
)
}
peerID
:=
rt
.
GenRandPeerID
(
bucketID
)
// for bucketID upto maxPrefixLen of 16, CPL should be Exactly bucketID
if
bucketID
<
16
{
...
...
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