Added Noise upgrade handler and Noise mux

This commit is contained in:
Juan Font Alonso
2022-06-11 19:08:35 +02:00
parent 304987b4ff
commit b40b4e8d45
2 changed files with 142 additions and 1 deletions

18
app.go
View File

@@ -79,7 +79,7 @@ type Headscale struct {
privateKey *key.MachinePrivate
noisePrivateKey *key.MachinePrivate
noiseRouter *gin.Engine
noiseMux *http.ServeMux
DERPMap *tailcfg.DERPMap
DERPServer *DERPServer
@@ -406,6 +406,7 @@ func (h *Headscale) createPrometheusRouter() *gin.Engine {
func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *gin.Engine {
router := gin.Default()
router.POST(ts2021UpgradePath, h.NoiseUpgradeHandler)
router.GET(
"/health",
func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"healthy": "ok"}) },
@@ -440,6 +441,15 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *gin.Engine {
return router
}
func (h *Headscale) createNoiseMux() *http.ServeMux {
mux := http.NewServeMux()
// mux.HandleFunc("/machine/register", h.NoiseRegistrationHandler)
// mux.HandleFunc("/machine/map", h.NoisePollNetMapHandler)
return mux
}
// Serve launches a GIN server with the Headscale API.
func (h *Headscale) Serve() error {
var err error
@@ -592,8 +602,14 @@ func (h *Headscale) Serve() error {
// HTTP setup
//
// This is the regular router that we expose
// over our main Addr. It also serves the legacy Tailcale API
router := h.createRouter(grpcGatewayMux)
// This router is served only over the Noise connection,
// and exposes only the new API
h.noiseMux = h.createNoiseMux()
httpServer := &http.Server{
Addr: h.cfg.Addr,
Handler: router,