mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
Made server keepalive ageing for tunnels to goroutine -- fix for premature tunnel collapses
Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
parent
54396a4e4b
commit
3ae48addbc
2 changed files with 31 additions and 9 deletions
|
@ -75,8 +75,9 @@ type (
|
|||
c *net.Conn // which also implements io.Reader, io.Writer, ...
|
||||
immClose bool
|
||||
|
||||
logCipherText bool // somewhat expensive, for debugging
|
||||
logPlainText bool // INSECURE and somewhat expensive, for debugging
|
||||
logCipherText bool // somewhat expensive, for debugging
|
||||
logPlainText bool // INSECURE and somewhat expensive, for debugging
|
||||
logTunActivity bool
|
||||
|
||||
cipheropts uint32 // post-KEx cipher/hmac options
|
||||
opts uint32 // post-KEx protocol options (caller-defined)
|
||||
|
@ -1112,8 +1113,11 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
|||
rport := binary.BigEndian.Uint16(payloadBytes[2:4])
|
||||
//fmt.Printf("[Got CSOTunData: [lport %d:rport %d] data:%v\n", lport, rport, payloadBytes[4:])
|
||||
if _, ok := (*hc.tuns)[rport]; ok {
|
||||
logger.LogDebug(fmt.Sprintf("[Writing data to rport [%d:%d]", lport, rport))
|
||||
if hc.logTunActivity {
|
||||
logger.LogDebug(fmt.Sprintf("[Writing data to rport [%d:%d]", lport, rport))
|
||||
}
|
||||
(*hc.tuns)[rport].Data <- payloadBytes[4:]
|
||||
(*hc.tuns)[rport].KeepAlive = 0
|
||||
} else {
|
||||
logger.LogDebug(fmt.Sprintf("[Attempt to write data to closed tun [%d:%d]", lport, rport))
|
||||
}
|
||||
|
|
|
@ -244,6 +244,24 @@ func (hc *Conn) StartServerTunnel(lport, rport uint16) {
|
|||
go func() {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
//
|
||||
// worker to age server tunnel and kill it if keepalives
|
||||
// stop from client
|
||||
//
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
(*hc.tuns)[rport].KeepAlive += 1
|
||||
if (*hc.tuns)[rport].KeepAlive > 25 {
|
||||
(*hc.tuns)[rport].Died = true
|
||||
logger.LogDebug("[ServerTun] worker A: Client died, hanging up.")
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for cmd := range (*hc.tuns)[rport].Ctl {
|
||||
var c net.Conn
|
||||
logger.LogDebug(fmt.Sprintf("[ServerTun] got Ctl '%c'.", cmd))
|
||||
|
@ -330,12 +348,12 @@ func (hc *Conn) StartServerTunnel(lport, rport uint16) {
|
|||
hc.WritePacket(rBuf[:n+4], CSOTunData)
|
||||
}
|
||||
|
||||
if (*hc.tuns)[rport].KeepAlive > 50 {
|
||||
(*hc.tuns)[rport].Died = true
|
||||
logger.LogDebug("[ServerTun] worker A: Client died, hanging up.")
|
||||
} else {
|
||||
(*hc.tuns)[rport].KeepAlive += 1
|
||||
}
|
||||
//if (*hc.tuns)[rport].KeepAlive > 50000 {
|
||||
// (*hc.tuns)[rport].Died = true
|
||||
// logger.LogDebug("[ServerTun] worker A: Client died, hanging up.")
|
||||
//} else {
|
||||
// (*hc.tuns)[rport].KeepAlive += 1
|
||||
//}
|
||||
|
||||
}
|
||||
logger.LogDebug("[ServerTun] worker A: exiting")
|
||||
|
|
Loading…
Reference in a new issue