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

View File

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