Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(walletshield): add params for timeout and probe delay #88

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/walletshield/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

Expand All @@ -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")
Expand All @@ -79,6 +80,8 @@ 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.IntVar(&timeout, "timeout", timeout, "seconds to wait for a request")
flag.Parse()

if listenAddr == "" && !testProbe {
Expand Down Expand Up @@ -139,7 +142,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)
Expand Down Expand Up @@ -217,7 +220,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)
Expand Down Expand Up @@ -265,6 +268,6 @@ func (s *Server) SendTestProbes(d time.Duration, testProbeCount int, testProbeRe
os.Exit(0)
}

time.Sleep(d)
time.Sleep(time.Duration(testProbeSendDelay) * time.Second)
}
}