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
dms3
go-dms3
Commits
dc0fbfd3
Commit
dc0fbfd3
authored
Sep 18, 2014
by
Juan Batiz-Benet
Committed by
Brian Tiger Chow
Sep 22, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some logging
parent
a114e9cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
+23
-3
routing/dht/query.go
routing/dht/query.go
+23
-3
No files found.
routing/dht/query.go
View file @
dc0fbfd3
...
...
@@ -111,7 +111,12 @@ func (r *dhtQueryRunner) Run(peers []*peer.Peer) (*dhtQueryResult, error) {
r
.
addPeerToQuery
(
p
,
nil
)
// don't have access to self here...
}
// wait until we're done. yep.
// go do this thing.
go
r
.
spawnWorkers
()
// so workers are working.
// wait until they're done.
select
{
case
<-
r
.
peersRemaining
.
Done
()
:
r
.
cancel
()
// ran all and nothing. cancel all outstanding workers.
...
...
@@ -158,6 +163,8 @@ func (r *dhtQueryRunner) addPeerToQuery(next *peer.Peer, benchmark *peer.Peer) {
r
.
peersSeen
[
next
.
Key
()]
=
next
r
.
Unlock
()
u
.
POut
(
"adding peer to query: %v
\n
"
,
next
.
ID
.
Pretty
())
// do this after unlocking to prevent possible deadlocks.
r
.
peersRemaining
.
Increment
(
1
)
select
{
...
...
@@ -166,8 +173,9 @@ func (r *dhtQueryRunner) addPeerToQuery(next *peer.Peer, benchmark *peer.Peer) {
}
}
func
(
r
*
dhtQueryRunner
)
spawnWorkers
(
p
*
peer
.
Peer
)
{
func
(
r
*
dhtQueryRunner
)
spawnWorkers
()
{
for
{
select
{
case
<-
r
.
peersRemaining
.
Done
()
:
return
...
...
@@ -175,13 +183,19 @@ func (r *dhtQueryRunner) spawnWorkers(p *peer.Peer) {
case
<-
r
.
ctx
.
Done
()
:
return
case
p
:=
<-
r
.
peersToQuery
.
DeqChan
:
case
p
,
more
:=
<-
r
.
peersToQuery
.
DeqChan
:
if
!
more
{
return
// channel closed.
}
u
.
POut
(
"spawning worker for: %v
\n
"
,
p
.
ID
.
Pretty
())
go
r
.
queryPeer
(
p
)
}
}
}
func
(
r
*
dhtQueryRunner
)
queryPeer
(
p
*
peer
.
Peer
)
{
u
.
POut
(
"spawned worker for: %v
\n
"
,
p
.
ID
.
Pretty
())
// make sure we rate limit concurrency.
select
{
case
<-
r
.
rateLimit
:
...
...
@@ -190,27 +204,33 @@ func (r *dhtQueryRunner) queryPeer(p *peer.Peer) {
return
}
u
.
POut
(
"running worker for: %v
\n
"
,
p
.
ID
.
Pretty
())
// finally, run the query against this peer
res
,
err
:=
r
.
query
.
qfunc
(
r
.
ctx
,
p
)
if
err
!=
nil
{
u
.
POut
(
"ERROR worker for: %v %v
\n
"
,
p
.
ID
.
Pretty
(),
err
)
r
.
Lock
()
r
.
errs
=
append
(
r
.
errs
,
err
)
r
.
Unlock
()
}
else
if
res
.
success
{
u
.
POut
(
"SUCCESS worker for: %v
\n
"
,
p
.
ID
.
Pretty
(),
res
)
r
.
Lock
()
r
.
result
=
res
r
.
Unlock
()
r
.
cancel
()
// signal to everyone that we're done.
}
else
if
res
.
closerPeers
!=
nil
{
u
.
POut
(
"PEERS CLOSER -- worker for: %v
\n
"
,
p
.
ID
.
Pretty
())
for
_
,
next
:=
range
res
.
closerPeers
{
r
.
addPeerToQuery
(
next
,
p
)
}
}
// signal we're done proccessing peer p
u
.
POut
(
"completing worker for: %v
\n
"
,
p
.
ID
.
Pretty
())
r
.
peersRemaining
.
Decrement
(
1
)
r
.
rateLimit
<-
struct
{}{}
}
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