@cryptotaxi247 / kubo / commits / 898b9696c

diag/net: add timeout param to cmd

Juan Batiz-Benet committed Jan 17, 2015 at 16:44 UTC 898b9696ca47545df781b214ad7d0623320b81cb
1 file changed +17 -1
core/commands/diag.go
+17 -1
@@ -36,6 +36,8 @@ type DiagnosticOutput struct {
36 Peers []DiagnosticPeer
37 }
38
39 +var DefaultDiagnosticTimeout = time.Second * 20
40 +
41 var DiagCmd = &cmds.Command{
42 Helptext: cmds.HelpText{
43 Tagline: "Generates diagnostic reports",
@@ -57,6 +59,7 @@ connected peers and latencies between them.
59 },
60
61 Options: []cmds.Option{
62 + cmds.StringOption("timeout", "diagnostic timeout duration"),
63 cmds.StringOption("vis", "output vis. one of: "+strings.Join(visFmts, ", ")),
64 },
65
@@ -75,7 +78,20 @@ connected peers and latencies between them.
78 return nil, err
79 }
80
78 - info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
81 + timeoutS, _, err := req.Option("timeout").String()
82 + if err != nil {
83 + return nil, err
84 + }
85 + timeout := DefaultDiagnosticTimeout
86 + if timeoutS != "" {
87 + t, err := time.ParseDuration(timeoutS)
88 + if err != nil {
89 + return nil, cmds.ClientError("error parsing timeout")
90 + }
91 + timeout = t
92 + }
93 +
94 + info, err := n.Diagnostics.GetDiagnostic(timeout)
95 if err != nil {
96 return nil, err
97 }