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
0794d5b4
Commit
0794d5b4
authored
Jan 09, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a little cleanup
parent
069966d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
core/commands/ping.go
core/commands/ping.go
+25
-4
No files found.
core/commands/ping.go
View file @
0794d5b4
...
...
@@ -2,6 +2,7 @@ package commands
import
(
"bytes"
"errors"
"fmt"
"io"
"time"
...
...
@@ -13,6 +14,8 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
const
kPingTimeout
=
10
*
time
.
Second
type
PingResult
struct
{
Success
bool
Time
time
.
Duration
...
...
@@ -30,7 +33,7 @@ send pings, wait for pongs, and print out round-trip latency information.
`
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"
peer-id"
,
tru
e
,
true
,
"
ID
of p
eer
to p
ing
"
),
cmds
.
StringArg
(
"
count"
,
fals
e
,
true
,
"
Number
of p
ings
to p
erform
"
),
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
...
...
@@ -66,15 +69,32 @@ send pings, wait for pongs, and print out round-trip latency information.
return
nil
,
err
}
// Must be online!
if
!
n
.
OnlineMode
()
{
return
nil
,
errNotOnline
}
peerID
,
err
:=
peer
.
IDB58Decode
(
"QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
)
if
len
(
req
.
Arguments
())
==
0
{
return
nil
,
errors
.
New
(
"no peer specified!"
)
}
// Set up number of pings
numPings
:=
10
val
,
found
,
err
:=
req
.
Option
(
"count"
)
.
Int
()
if
err
!=
nil
{
return
nil
,
err
}
const
kPingTimeout
=
10
*
time
.
Second
if
found
{
numPings
=
val
}
// One argument of input required, must be base58 encoded peerID
peerID
,
err
:=
peer
.
IDB58Decode
(
req
.
Arguments
()[
0
])
if
err
!=
nil
{
return
nil
,
err
}
// Make sure we can find the node in question
ctx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
kPingTimeout
)
p
,
err
:=
n
.
Routing
.
FindPeer
(
ctx
,
peerID
)
if
err
!=
nil
{
...
...
@@ -85,11 +105,12 @@ send pings, wait for pongs, and print out round-trip latency information.
go
func
()
{
defer
close
(
outChan
)
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
numPings
;
i
++
{
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
kPingTimeout
)
before
:=
time
.
Now
()
err
:=
n
.
Routing
.
Ping
(
ctx
,
p
.
ID
)
if
err
!=
nil
{
log
.
Errorf
(
"Ping error: %s"
,
err
)
outChan
<-
&
PingResult
{}
break
}
...
...
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