Add keepalive message to port forwarder
This commit is contained in:
parent
913f70a2af
commit
2f105fa6b5
13
net.go
13
net.go
@ -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()
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user