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
616b0e12
Commit
616b0e12
authored
Jan 21, 2020
by
Adin Schmahmann
Committed by
Steven Allen
Apr 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix refreshing buckets during query. getting topK peers is more efficient.
parent
564764fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
kpeerset/sorted_peerset.go
kpeerset/sorted_peerset.go
+10
-9
lookup.go
lookup.go
+1
-1
routing.go
routing.go
+2
-2
No files found.
kpeerset/sorted_peerset.go
View file @
616b0e12
...
...
@@ -116,23 +116,24 @@ func (ps *SortedPeerset) Add(p peer.ID) {
}
func
(
ps
*
SortedPeerset
)
TopK
()
[]
peer
.
ID
{
return
ps
.
getTopK
(
nil
)
}
ps
.
lock
.
Lock
(
)
defer
ps
.
lock
.
Unlock
()
func
(
ps
*
SortedPeerset
)
KUnqueried
()
[]
peer
.
ID
{
return
ps
.
getTopK
(
func
(
p
peer
.
ID
)
bool
{
_
,
ok
:=
ps
.
queried
[
p
]
return
ok
})
topK
:=
make
([]
peer
.
ID
,
0
,
len
(
ps
.
heapTopKPeers
.
data
))
for
_
,
pm
:=
range
ps
.
heapTopKPeers
.
data
{
topK
=
append
(
topK
,
pm
.
Peer
())
}
return
topK
}
func
(
ps
*
SortedPeerset
)
getTopK
(
filter
func
(
p
peer
.
ID
)
bool
)
[]
peer
.
ID
{
func
(
ps
*
SortedPeerset
)
KUnqueried
(
)
[]
peer
.
ID
{
ps
.
lock
.
Lock
()
defer
ps
.
lock
.
Unlock
()
topK
:=
make
([]
IPeerMetric
,
0
,
len
(
ps
.
heapTopKPeers
.
data
))
for
_
,
pm
:=
range
ps
.
heapTopKPeers
.
data
{
if
filter
==
nil
||
!
filter
(
pm
.
Peer
()
)
{
if
_
,
ok
:=
ps
.
queried
[
pm
.
Peer
()
];
!
ok
{
topK
=
append
(
topK
,
pm
.
IPeerMetric
)
}
}
...
...
lookup.go
View file @
616b0e12
...
...
@@ -117,7 +117,7 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan pee
out
<-
p
}
if
ctx
.
Err
()
!
=
nil
{
if
ctx
.
Err
()
=
=
nil
{
// refresh the cpl for this key as the query was successful
dht
.
routingTable
.
ResetCplRefreshedAtForID
(
kadID
,
time
.
Now
())
}
...
...
routing.go
View file @
616b0e12
...
...
@@ -403,7 +403,7 @@ func (dht *IpfsDHT) getValues(ctx context.Context, key string, stopFn func() boo
}
}
if
!
shortcutTaken
{
if
!
shortcutTaken
&&
ctx
.
Err
()
==
nil
{
kadID
:=
kb
.
ConvertKey
(
key
)
// refresh the cpl for this key as the query was successful
dht
.
routingTable
.
ResetCplRefreshedAtForID
(
kadID
,
time
.
Now
())
...
...
@@ -678,7 +678,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (_ peer.AddrInfo,
return
dht
.
peerstore
.
PeerInfo
(
id
),
nil
}
else
{
if
ctx
.
Err
()
!
=
nil
{
if
ctx
.
Err
()
=
=
nil
{
kadID
:=
kb
.
ConvertPeerID
(
id
)
// refresh the cpl for this key as the query was successful
dht
.
routingTable
.
ResetCplRefreshedAtForID
(
kadID
,
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