From 50bb1277fc784c05532a8e4527b0fee105ee9a46 Mon Sep 17 00:00:00 2001 From: Aptimex Date: Sat, 6 Jul 2024 17:42:32 -0600 Subject: [PATCH 1/3] status command: faster timeout and show partial data --- src/api/api.go | 3 ++- src/cmd/status.go | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) mode change 100644 => 100755 src/api/api.go mode change 100644 => 100755 src/cmd/status.go diff --git a/src/api/api.go b/src/api/api.go old mode 100644 new mode 100755 index b7adadc..e1d85ef --- a/src/api/api.go +++ b/src/api/api.go @@ -11,6 +11,7 @@ import ( "net/http" "net/netip" "strings" + "time" "wiretap/peer" serverapi "wiretap/transport/api" @@ -27,7 +28,7 @@ type request struct { // MakeRequest attempts to send an API query to the Wiretap server. func makeRequest(req request) ([]byte, error) { - client := &http.Client{} + client := &http.Client{Timeout: 3 * time.Second} reqBody := bytes.NewBuffer(req.Body) r, err := http.NewRequest(req.Method, req.URL, reqBody) diff --git a/src/cmd/status.go b/src/cmd/status.go old mode 100644 new mode 100755 index b2b2484..e97d157 --- a/src/cmd/status.go +++ b/src/cmd/status.go @@ -4,6 +4,7 @@ import ( "fmt" "net/netip" "strings" + "log" "github.com/fatih/color" "github.com/m1gwings/treedrawer/tree" @@ -77,11 +78,20 @@ func (c statusCmdConfig) Run() { e2ee_peer_list := clientConfigE2EE.GetPeers() for _, ep := range e2ee_peer_list { relayConfig, e2eeConfig, err := api.ServerInfo(netip.AddrPortFrom(ep.GetApiAddr(), uint16(ApiPort))) - check("failed to fetch node's configuration as peer", err) - nodes[relayConfig.GetPublicKey()] = Node{ - peerConfig: ep, - relayConfig: relayConfig, - e2eeConfig: e2eeConfig, + if err != nil { + message := "failed to fetch node's configuration as peer" + log.Printf("%s: %v", message, err) + nodes["TIMEOUT"] = Node{ + peerConfig: ep, + relayConfig: relayConfig, + e2eeConfig: e2eeConfig, + } + } else { + nodes[relayConfig.GetPublicKey()] = Node{ + peerConfig: ep, + relayConfig: relayConfig, + e2eeConfig: e2eeConfig, + } } } @@ -111,8 +121,8 @@ func (c statusCmdConfig) Run() { // Use node tree to build diagram tree. t.AddChild(tree.NodeString(fmt.Sprintf(`client - relay: %v... - e2ee: %v... + relay: %v... + e2ee: %v... `, client.relayConfig.GetPublicKey()[:8], client.e2eeConfig.GetPublicKey()[:8]))) // Closest peers should be at the top @@ -129,10 +139,10 @@ func (c statusCmdConfig) Run() { } } t.AddChild(tree.NodeString(fmt.Sprintf(`server - relay: %v... - e2ee: %v... + relay: %v... + e2ee: %v... - api: %v + api: %v routes: %v `, c.relayConfig.GetPublicKey()[:8], c.e2eeConfig.GetPublicKey()[:8], api, strings.Join(ips, ",")))) child, err := t.Child(0) check("could not build tree", err) From f91e9f4d1a2529d9368e121ef0b16fef1644f683 Mon Sep 17 00:00:00 2001 From: Aptimex Date: Thu, 18 Jul 2024 16:49:12 -0600 Subject: [PATCH 2/3] undo file perm changes; undo whitespace removal --- src/api/api.go | 0 src/cmd/status.go | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) mode change 100755 => 100644 src/api/api.go mode change 100755 => 100644 src/cmd/status.go diff --git a/src/api/api.go b/src/api/api.go old mode 100755 new mode 100644 diff --git a/src/cmd/status.go b/src/cmd/status.go old mode 100755 new mode 100644 index e97d157..753e227 --- a/src/cmd/status.go +++ b/src/cmd/status.go @@ -121,8 +121,8 @@ func (c statusCmdConfig) Run() { // Use node tree to build diagram tree. t.AddChild(tree.NodeString(fmt.Sprintf(`client - relay: %v... - e2ee: %v... + relay: %v... + e2ee: %v... `, client.relayConfig.GetPublicKey()[:8], client.e2eeConfig.GetPublicKey()[:8]))) // Closest peers should be at the top @@ -139,10 +139,10 @@ func (c statusCmdConfig) Run() { } } t.AddChild(tree.NodeString(fmt.Sprintf(`server - relay: %v... - e2ee: %v... + relay: %v... + e2ee: %v... - api: %v + api: %v routes: %v `, c.relayConfig.GetPublicKey()[:8], c.e2eeConfig.GetPublicKey()[:8], api, strings.Join(ips, ",")))) child, err := t.Child(0) check("could not build tree", err) From 1a7dadb10635dcdee34382529167a6574261222e Mon Sep 17 00:00:00 2001 From: Aptimex Date: Wed, 24 Jul 2024 15:42:25 -0600 Subject: [PATCH 3/3] removed useless nodes[] addition --- src/cmd/status.go | 5 ----- 1 file changed, 5 deletions(-) mode change 100644 => 100755 src/cmd/status.go diff --git a/src/cmd/status.go b/src/cmd/status.go old mode 100644 new mode 100755 index 753e227..b173317 --- a/src/cmd/status.go +++ b/src/cmd/status.go @@ -81,11 +81,6 @@ func (c statusCmdConfig) Run() { if err != nil { message := "failed to fetch node's configuration as peer" log.Printf("%s: %v", message, err) - nodes["TIMEOUT"] = Node{ - peerConfig: ep, - relayConfig: relayConfig, - e2eeConfig: e2eeConfig, - } } else { nodes[relayConfig.GetPublicKey()] = Node{ peerConfig: ep,