KeepAlive WIP. TODO: check exitStatus logic for shell 'exit' clean exit

This commit is contained in:
Russ Magee 2023-11-05 18:48:19 -08:00
parent d0f8751b2b
commit 9244cc9785
3 changed files with 10 additions and 10 deletions

View File

@ -1005,7 +1005,7 @@ func main() { //nolint: funlen, gocyclo
loginTimeout := time.AfterFunc(30*time.Second, func() { //nolint:gomnd
restoreTermState(oldState)
fmt.Printf(" .. [login timeout]\n")
exitWithStatus(xsnet.CSOLoginTimeout)
exitWithStatus(xsnet.CSELoginTimeout)
})
if authCookie == "" {
@ -1152,5 +1152,6 @@ func exitWithStatus(status int) {
}
}
fmt.Printf("[exitStatus:%d]\n", status)
os.Exit(status)
}

View File

@ -53,6 +53,7 @@ const (
CSECipherAlgDenied // server rejected proposed Cipher alg
CSEHMACAlgDenied // server rejected proposed HMAC alg
CSEConnDead // connection keepalives expired
CSELoginTimeout
)
// Extended (>255 UNIX exit status) codes
@ -68,9 +69,6 @@ const (
CSOExitStatus // Remote cmd exit status
CSOChaff // Dummy packet, do not pass beyond decryption
// Client side errors
CSOLoginTimeout
// Tunnel setup/control/status
CSOTunSetup // client -> server tunnel setup request (dstport)
CSOTunSetupAck // server -> client tunnel setup ack

View File

@ -1196,7 +1196,7 @@ func (hl *HKExListener) Accept() (hc Conn, err error) {
// packet processing.
//
// See go doc io.Reader
func (hc Conn) Read(b []byte) (n int, err error) {
func (hc *Conn) Read(b []byte) (n int, err error) {
for {
if hc.dBuf.Len() > 0 {
break
@ -1214,7 +1214,8 @@ func (hc Conn) Read(b []byte) (n int, err error) {
return 0, io.EOF
}
if strings.HasSuffix(err.Error(), "use of closed network connection") {
logger.LogDebug(fmt.Sprintln("[Client hung up]"))
logger.LogDebug(fmt.Sprintln("[Client hung up(1)]"))
//!rlm hc.SetStatus(CSENone) //FIXME: re-examine this (exit 9 w/o it - 2023-11-05)
return 0, io.EOF
}
etxt := fmt.Sprintf("** Failed read:%s (%s) **", "ctrlStatOp", err)
@ -1237,7 +1238,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
return 0, io.EOF
}
if strings.HasSuffix(err.Error(), "use of closed network connection") {
logger.LogDebug(fmt.Sprintln("[Client hung up]"))
logger.LogDebug(fmt.Sprintln("[Client hung up(2)]"))
return 0, io.EOF
}
etxt := fmt.Sprintf("** Failed read:%s (%s) **", "HMAC", err)
@ -1253,7 +1254,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
return 0, io.EOF
}
if strings.HasSuffix(err.Error(), "use of closed network connection") {
logger.LogDebug(fmt.Sprintln("[Client hung up]"))
logger.LogDebug(fmt.Sprintln("[Client hung up(3)]"))
return 0, io.EOF
}
etxt := fmt.Sprintf("** Failed read:%s (%s) **", "payloadLen", err)
@ -1276,7 +1277,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
return 0, io.EOF
}
if strings.HasSuffix(err.Error(), "use of closed network connection") {
logger.LogDebug(fmt.Sprintln("[Client hung up]"))
logger.LogDebug(fmt.Sprintln("[Client hung up(4)]"))
return 0, io.EOF
}
etxt := fmt.Sprintf("** Failed read:%s (%s) **", "payloadBytes", err)
@ -1647,7 +1648,7 @@ func (hc *Conn) keepaliveHelper() {
}
time.Sleep(time.Duration(nextDuration) * time.Millisecond)
hc.keepalive -= 1
logger.LogDebug(fmt.Sprintf("[keepAlive is now %d]\n", hc.keepalive))
//if rand.Intn(32) == 0 {
// hc.keepalive = 0
//}