diff --git a/net.go b/net.go index e59ce2a..d8e619e 100644 --- a/net.go +++ b/net.go @@ -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() diff --git a/servermanager.go b/servermanager.go index e71189c..79c55c0 100644 --- a/servermanager.go +++ b/servermanager.go @@ -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 }