Commit d5f0476c authored by Jeromy's avatar Jeromy

implement diagnostics command

parent 280c7e7e
package main
import (
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
)
var cmdIpfsDiag = &commander.Command{
UsageLine: "diag",
Short: "Generate a diagnostics report",
Long: `ipfs diag - Generate a diagnostics report.
Sends out a message to each node in the network recursively
requesting a listing of data about them including number of
connected peers and latencies between them.
`,
Run: diagCmd,
Flag: *flag.NewFlagSet("ipfs-diag", flag.ExitOnError),
}
var diagCmd = makeCommand(command{
name: "diag",
args: 0,
flags: nil,
cmdFn: commands.Diag,
})
package commands
import (
"encoding/json"
"io"
"time"
"github.com/jbenet/go-ipfs/core"
)
func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
if err != nil {
return err
}
enc := json.NewEncoder(out)
err = enc.Encode(info)
if err != nil {
return err
}
return nil
}
......@@ -8,7 +8,6 @@ import (
"os"
"path"
"sync"
"time"
core "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands"
......@@ -138,14 +137,7 @@ func (dl *DaemonListener) handleConnection(conn net.Conn) {
case "resolve":
err = commands.Resolve(dl.node, command.Args, command.Opts, conn)
case "diag":
log.Debug("DIAGNOSTIC!")
info, err := dl.node.Diagnostics.GetDiagnostic(time.Second * 20)
if err != nil {
fmt.Fprintln(conn, err)
return
}
enc := json.NewEncoder(conn)
err = enc.Encode(info)
err = commands.Diag(dl.node, command.Args, command.Opts, conn)
default:
err = fmt.Errorf("Invalid Command: '%s'", command.Command)
}
......
......@@ -13,7 +13,7 @@ It has these top-level messages:
*/
package diagnostic
import proto "code.google.com/p/goprotobuf/proto"
import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment