@@ -14,13 +14,15 @@ import (
1414)
1515
1616type statusCmdConfig struct {
17+ networkInfo bool
1718 configFileRelay string
1819 configFileE2EE string
1920}
2021
2122// Defaults for status command.
2223// See root command for shared defaults.
2324var statusCmd = statusCmdConfig {
25+ networkInfo : false ,
2426 configFileRelay : ConfigRelay ,
2527 configFileE2EE : ConfigE2EE ,
2628}
@@ -39,29 +41,31 @@ func init() {
3941
4042 rootCmd .AddCommand (cmd )
4143
44+ cmd .Flags ().BoolVarP (& statusCmd .networkInfo , "network-info" , "n" , statusCmd .networkInfo , "Display network info for each online server node" )
4245 cmd .Flags ().StringVarP (& statusCmd .configFileRelay , "relay" , "1" , statusCmd .configFileRelay , "wireguard relay config input filename" )
4346 cmd .Flags ().StringVarP (& statusCmd .configFileE2EE , "e2ee" , "2" , statusCmd .configFileE2EE , "wireguard E2EE config input filename" )
4447
4548 cmd .Flags ().SortFlags = false
4649}
4750
4851// Run attempts to parse config files into a network diagram.
49- func (c statusCmdConfig ) Run () {
52+ func (cc statusCmdConfig ) Run () {
5053 // Start building tree.
5154 type Node struct {
5255 peerConfig peer.PeerConfig
5356 relayConfig peer.Config
5457 e2eeConfig peer.Config
5558 children []* Node
59+ interfaces []api.HostInterface
5660 error string
5761 }
5862
5963 var err error
6064
6165 // Parse the relay and e2ee config files
62- clientConfigRelay , err := peer .ParseConfig (c .configFileRelay )
66+ clientConfigRelay , err := peer .ParseConfig (cc .configFileRelay )
6367 check ("failed to parse relay config file" , err )
64- clientConfigE2EE , err := peer .ParseConfig (c .configFileE2EE )
68+ clientConfigE2EE , err := peer .ParseConfig (cc .configFileE2EE )
6569 check ("failed to parse e2ee config file" , err )
6670
6771 client := Node {
@@ -81,15 +85,26 @@ func (c statusCmdConfig) Run() {
8185 relayConfig , e2eeConfig , err := api .ServerInfo (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
8286 if err != nil {
8387 errorNodes = append (errorNodes , Node {
84- peerConfig : ep ,
85- error : err .Error (),
88+ peerConfig : ep ,
89+ error : err .Error (),
8690 })
87-
91+
8892 } else {
93+ var interfaces []api.HostInterface
94+ if cc .networkInfo {
95+ interfaces , err = api .ServerInterfaces (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
96+ if err != nil {
97+ interfaces = append (interfaces , api.HostInterface {
98+ Name : "ERROR: " + err .Error (),
99+ })
100+ }
101+ }
102+
89103 nodes [relayConfig .GetPublicKey ()] = Node {
90104 peerConfig : ep ,
91105 relayConfig : relayConfig ,
92106 e2eeConfig : e2eeConfig ,
107+ interfaces : interfaces ,
93108 }
94109 }
95110 }
@@ -131,19 +146,43 @@ func (c statusCmdConfig) Run() {
131146 ips := []string {}
132147 var api string
133148 for j , a := range c .peerConfig .GetAllowedIPs () {
134- if j == len (c .peerConfig .GetAllowedIPs ()) - 1 {
149+ if j == len (c .peerConfig .GetAllowedIPs ())- 1 {
135150 api = a .IP .String ()
136151 } else {
137152 ips = append (ips , a .String ())
138153 }
139154 }
140- t .AddChild (tree .NodeString (fmt .Sprintf (`server
155+
156+ nodeString := fmt .Sprintf (
157+ `server
141158 nickname: %v
142159 relay: %v...
143160 e2ee: %v...
144161
145162 api: %v
146- routes: %v ` , c .peerConfig .GetNickname (), c .relayConfig .GetPublicKey ()[:8 ], c .e2eeConfig .GetPublicKey ()[:8 ], api , strings .Join (ips , "," ))))
163+ routes: %v ` ,
164+ c .peerConfig .GetNickname (),
165+ c .relayConfig .GetPublicKey ()[:8 ],
166+ c .e2eeConfig .GetPublicKey ()[:8 ],
167+ api ,
168+ strings .Join (ips , "," ),
169+ )
170+
171+ if cc .networkInfo {
172+ nodeString += `
173+
174+ Network Interfaces:
175+ -------------------
176+ `
177+ for _ , ifx := range c .interfaces {
178+ nodeString += fmt .Sprintf ("%v:\n " , ifx .Name )
179+ for _ , a := range ifx .Addrs {
180+ nodeString += strings .Repeat (" " , 2 ) + a .String () + "\n "
181+ }
182+ }
183+ }
184+
185+ t .AddChild (tree .NodeString (nodeString ))
147186 child , err := t .Child (0 )
148187 check ("could not build tree" , err )
149188 treeTraversal (node .children [i ], child )
@@ -156,31 +195,39 @@ func (c statusCmdConfig) Run() {
156195 fmt .Println ()
157196 fmt .Fprintln (color .Output , WhiteBold (t ))
158197 fmt .Println ()
159-
198+
160199 if len (errorNodes ) > 0 {
161200 // Display known peers that we had issues connecting to
162201 fmt .Fprintln (color .Output , WhiteBold ("Peers with Errors:" ))
163202 fmt .Println ()
164-
203+
165204 for _ , node := range errorNodes {
166205 ips := []string {}
167206 var api string
168207 for j , a := range node .peerConfig .GetAllowedIPs () {
169- if j == len (node .peerConfig .GetAllowedIPs ()) - 1 {
208+ if j == len (node .peerConfig .GetAllowedIPs ())- 1 {
170209 api = a .IP .String ()
171210 } else {
172211 ips = append (ips , a .String ())
173212 }
174213 }
175-
176- t = tree .NewTree (tree .NodeString (fmt .Sprintf (`server
177214
178- nickname: %v
179- e2ee: %v...
180- api: %v
181- routes: %v
215+ nodeString := fmt .Sprintf (
216+ `server
182217
183- error: %v` , node .peerConfig .GetNickname (), node .peerConfig .GetPublicKey ().String ()[:8 ], api , strings .Join (ips , "," ), errorWrap (node .error , 80 ))))
218+ nickname: %v
219+ e2ee: %v...
220+ api: %v
221+ routes: %v
222+
223+ error: %v` ,
224+ node .peerConfig .GetNickname (),
225+ node .peerConfig .GetPublicKey ().String ()[:8 ],
226+ api , strings .Join (ips , "," ),
227+ errorWrap (node .error , 80 ),
228+ )
229+
230+ t = tree .NewTree (tree .NodeString (nodeString ))
184231 fmt .Fprintln (color .Output , WhiteBold (t ))
185232 }
186233 }
0 commit comments