mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-24 08:47:49 +00:00
Be consistent with uppercase DERP
This commit is contained in:
parent
23cde8445f
commit
607c1eb316
12
app.go
12
app.go
@ -144,7 +144,7 @@ type Headscale struct {
|
|||||||
privateKey *key.MachinePrivate
|
privateKey *key.MachinePrivate
|
||||||
|
|
||||||
DERPMap *tailcfg.DERPMap
|
DERPMap *tailcfg.DERPMap
|
||||||
EmbeddedDerpServer *EmbeddedDerpServer
|
EmbeddedDERPServer *EmbeddedDERPServer
|
||||||
|
|
||||||
aclPolicy *ACLPolicy
|
aclPolicy *ACLPolicy
|
||||||
aclRules []tailcfg.FilterRule
|
aclRules []tailcfg.FilterRule
|
||||||
@ -242,11 +242,11 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.DERP.EmbeddedDERP {
|
if cfg.DERP.EmbeddedDERP {
|
||||||
embeddedDerpServer, err := app.NewEmbeddedDerpServer()
|
embeddedDERPServer, err := app.NewEmbeddedDERPServer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
app.EmbeddedDerpServer = embeddedDerpServer
|
app.EmbeddedDERPServer = embeddedDERPServer
|
||||||
|
|
||||||
// If we are using the embedded DERP, there is no reason to use Tailscale's DERP infrastructure
|
// If we are using the embedded DERP, there is no reason to use Tailscale's DERP infrastructure
|
||||||
serverURL, err := url.Parse(app.cfg.ServerURL)
|
serverURL, err := url.Parse(app.cfg.ServerURL)
|
||||||
@ -496,9 +496,9 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *gin.Engine {
|
|||||||
router.GET("/swagger/v1/openapiv2.json", SwaggerAPIv1)
|
router.GET("/swagger/v1/openapiv2.json", SwaggerAPIv1)
|
||||||
|
|
||||||
if h.cfg.DERP.EmbeddedDERP {
|
if h.cfg.DERP.EmbeddedDERP {
|
||||||
router.Any("/derp", h.EmbeddedDerpHandler)
|
router.Any("/derp", h.EmbeddedDERPHandler)
|
||||||
router.Any("/derp/probe", h.EmbeddedDerpProbeHandler)
|
router.Any("/derp/probe", h.EmbeddedDERPProbeHandler)
|
||||||
router.Any("/bootstrap-dns", h.EmbeddedDerpBootstrapDNSHandler)
|
router.Any("/bootstrap-dns", h.EmbeddedDERPBootstrapDNSHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
api := router.Group("/api")
|
api := router.Group("/api")
|
||||||
|
@ -28,17 +28,17 @@ var (
|
|||||||
bootstrapDNS = "derp.tailscale.com"
|
bootstrapDNS = "derp.tailscale.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmbeddedDerpServer struct {
|
type EmbeddedDERPServer struct {
|
||||||
tailscaleDerp *derp.Server
|
tailscaleDERP *derp.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) NewEmbeddedDerpServer() (*EmbeddedDerpServer, error) {
|
func (h *Headscale) NewEmbeddedDERPServer() (*EmbeddedDERPServer, error) {
|
||||||
s := derp.NewServer(key.NodePrivate(*h.privateKey), log.Info().Msgf)
|
s := derp.NewServer(key.NodePrivate(*h.privateKey), log.Info().Msgf)
|
||||||
return &EmbeddedDerpServer{s}, nil
|
return &EmbeddedDERPServer{s}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) EmbeddedDerpHandler(ctx *gin.Context) {
|
func (h *Headscale) EmbeddedDERPHandler(ctx *gin.Context) {
|
||||||
up := strings.ToLower(ctx.Request.Header.Get("Upgrade"))
|
up := strings.ToLower(ctx.Request.Header.Get("Upgrade"))
|
||||||
if up != "websocket" && up != "derp" {
|
if up != "websocket" && up != "derp" {
|
||||||
if up != "" {
|
if up != "" {
|
||||||
@ -75,12 +75,12 @@ func (h *Headscale) EmbeddedDerpHandler(ctx *gin.Context) {
|
|||||||
pubKey.UntypedHexString())
|
pubKey.UntypedHexString())
|
||||||
}
|
}
|
||||||
|
|
||||||
h.EmbeddedDerpServer.tailscaleDerp.Accept(netConn, conn, netConn.RemoteAddr().String())
|
h.EmbeddedDERPServer.tailscaleDERP.Accept(netConn, conn, netConn.RemoteAddr().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmbeddedDerpProbeHandler is the endpoint that js/wasm clients hit to measure
|
// EmbeddedDERPProbeHandler is the endpoint that js/wasm clients hit to measure
|
||||||
// DERP latency, since they can't do UDP STUN queries.
|
// DERP latency, since they can't do UDP STUN queries.
|
||||||
func (h *Headscale) EmbeddedDerpProbeHandler(ctx *gin.Context) {
|
func (h *Headscale) EmbeddedDERPProbeHandler(ctx *gin.Context) {
|
||||||
switch ctx.Request.Method {
|
switch ctx.Request.Method {
|
||||||
case "HEAD", "GET":
|
case "HEAD", "GET":
|
||||||
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
@ -89,7 +89,7 @@ func (h *Headscale) EmbeddedDerpProbeHandler(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) EmbeddedDerpBootstrapDNSHandler(ctx *gin.Context) {
|
func (h *Headscale) EmbeddedDERPBootstrapDNSHandler(ctx *gin.Context) {
|
||||||
ctx.Header("Content-Type", "application/json")
|
ctx.Header("Content-Type", "application/json")
|
||||||
j, _ := dnsCache.Load().([]byte)
|
j, _ := dnsCache.Load().([]byte)
|
||||||
// Bootstrap DNS requests occur cross-regions,
|
// Bootstrap DNS requests occur cross-regions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user