4
4
"fmt"
5
5
"net/netip"
6
6
"strings"
7
- "log"
8
7
9
8
"github.com/fatih/color"
10
9
"github.com/m1gwings/treedrawer/tree"
@@ -54,6 +53,7 @@ func (c statusCmdConfig) Run() {
54
53
relayConfig peer.Config
55
54
e2eeConfig peer.Config
56
55
children []* Node
56
+ error string
57
57
}
58
58
59
59
var err error
@@ -75,12 +75,16 @@ func (c statusCmdConfig) Run() {
75
75
// Get map of all nodes for building tree.
76
76
// Key on public key of relay interfaces.
77
77
nodes := make (map [string ]Node )
78
- e2ee_peer_list := clientConfigE2EE .GetPeers ()
78
+ var errorNodes []Node
79
+ e2ee_peer_list := client .e2eeConfig .GetPeers ()
79
80
for _ , ep := range e2ee_peer_list {
80
81
relayConfig , e2eeConfig , err := api .ServerInfo (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
81
82
if err != nil {
82
- message := "failed to fetch node's configuration as peer"
83
- log .Printf ("%s: %v" , message , err )
83
+ errorNodes = append (errorNodes , Node {
84
+ peerConfig : ep ,
85
+ error : err .Error (),
86
+ })
87
+
84
88
} else {
85
89
nodes [relayConfig .GetPublicKey ()] = Node {
86
90
peerConfig : ep ,
@@ -127,7 +131,7 @@ func (c statusCmdConfig) Run() {
127
131
ips := []string {}
128
132
var api string
129
133
for j , a := range c .peerConfig .GetAllowedIPs () {
130
- if j == len (c .peerConfig .GetAllowedIPs ())- 1 {
134
+ if j == len (c .peerConfig .GetAllowedIPs ()) - 1 {
131
135
api = a .IP .String ()
132
136
} else {
133
137
ips = append (ips , a .String ())
@@ -149,6 +153,56 @@ func (c statusCmdConfig) Run() {
149
153
check ("could not build tree" , err )
150
154
treeTraversal (& client , child )
151
155
152
- fmt .Fprintln ( color . Output )
156
+ fmt .Println ( )
153
157
fmt .Fprintln (color .Output , WhiteBold (t ))
158
+ fmt .Println ()
159
+
160
+ if len (errorNodes ) > 0 {
161
+ // Display known peers that we had issues connecting to
162
+ fmt .Fprintln (color .Output , WhiteBold ("Peers with Errors:" ))
163
+ fmt .Println ()
164
+
165
+ for _ , node := range errorNodes {
166
+ ips := []string {}
167
+ var api string
168
+ for j , a := range node .peerConfig .GetAllowedIPs () {
169
+ if j == len (node .peerConfig .GetAllowedIPs ()) - 1 {
170
+ api = a .IP .String ()
171
+ } else {
172
+ ips = append (ips , a .String ())
173
+ }
174
+ }
175
+
176
+ t = tree .NewTree (tree .NodeString (fmt .Sprintf (`server
177
+
178
+ nickname: %v
179
+ e2ee: %v...
180
+ api: %v
181
+ routes: %v
182
+
183
+ error: %v` , node .peerConfig .GetNickname (), node .peerConfig .GetPublicKey ().String ()[:8 ], api , strings .Join (ips , "," ), errorWrap (node .error , 80 ))))
184
+ fmt .Fprintln (color .Output , WhiteBold (t ))
185
+ }
186
+ }
187
+ }
188
+
189
+ func errorWrap (text string , lineWidth int ) string {
190
+ words := strings .Fields (strings .TrimSpace (text ))
191
+ if len (words ) == 0 {
192
+ return text
193
+ }
194
+ wrapped := words [0 ]
195
+ spaceLeft := lineWidth - len (wrapped )
196
+ indent := len (" error: " )
197
+ for _ , word := range words [1 :] {
198
+ if len (word )+ 1 > spaceLeft {
199
+ wrapped += " \n " + strings .Repeat (" " , indent ) + word
200
+ spaceLeft = lineWidth - len (word )
201
+ } else {
202
+ wrapped += " " + word
203
+ spaceLeft -= 1 + len (word )
204
+ }
205
+ }
206
+
207
+ return wrapped
154
208
}
0 commit comments