Skip to content

Commit

Permalink
Merge pull request #88 from 0KnowledgeNetwork/misc
Browse files Browse the repository at this point in the history
feat(walletshield): add params for timeout and probe delay
  • Loading branch information
xendarboh authored Nov 27, 2024
2 parents db5cfda + 79d0897 commit cb94056
Showing 1 changed file with 8 additions and 5 deletions.
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)
}
}

0 comments on commit cb94056

Please sign in to comment.