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
844420e8
Commit
844420e8
authored
Apr 05, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments
parent
7c961a02
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
table_refresh.go
table_refresh.go
+2
-2
table_refresh_test.go
table_refresh_test.go
+6
-6
No files found.
table_refresh.go
View file @
844420e8
...
...
@@ -26,8 +26,8 @@ func (rt *RoutingTable) GetTrackedCplsForRefresh() []time.Time {
rt
.
cplRefreshLk
.
RLock
()
defer
rt
.
cplRefreshLk
.
RUnlock
()
cpls
:=
make
([]
time
.
Time
,
maxCommonPrefix
)
for
i
:=
uint
(
0
);
i
<
maxCommonPrefix
;
i
++
{
cpls
:=
make
([]
time
.
Time
,
maxCommonPrefix
+
1
)
for
i
:=
uint
(
0
);
i
<
=
maxCommonPrefix
;
i
++
{
// defaults to the zero value if we haven't refreshed it yet.
cpls
[
i
]
=
rt
.
cplRefreshedAt
[
i
]
}
...
...
table_refresh_test.go
View file @
844420e8
...
...
@@ -51,7 +51,7 @@ func TestRefreshAndGetTrackedCpls(t *testing.T) {
// fetch cpl's
trackedCpls
:=
rt
.
GetTrackedCplsForRefresh
()
// should have nothing.
require
.
Len
(
t
,
trackedCpls
,
0
)
require
.
Len
(
t
,
trackedCpls
,
1
)
var
peerIDs
[]
peer
.
ID
for
i
:=
minCpl
;
i
<=
maxCpl
;
i
++
{
...
...
@@ -65,18 +65,18 @@ func TestRefreshAndGetTrackedCpls(t *testing.T) {
added
,
err
:=
rt
.
TryAddPeer
(
id
,
true
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
added
)
require
.
Len
(
t
,
rt
.
GetTrackedCplsForRefresh
(),
minCpl
+
i
)
require
.
Len
(
t
,
rt
.
GetTrackedCplsForRefresh
(),
minCpl
+
i
+
1
)
}
// and remove down to the test CPL
for
i
:=
maxCpl
;
i
>
testCpl
;
i
--
{
rt
.
RemovePeer
(
peerIDs
[
i
-
minCpl
])
require
.
Len
(
t
,
rt
.
GetTrackedCplsForRefresh
(),
i
-
1
)
require
.
Len
(
t
,
rt
.
GetTrackedCplsForRefresh
(),
i
)
}
// should be tracking testCpl
trackedCpls
=
rt
.
GetTrackedCplsForRefresh
()
require
.
Len
(
t
,
trackedCpls
,
testCpl
)
require
.
Len
(
t
,
trackedCpls
,
testCpl
+
1
)
// they should all be zero
for
_
,
refresh
:=
range
trackedCpls
{
require
.
True
(
t
,
refresh
.
IsZero
(),
"tracked cpl's should be zero"
)
...
...
@@ -89,7 +89,7 @@ func TestRefreshAndGetTrackedCpls(t *testing.T) {
// should be tracking the max
trackedCpls
=
rt
.
GetTrackedCplsForRefresh
()
require
.
Len
(
t
,
trackedCpls
,
int
(
maxCplForRefresh
))
require
.
Len
(
t
,
trackedCpls
,
int
(
maxCplForRefresh
)
+
1
)
// and not refreshed
for
_
,
refresh
:=
range
trackedCpls
{
...
...
@@ -102,7 +102,7 @@ func TestRefreshAndGetTrackedCpls(t *testing.T) {
// should still be tracking all buckets
trackedCpls
=
rt
.
GetTrackedCplsForRefresh
()
require
.
Len
(
t
,
trackedCpls
,
int
(
maxCplForRefresh
))
require
.
Len
(
t
,
trackedCpls
,
int
(
maxCplForRefresh
)
+
1
)
for
i
,
refresh
:=
range
trackedCpls
{
if
i
==
testCpl
{
...
...
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