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

gh-276 req/resp check for connect liveness check #10

Merged
merged 1 commit into from
May 15, 2023
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
22 changes: 21 additions & 1 deletion serviceprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package loxilib

import (
"bytes"
"github.com/loxilb-io/sctp"
"net"
"net/http"
Expand All @@ -26,8 +27,10 @@ func HTTPProber(urls string) bool {
// sType is "tcp" or "udp" or "sctp"
// sName is end-point IP address in string format
// sHint is source address hint if any
// req is the request to be made to server (empty for none)
// resp is the response expected from server (empty for none)
// returns true/false depending on whether probing was successful
func L4ServiceProber(sType string, sName string, sHint string) bool {
func L4ServiceProber(sType string, sName string, sHint, req, resp string) bool {
sOk := false
timeout := 1 * time.Second

Expand Down Expand Up @@ -93,5 +96,22 @@ func L4ServiceProber(sType string, sName string, sHint string) bool {
defer c.Close()
}

if req != "" && resp != "" {
c.SetDeadline(time.Now().Add(2 * time.Second))
_, err = c.Write([]byte(req))
if err != nil {
return false
}
aRb := []byte(resp)
rRb := []byte(resp)
_, err = c.Read(aRb)
if err != nil {
return false
}
if !bytes.Equal(aRb, rRb) {
return false
}
}

return sOk
}