This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 361
/
net.go
66 lines (57 loc) · 1.57 KB
/
net.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package commands
import (
"os"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/bytom/util"
)
var netInfoCmd = &cobra.Command{
Use: "net-info",
Short: "Print the summary of network",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
data, exitCode := util.ClientCall("/net-info")
if exitCode != util.Success {
os.Exit(exitCode)
}
printJSON(data)
},
}
var netListeningCmd = &cobra.Command{
Use: "net-listening",
Short: "If client is actively listening for network connections",
Run: func(cmd *cobra.Command, args []string) {
data, exitCode := util.ClientCall("/net-info")
if exitCode != util.Success {
os.Exit(exitCode)
}
net := data.(map[string]interface{})
jww.FEEDBACK.Printf("net listening: %v\n", net["listening"])
},
}
var peerCountCmd = &cobra.Command{
Use: "peer-count",
Short: "Number of peers currently connected to the client",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
data, exitCode := util.ClientCall("/net-info")
if exitCode != util.Success {
os.Exit(exitCode)
}
net := data.(map[string]interface{})
jww.FEEDBACK.Printf("peer count: %v\n", net["peer_count"])
},
}
var netSyncingCmd = &cobra.Command{
Use: "net-syncing",
Short: "If the network is still syncing",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
data, exitCode := util.ClientCall("/net-info")
if exitCode != util.Success {
os.Exit(exitCode)
}
net := data.(map[string]interface{})
jww.FEEDBACK.Printf("net syncing: %v\n", net["syncing"])
},
}