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
f7941e98
Commit
f7941e98
authored
Jan 10, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ping: use context
parent
374a75b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
core/commands/ping.go
core/commands/ping.go
+14
-6
No files found.
core/commands/ping.go
View file @
f7941e98
...
...
@@ -72,6 +72,7 @@ Send pings to a peer using the routing system to discover its address
},
},
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
ctx
:=
req
.
Context
()
.
Context
n
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -103,14 +104,14 @@ Send pings to a peer using the routing system to discover its address
outChan
:=
make
(
chan
interface
{})
go
pingPeer
(
n
,
peerID
,
numPings
,
outChan
)
go
pingPeer
(
ctx
,
n
,
peerID
,
numPings
,
outChan
)
return
outChan
,
nil
},
Type
:
PingResult
{},
}
func
pingPeer
(
n
*
core
.
IpfsNode
,
pid
peer
.
ID
,
numPings
int
,
outChan
chan
interface
{})
{
func
pingPeer
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
pid
peer
.
ID
,
numPings
int
,
outChan
chan
interface
{})
{
defer
close
(
outChan
)
if
len
(
n
.
Peerstore
.
Addresses
(
pid
))
==
0
{
...
...
@@ -119,8 +120,7 @@ func pingPeer(n *core.IpfsNode, pid peer.ID, numPings int, outChan chan interfac
Text
:
fmt
.
Sprintf
(
"Looking up peer %s"
,
pid
.
Pretty
()),
}
// TODO: get master context passed in
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
kPingTimeout
)
ctx
,
_
:=
context
.
WithTimeout
(
ctx
,
kPingTimeout
)
p
,
err
:=
n
.
Routing
.
FindPeer
(
ctx
,
pid
)
if
err
!=
nil
{
outChan
<-
&
PingResult
{
Text
:
fmt
.
Sprintf
(
"Peer lookup error: %s"
,
err
)}
...
...
@@ -131,9 +131,17 @@ func pingPeer(n *core.IpfsNode, pid peer.ID, numPings int, outChan chan interfac
outChan
<-
&
PingResult
{
Text
:
fmt
.
Sprintf
(
"PING %s."
,
pid
.
Pretty
())}
var
done
bool
var
total
time
.
Duration
for
i
:=
0
;
i
<
numPings
;
i
++
{
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
kPingTimeout
)
for
i
:=
0
;
i
<
numPings
&&
!
done
;
i
++
{
select
{
case
<-
ctx
.
Done
()
:
done
=
true
continue
default
:
}
ctx
,
_
:=
context
.
WithTimeout
(
ctx
,
kPingTimeout
)
took
,
err
:=
n
.
Routing
.
Ping
(
ctx
,
pid
)
if
err
!=
nil
{
log
.
Errorf
(
"Ping error: %s"
,
err
)
...
...
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