feat: add single tailnet support to moons (#8587)

This commit is contained in:
Colin Adler
2023-07-19 11:11:11 -05:00
committed by GitHub
parent cc8d0af027
commit 517fb19474
36 changed files with 1195 additions and 80 deletions

View File

@ -25,3 +25,24 @@ func Heartbeat(ctx context.Context, conn *websocket.Conn) {
}
}
}
// Heartbeat loops to ping a WebSocket to keep it alive. It kills the connection
// on ping failure.
func HeartbeatClose(ctx context.Context, exit func(), conn *websocket.Conn) {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
}
err := conn.Ping(ctx)
if err != nil {
_ = conn.Close(websocket.StatusGoingAway, "Ping failed")
exit()
return
}
}
}