From 9913e029ec08d46dd3d27cb5bd0c7a3270cd6a8f Mon Sep 17 00:00:00 2001 From: Xendarboh <1435589+xendarboh@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:12:52 -0800 Subject: [PATCH 1/2] feat(walletshield): add param to set probe send delay close #70 --- apps/walletshield/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/walletshield/main.go b/apps/walletshield/main.go index 112b10e..51c1e02 100644 --- a/apps/walletshield/main.go +++ b/apps/walletshield/main.go @@ -70,6 +70,7 @@ func main() { var testProbe bool var testProbeCount int var testProbeResponseDelay int + var testProbeSendDelay int flag.StringVar(&configPath, "config", "", "file path of the client configuration TOML file") flag.IntVar(&delayStart, "delay_start", 0, "max random seconds to delay start") @@ -79,6 +80,7 @@ func main() { flag.BoolVar(&testProbe, "probe", false, "send test probes instead of handling requests") flag.IntVar(&testProbeCount, "probe_count", 1, "number of test probes to send") flag.IntVar(&testProbeResponseDelay, "probe_response_delay", 0, "test probe response deplay") + flag.IntVar(&testProbeSendDelay, "probe_send_delay", 10, "test probe delay between probes") flag.Parse() if listenAddr == "" && !testProbe { @@ -139,7 +141,7 @@ func main() { } if testProbe { - server.SendTestProbes(10*time.Second, testProbeCount, testProbeResponseDelay) + server.SendTestProbes(testProbeSendDelay, testProbeCount, testProbeResponseDelay) } else { http.HandleFunc("/", server.Handler) err := http.ListenAndServe(listenAddr, nil) @@ -217,7 +219,7 @@ func (s *Server) Handler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, string(response.Payload)) } -func (s *Server) SendTestProbes(d time.Duration, testProbeCount int, testProbeResponseDelay int) { +func (s *Server) SendTestProbes(testProbeSendDelay int, testProbeCount int, testProbeResponseDelay int) { url := fmt.Sprintf("http://nowhere/_/probe/%d", testProbeResponseDelay) req, err := http.NewRequest("GET", url, nil) buf := new(bytes.Buffer) @@ -265,6 +267,6 @@ func (s *Server) SendTestProbes(d time.Duration, testProbeCount int, testProbeRe os.Exit(0) } - time.Sleep(d) + time.Sleep(time.Duration(testProbeSendDelay) * time.Second) } } From 79d0897bc0a8a808275fcc23e7678585c7e1b146 Mon Sep 17 00:00:00 2001 From: Xendarboh <1435589+xendarboh@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:36:22 -0800 Subject: [PATCH 2/2] feat(walletshield): add param to set context timeout close #71 --- apps/walletshield/main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/walletshield/main.go b/apps/walletshield/main.go index 51c1e02..ac73d9e 100644 --- a/apps/walletshield/main.go +++ b/apps/walletshield/main.go @@ -30,7 +30,7 @@ import ( ) var ( - timeout = time.Second * 45 + timeout = 20 // (default) context timeout ProxyHTTPService = "http_proxy" // Note: UserForwardPayloadLength should match the same value passed to genconfig. @@ -51,7 +51,7 @@ func sendRequest(thin *thin.ThinClient, payload []byte) ([]byte, error) { } nodeId := hash.Sum256(target.MixDescriptor.IdentityKey) - timeoutCtx, _ := context.WithTimeout(context.TODO(), timeout) + timeoutCtx, _ := context.WithTimeout(context.TODO(), time.Duration(timeout)*time.Second) return thin.BlockingSendMessage(timeoutCtx, payload, &nodeId, target.RecipientQueueID) } @@ -81,6 +81,7 @@ func main() { flag.IntVar(&testProbeCount, "probe_count", 1, "number of test probes to send") flag.IntVar(&testProbeResponseDelay, "probe_response_delay", 0, "test probe response deplay") flag.IntVar(&testProbeSendDelay, "probe_send_delay", 10, "test probe delay between probes") + flag.IntVar(&timeout, "timeout", timeout, "seconds to wait for a request") flag.Parse() if listenAddr == "" && !testProbe {