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
a4329c39
Commit
a4329c39
authored
Apr 09, 2020
by
Aarsh Shah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better naming
parent
ac6d9f25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
table.go
table.go
+6
-6
No files found.
table.go
View file @
a4329c39
...
...
@@ -49,14 +49,14 @@ type RoutingTable struct {
PeerRemoved
func
(
peer
.
ID
)
PeerAdded
func
(
peer
.
ID
)
//
maxLastUsefulAt is the max threshold/upper limit for the value of "LastUsefulAt"
//
of the
peer in the bucket
above
which we will evict it to make place for a new peer if the bucket
//
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
maxLastUsefulAt
float64
usefulnessGracePeriod
float64
}
// 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
,
maxLastUsefulAt
float64
)
(
*
RoutingTable
,
error
)
{
func
NewRoutingTable
(
bucketsize
int
,
localID
ID
,
latency
time
.
Duration
,
m
peerstore
.
Metrics
,
usefulnessGracePeriod
float64
)
(
*
RoutingTable
,
error
)
{
rt
:=
&
RoutingTable
{
buckets
:
[]
*
bucket
{
newBucket
()},
bucketsize
:
bucketsize
,
...
...
@@ -70,7 +70,7 @@ func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m peerst
PeerRemoved
:
func
(
peer
.
ID
)
{},
PeerAdded
:
func
(
peer
.
ID
)
{},
maxLastUsefulAt
:
maxLastUsefulAt
,
usefulnessGracePeriod
:
usefulnessGracePeriod
,
}
rt
.
ctx
,
rt
.
ctxCancel
=
context
.
WithCancel
(
context
.
Background
())
...
...
@@ -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
.
maxLastUsefulAt
{
if
float64
(
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
(),
...
...
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