Add keepalive message to port forwarder

This commit is contained in:
Gary Talent 2017-01-27 15:28:16 -06:00
parent 913f70a2af
commit 2f105fa6b5
2 changed files with 12 additions and 5 deletions

13
net.go
View File

@ -11,6 +11,7 @@ import (
"io"
"log"
"net"
"time"
)
const (
@ -35,12 +36,18 @@ func portForward(wanConn *net.TCPConn, lanIp, port string, connStatus chan ConnS
go forwardConn(wanConn, lanConn, done)
go forwardConn(lanConn, wanConn, done)
ticker := time.NewTicker(time.Minute * 1)
for i := 0; i < 2; i++ {
err = <-done
if err != nil {
log.Print("Proxy:", err)
select {
case err = <-done:
if err != nil {
log.Print("Proxy:", err)
}
case <-ticker.C:
connStatus <- ConnStatus{Status: CONN_ACTIVE}
}
}
ticker.Stop()
wanConn.Close()
lanConn.Close()

View File

@ -38,7 +38,6 @@ type ServerManager struct {
done chan interface{}
connStatus chan ConnStatus
lastKeepAliveTime time.Time
usageScore int // spin down server when this reaches 0
server ServerHandler
}
@ -49,7 +48,6 @@ func NewServerManager(name string, server ServerHandler, settings Settings) *Ser
sm.ports = settings.Servers[name].Ports
sm.in = make(chan serverManagerEvent)
sm.done = make(chan interface{})
sm.usageScore = 5
sm.server = server
return sm
@ -80,6 +78,8 @@ func (me *ServerManager) Serve() {
}
}
ticker.Stop()
// notify done
me.done <- 42
}