44 "fmt"
55 "net/netip"
66 "strings"
7- "log"
87
98 "github.com/fatih/color"
109 "github.com/m1gwings/treedrawer/tree"
@@ -54,6 +53,7 @@ func (c statusCmdConfig) Run() {
5453 relayConfig peer.Config
5554 e2eeConfig peer.Config
5655 children []* Node
56+ error string
5757 }
5858
5959 var err error
@@ -75,12 +75,16 @@ func (c statusCmdConfig) Run() {
7575 // Get map of all nodes for building tree.
7676 // Key on public key of relay interfaces.
7777 nodes := make (map [string ]Node )
78- e2ee_peer_list := clientConfigE2EE .GetPeers ()
78+ var errorNodes []Node
79+ e2ee_peer_list := client .e2eeConfig .GetPeers ()
7980 for _ , ep := range e2ee_peer_list {
8081 relayConfig , e2eeConfig , err := api .ServerInfo (netip .AddrPortFrom (ep .GetApiAddr (), uint16 (ApiPort )))
8182 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+
8488 } else {
8589 nodes [relayConfig .GetPublicKey ()] = Node {
8690 peerConfig : ep ,
@@ -127,7 +131,7 @@ func (c statusCmdConfig) Run() {
127131 ips := []string {}
128132 var api string
129133 for j , a := range c .peerConfig .GetAllowedIPs () {
130- if j == len (c .peerConfig .GetAllowedIPs ())- 1 {
134+ if j == len (c .peerConfig .GetAllowedIPs ()) - 1 {
131135 api = a .IP .String ()
132136 } else {
133137 ips = append (ips , a .String ())
@@ -149,6 +153,56 @@ func (c statusCmdConfig) Run() {
149153 check ("could not build tree" , err )
150154 treeTraversal (& client , child )
151155
152- fmt .Fprintln ( color . Output )
156+ fmt .Println ( )
153157 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
154208}
0 commit comments