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-kad-dht
Commits
b3846d01
Unverified
Commit
b3846d01
authored
Jun 05, 2020
by
Steven Allen
Committed by
GitHub
Jun 05, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #666 from libp2p/fix/tagging
feat: protect all peers in low buckets, tag everyone else with 5
parents
df4f28c3
e14fe9b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
35 deletions
+8
-35
dht.go
dht.go
+8
-21
query.go
query.go
+0
-14
No files found.
dht.go
View file @
b3846d01
...
...
@@ -48,17 +48,6 @@ const (
// manager "kbucket" tag. It is added with the common prefix length
// between two peer IDs.
baseConnMgrScore
=
5
// UsefulConnMgrScore is given to peers that are among the first peers
// to respond to a query.
//
// This score is given to peers the first time they're useful and lasts
// until we disconnect from the peer.
usefulConnMgrScore
=
20
// UsefulConnMgrProtectedBuckets is the number of buckets where useful
// peers are _protected_, instead of just given the useful score.
usefulConnMgrProtectedBuckets
=
2
)
type
mode
int
...
...
@@ -74,8 +63,8 @@ const (
)
const
(
dhtUsefulTag
=
"dht-useful
"
kbucketTag
=
"kbucket"
kbucketTag
=
"kbucket
"
protectedBuckets
=
2
)
// IpfsDHT is an implementation of Kademlia with S/Kademlia modifications.
...
...
@@ -380,17 +369,15 @@ func makeRoutingTable(dht *IpfsDHT, cfg config, maxLastSuccessfulOutboundThresho
cmgr
:=
dht
.
host
.
ConnManager
()
rt
.
PeerAdded
=
func
(
p
peer
.
ID
)
{
// We tag our closest peers with higher and higher scores so we
// stay connected to our nearest neighbors.
//
// We _also_ (elsewhere) protect useful peers in the furthest
// buckets (our "core" routing nodes) and give high scores to
// all other useful peers.
commonPrefixLen
:=
kb
.
CommonPrefixLen
(
dht
.
selfKey
,
kb
.
ConvertPeerID
(
p
))
cmgr
.
TagPeer
(
p
,
kbucketTag
,
baseConnMgrScore
+
commonPrefixLen
)
if
commonPrefixLen
<
protectedBuckets
{
cmgr
.
Protect
(
p
,
kbucketTag
)
}
else
{
cmgr
.
TagPeer
(
p
,
kbucketTag
,
baseConnMgrScore
)
}
}
rt
.
PeerRemoved
=
func
(
p
peer
.
ID
)
{
cmgr
.
Unprotect
(
p
,
dhtUseful
Tag
)
cmgr
.
Unprotect
(
p
,
kbucket
Tag
)
cmgr
.
UntagPeer
(
p
,
kbucketTag
)
// try to fix the RT
...
...
query.go
View file @
b3846d01
...
...
@@ -187,20 +187,6 @@ func (q *query) recordPeerIsValuable(p peer.ID) {
// not in routing table
return
}
// Protect useful peers, when they're actually useful. This will last
// through disconnects. However, we'll still evict them if they keep
// disconnecting from us.
//
// Restrict to buckets 0, 1 (75% of requests, max 40 peers), so we don't
// protect _too_ many peers.
commonPrefixLen
:=
kb
.
CommonPrefixLen
(
q
.
dht
.
selfKey
,
kb
.
ConvertPeerID
(
p
))
cmgr
:=
q
.
dht
.
host
.
ConnManager
()
if
commonPrefixLen
<
usefulConnMgrProtectedBuckets
{
cmgr
.
Protect
(
p
,
dhtUsefulTag
)
}
else
{
cmgr
.
TagPeer
(
p
,
dhtUsefulTag
,
usefulConnMgrScore
)
}
}
func
(
q
*
query
)
recordValuablePeers
()
{
...
...
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