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
f7225934
Unverified
Commit
f7225934
authored
Apr 09, 2020
by
Steven Allen
Committed by
GitHub
Apr 09, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76 from libp2p/fix/use-duration
fix: use time.Duration for time, not floats
parents
6f708c1f
e3c58ad9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
table.go
table.go
+5
-5
table_test.go
table_test.go
+2
-2
No files found.
table.go
View file @
f7225934
...
...
@@ -50,13 +50,13 @@ type RoutingTable struct {
PeerAdded
func
(
peer
.
ID
)
// usefulnessGracePeriod is the maximum grace period we will give to a
// peer in the bucket to be useful to us, failing which, we will evict
it to make place for a new peer if the bucket
// is full
usefulnessGracePeriod
float64
// peer in the bucket to be useful to us, failing which, we will evict
//
it to make place for a new peer if the bucket
is full
usefulnessGracePeriod
time
.
Duration
}
// NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
func
NewRoutingTable
(
bucketsize
int
,
localID
ID
,
latency
time
.
Duration
,
m
peerstore
.
Metrics
,
usefulnessGracePeriod
float64
)
(
*
RoutingTable
,
error
)
{
func
NewRoutingTable
(
bucketsize
int
,
localID
ID
,
latency
time
.
Duration
,
m
peerstore
.
Metrics
,
usefulnessGracePeriod
time
.
Duration
)
(
*
RoutingTable
,
error
)
{
rt
:=
&
RoutingTable
{
buckets
:
[]
*
bucket
{
newBucket
()},
bucketsize
:
bucketsize
,
...
...
@@ -154,7 +154,7 @@ func (rt *RoutingTable) addPeer(p peer.ID, queryPeer bool) (bool, error) {
// in that bucket with a LastSuccessfulOutboundQuery value above the maximum threshold and replace it.
allPeers
:=
bucket
.
peers
()
for
_
,
pc
:=
range
allPeers
{
if
float64
(
time
.
Since
(
pc
.
LastUsefulAt
)
)
>
rt
.
usefulnessGracePeriod
{
if
time
.
Since
(
pc
.
LastUsefulAt
)
>
rt
.
usefulnessGracePeriod
{
// let's evict it and add the new peer
if
bucket
.
remove
(
pc
.
Id
)
{
bucket
.
pushFront
(
&
PeerInfo
{
Id
:
p
,
LastUsefulAt
:
lastUsefulAt
,
LastSuccessfulOutboundQueryAt
:
time
.
Now
(),
...
...
table_test.go
View file @
f7225934
...
...
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)
var
NoOpThreshold
=
float64
(
100
*
time
.
Hour
)
var NoOpThreshold = 100 * time.Hour
func TestPrint(t *testing.T) {
t.Parallel()
...
...
@@ -248,7 +248,7 @@ func TestUpdateLastUsefulAt(t *testing.T) {
}
func TestTryAddPeer(t *testing.T) {
minThreshold
:=
float64
(
24
*
1
*
time
.
Hour
)
minThreshold := 24 * 1 * time.Hour
t.Parallel()
local := test.RandPeerIDFatal(t)
...
...
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