@@ -19,6 +19,16 @@ type statusCmdConfig struct {
1919 configFileE2EE string
2020}
2121
22+ // Represents one Server or Client in tree
23+ type Node struct {
24+ peerConfig peer.PeerConfig
25+ relayConfig peer.Config
26+ e2eeConfig peer.Config
27+ children []* Node
28+ interfaces []api.HostInterface
29+ error string
30+ }
31+
2232// Defaults for status command.
2333// See root command for shared defaults.
2434var statusCmd = statusCmdConfig {
@@ -50,16 +60,6 @@ func init() {
5060
5161// Run attempts to parse config files into a network diagram.
5262func (cc statusCmdConfig ) Run () {
53- // Start building tree.
54- type Node struct {
55- peerConfig peer.PeerConfig
56- relayConfig peer.Config
57- e2eeConfig peer.Config
58- children []* Node
59- interfaces []api.HostInterface
60- error string
61- }
62-
6363 var err error
6464
6565 // Parse the relay and e2ee config files
@@ -81,32 +81,21 @@ func (cc statusCmdConfig) Run() {
8181 nodes := make (map [string ]Node )
8282 var errorNodes []Node
8383 e2ee_peer_list := client .e2eeConfig .GetPeers ()
84+ nodeChannel := make (chan Node )
8485 for _ , ep := range e2ee_peer_list {
85- relayConfig , e2eeConfig , err := api .ServerInfo (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
86- if err != nil {
87- errorNodes = append (errorNodes , Node {
88- peerConfig : ep ,
89- error : err .Error (),
90- })
86+ // Make all the API requests concurrently to speed things up
87+ go cc .makeAPIRequests (nodeChannel , ep )
88+ }
9189
92- } 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- }
90+ // Don't need to do anything with values, just need to loop the same number of times
91+ for range e2ee_peer_list {
92+ responseNode := <- nodeChannel
10293
103- nodes [relayConfig .GetPublicKey ()] = Node {
104- peerConfig : ep ,
105- relayConfig : relayConfig ,
106- e2eeConfig : e2eeConfig ,
107- interfaces : interfaces ,
108- }
109- }
94+ if responseNode .error == "" {
95+ nodes [responseNode .relayConfig .GetPublicKey ()] = responseNode
96+ } else {
97+ errorNodes = append (errorNodes , responseNode )
98+ }
11099 }
111100
112101 // Build tree by adding each relay node as a child.
@@ -167,6 +156,10 @@ func (cc statusCmdConfig) Run() {
167156 api ,
168157 strings .Join (ips , "," ),
169158 )
159+
160+ if c .relayConfig .GetLocalhostIP () != "" {
161+ nodeString += "\n lhost IP: " + c .relayConfig .GetLocalhostIP ()
162+ }
170163
171164 if cc .networkInfo {
172165 nodeString += `
@@ -175,7 +168,7 @@ Network Interfaces:
175168-------------------
176169`
177170 for _ , ifx := range c .interfaces {
178- nodeString += fmt . Sprintf ( "%v: \n ", ifx . Name )
171+ nodeString += ifx . Name + " \n "
179172 for _ , a := range ifx .Addrs {
180173 nodeString += strings .Repeat (" " , 2 ) + a .String () + "\n "
181174 }
@@ -233,6 +226,36 @@ Network Interfaces:
233226 }
234227}
235228
229+ func (cc statusCmdConfig ) makeAPIRequests (ch chan <- Node , ep peer.PeerConfig ) {
230+ relayConfig , e2eeConfig , err := api .ServerInfo (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
231+ if err != nil {
232+ ch <- Node {
233+ peerConfig : ep ,
234+ error : err .Error (),
235+ }
236+ return
237+
238+ } else {
239+ var interfaces []api.HostInterface
240+ if cc .networkInfo {
241+ interfaces , err = api .ServerInterfaces (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
242+ if err != nil {
243+ interfaces = append (interfaces , api.HostInterface {
244+ Name : "ERROR: " + err .Error (),
245+ })
246+ }
247+ }
248+
249+ ch <- Node {
250+ peerConfig : ep ,
251+ relayConfig : relayConfig ,
252+ e2eeConfig : e2eeConfig ,
253+ interfaces : interfaces ,
254+ }
255+ return
256+ }
257+ }
258+
236259func errorWrap (text string , lineWidth int ) string {
237260 words := strings .Fields (strings .TrimSpace (text ))
238261 if len (words ) == 0 {
0 commit comments