-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
- Loading branch information
Brian Tiger Chow
committed
Dec 5, 2014
1 parent
b1cfb3f
commit f777332
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package commands | ||
|
||
import ( | ||
"time" | ||
|
||
cmds "github.com/jbenet/go-ipfs/commands" | ||
"github.com/jbenet/go-ipfs/net/message" | ||
peer "github.com/jbenet/go-ipfs/peer" | ||
|
||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" | ||
) | ||
|
||
var PingCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "send echo request packets to IPFS hosts", | ||
Synopsis: ` | ||
ipfs ping <peer.ID> - Send pings to a peer using the routing system to discover its address | ||
`, | ||
ShortDescription: ` | ||
ipfs ping is a tool to find a node (in the routing system), | ||
send pings, wait for pongs, and print out round-trip latency information. | ||
`, | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("peer-id", true, true, "ID of peer to ping"), | ||
}, | ||
Run: func(req cmds.Request) (interface{}, error) { | ||
n, err := req.Context().GetNode() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !n.OnlineMode() { | ||
return nil, errNotOnline | ||
} | ||
|
||
peerID := peer.DecodePrettyID("QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ") | ||
const kPingTimeout = 10 * time.Second | ||
ctx, _ := context.WithTimeout(context.Background(), kPingTimeout) | ||
p, err := n.Routing.FindPeer(ctx, peerID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := n.Network.DialPeer(ctx, p); err != nil { | ||
return nil, err | ||
} | ||
msg := message.New(p, nil) | ||
n.Network.SendMessage(msg) | ||
return nil, nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters