-
Notifications
You must be signed in to change notification settings - Fork 255
/
net.go
141 lines (123 loc) · 3.32 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package commands
import (
"github.com/33cn/chain33/types"
"github.com/spf13/cobra"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
)
// NetCmd net command
func NetCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "net",
Short: "Net operation",
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(
GetPeerInfoCmd(),
IsClockSyncCmd(),
IsSyncCmd(),
GetNetInfoCmd(),
GetFatalFailureCmd(),
GetTimeStausCmd(),
)
return cmd
}
// GetPeerInfoCmd get peers connected info
func GetPeerInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "peer",
Short: "Get remote peer nodes",
Run: peerInfo,
}
cmd.Flags().StringP("type", "t", "", "p2p type, gossip or dht")
return cmd
}
func peerInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res rpctypes.PeerList
p2pty, _ := cmd.Flags().GetString("type")
req := types.P2PGetPeerReq{P2PType: p2pty}
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetPeerInfo", req, &res)
ctx.Run()
}
// IsClockSyncCmd get ntp clock sync status
func IsClockSyncCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "is_clock_sync",
Short: "Get ntp clock synchronization status",
Run: isClockSync,
}
return cmd
}
func isClockSync(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res bool
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.IsNtpClockSync", nil, &res)
ctx.Run()
}
// IsSyncCmd get local db sync status
func IsSyncCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "is_sync",
Short: "Get blockchain synchronization status",
Run: isSync,
}
return cmd
}
func isSync(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res bool
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.IsSync", nil, &res)
ctx.Run()
}
// GetNetInfoCmd get net info
func GetNetInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "info",
Short: "Get net information",
Run: netInfo,
}
cmd.Flags().StringP("type", "t", "", "p2p type, gossip or dht")
return cmd
}
func netInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
p2pty, _ := cmd.Flags().GetString("type")
req := types.P2PGetNetInfoReq{P2PType: p2pty}
var res rpctypes.NodeNetinfo
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetNetInfo", req, &res)
ctx.Run()
}
// GetFatalFailureCmd get FatalFailure
func GetFatalFailureCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fault",
Short: "Get system fault",
Run: fatalFailure,
}
return cmd
}
func fatalFailure(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res int64
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetFatalFailure", nil, &res)
ctx.Run()
}
// GetTimeStausCmd get time status
func GetTimeStausCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "time",
Short: "Get time status",
Run: timestatus,
}
return cmd
}
func timestatus(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res rpctypes.TimeStatus
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.GetTimeStatus", nil, &res)
ctx.Run()
}