@@ -19,6 +19,16 @@ type statusCmdConfig struct {
19
19
configFileE2EE string
20
20
}
21
21
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
+
22
32
// Defaults for status command.
23
33
// See root command for shared defaults.
24
34
var statusCmd = statusCmdConfig {
@@ -50,16 +60,6 @@ func init() {
50
60
51
61
// Run attempts to parse config files into a network diagram.
52
62
func (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
-
63
63
var err error
64
64
65
65
// Parse the relay and e2ee config files
@@ -81,32 +81,21 @@ func (cc statusCmdConfig) Run() {
81
81
nodes := make (map [string ]Node )
82
82
var errorNodes []Node
83
83
e2ee_peer_list := client .e2eeConfig .GetPeers ()
84
+ nodeChannel := make (chan Node )
84
85
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
+ }
91
89
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
102
93
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
+ }
110
99
}
111
100
112
101
// Build tree by adding each relay node as a child.
@@ -167,6 +156,10 @@ func (cc statusCmdConfig) Run() {
167
156
api ,
168
157
strings .Join (ips , "," ),
169
158
)
159
+
160
+ if c .relayConfig .GetLocalhostIP () != "" {
161
+ nodeString += "\n lhost IP: " + c .relayConfig .GetLocalhostIP ()
162
+ }
170
163
171
164
if cc .networkInfo {
172
165
nodeString += `
@@ -175,7 +168,7 @@ Network Interfaces:
175
168
-------------------
176
169
`
177
170
for _ , ifx := range c .interfaces {
178
- nodeString += fmt . Sprintf ( "%v: \n ", ifx . Name )
171
+ nodeString += ifx . Name + " \n "
179
172
for _ , a := range ifx .Addrs {
180
173
nodeString += strings .Repeat (" " , 2 ) + a .String () + "\n "
181
174
}
@@ -233,6 +226,36 @@ Network Interfaces:
233
226
}
234
227
}
235
228
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
+
236
259
func errorWrap (text string , lineWidth int ) string {
237
260
words := strings .Fields (strings .TrimSpace (text ))
238
261
if len (words ) == 0 {
0 commit comments