@cryptotaxi247 / kubo / commits / d5f0476c1

implement diagnostics command

Jeromy committed Oct 10, 2014 at 05:29 UTC d5f0476c1c4d02864c22675d1d9e797842c1190e
4 files changed +52 -10
cmd/ipfs/diag.go new
+28
@@ -0,0 +1,28 @@
1 +package main
2 +
3 +import (
4 + "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5 +
6 + "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
7 + "github.com/jbenet/go-ipfs/core/commands"
8 +)
9 +
10 +var cmdIpfsDiag = &commander.Command{
11 + UsageLine: "diag",
12 + Short: "Generate a diagnostics report",
13 + Long: `ipfs diag - Generate a diagnostics report.
14 +
15 + Sends out a message to each node in the network recursively
16 + requesting a listing of data about them including number of
17 + connected peers and latencies between them.
18 +`,
19 + Run: diagCmd,
20 + Flag: *flag.NewFlagSet("ipfs-diag", flag.ExitOnError),
21 +}
22 +
23 +var diagCmd = makeCommand(command{
24 + name: "diag",
25 + args: 0,
26 + flags: nil,
27 + cmdFn: commands.Diag,
28 +})
core/commands/diag.go new
+22
@@ -0,0 +1,22 @@
1 +package commands
2 +
3 +import (
4 + "encoding/json"
5 + "io"
6 + "time"
7 +
8 + "github.com/jbenet/go-ipfs/core"
9 +)
10 +
11 +func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12 + info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
13 + if err != nil {
14 + return err
15 + }
16 + enc := json.NewEncoder(out)
17 + err = enc.Encode(info)
18 + if err != nil {
19 + return err
20 + }
21 + return nil
22 +}
daemon/daemon.go
+1 -9
@@ -8,7 +8,6 @@ import (
8 "os"
9 "path"
10 "sync"
11 - "time"
11
12 core "github.com/jbenet/go-ipfs/core"
13 "github.com/jbenet/go-ipfs/core/commands"
@@ -138,14 +137,7 @@ func (dl *DaemonListener) handleConnection(conn net.Conn) {
137 case "resolve":
138 err = commands.Resolve(dl.node, command.Args, command.Opts, conn)
139 case "diag":
141 - log.Debug("DIAGNOSTIC!")
142 - info, err := dl.node.Diagnostics.GetDiagnostic(time.Second * 20)
143 - if err != nil {
144 - fmt.Fprintln(conn, err)
145 - return
146 - }
147 - enc := json.NewEncoder(conn)
148 - err = enc.Encode(info)
140 + err = commands.Diag(dl.node, command.Args, command.Opts, conn)
141 default:
142 err = fmt.Errorf("Invalid Command: '%s'", command.Command)
143 }
diagnostics/message.pb.go
+1 -1
@@ -13,7 +13,7 @@ It has these top-level messages:
13 */
14 package diagnostic
15
16 -import proto "code.google.com/p/goprotobuf/proto"
16 +import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
17 import math "math"
18
19 // Reference imports to suppress errors if they are not otherwise used.