Skip to content

Commit

Permalink
Rename variables for custom DERP entry
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhalbi-a committed Nov 20, 2023
1 parent 6e734bc commit 46d2890
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ derp:

# For better connection stability (especially when using an Exit-Node and DNS is not working),
# it is possible to optionall add the public IPv4 and IPv6 address to the Derp-Map using:
IPv4: 1.2.3.4
IPv6: 2001:db8::1
ipv4: 1.2.3.4
ipv6: 2001:db8::1

# This flag can be used, so the DERP map entry for the embedded DERP server is not written automatically,
# it enables the creation of your very own DERP map entry using a locally available file with the parameter DERP.paths
# If you enable the DERP server and set this to true, it is required to add the DERP server to the DERP map using DERP.paths
manual_derp_map: false
# If you enable the DERP server and set this to false, it is required to add the DERP server to the DERP map using DERP.paths
automatically_add_embedded_derp_region: true

# List of externally available DERP maps encoded in JSON
urls:
Expand Down
4 changes: 2 additions & 2 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (h *Headscale) scheduledDERPMapUpdateWorker(cancelChan <-chan struct{}) {
case <-ticker.C:
log.Info().Msg("Fetching DERPMap updates")
h.DERPMap = derp.GetDERPMap(h.cfg.DERP)
if h.cfg.DERP.ServerEnabled && !h.cfg.DERP.ManualDerpMap {
if h.cfg.DERP.ServerEnabled && h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {
region, _ := h.DERPServer.GenerateRegion()
h.DERPMap.Regions[region.RegionID] = &region
}
Expand Down Expand Up @@ -499,7 +499,7 @@ func (h *Headscale) Serve() error {
return err
}

if !h.cfg.DERP.ManualDerpMap {
if h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {
h.DERPMap.Regions[region.RegionID] = &region
}

Expand Down
20 changes: 10 additions & 10 deletions hscontrol/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type OIDCConfig struct {

type DERPConfig struct {
ServerEnabled bool
ManualDerpMap bool
AutomaticallyAddEmbeddedDerpRegion bool
ServerRegionID int
ServerRegionCode string
ServerRegionName string
Expand Down Expand Up @@ -172,7 +172,7 @@ func LoadConfig(path string, isFile bool) error {

viper.SetDefault("derp.server.enabled", false)
viper.SetDefault("derp.server.stun.enabled", true)
viper.SetDefault("derp.server.manual_derp_map", false)
viper.SetDefault("derp.server.automatically_add_embedded_derp_region", true)

viper.SetDefault("unix_socket", "/var/run/headscale/headscale.sock")
viper.SetDefault("unix_socket_permission", "0o770")
Expand Down Expand Up @@ -290,9 +290,9 @@ func GetDERPConfig() DERPConfig {
serverRegionCode := viper.GetString("derp.server.region_code")
serverRegionName := viper.GetString("derp.server.region_name")
stunAddr := viper.GetString("derp.server.stun_listen_addr")
IPv4 := viper.GetString("derp.server.IPv4")
IPv6 := viper.GetString("derp.server.IPv6")
manual_derp_map := viper.GetBool("derp.server.manual_derp_map")
ipv4 := viper.GetString("derp.server.ipv4")
ipv6 := viper.GetString("derp.server.ipv6")
automatically_add_embedded_derp_region := viper.GetBool("derp.server.automatically_add_embedded_derp_region")

if serverEnabled && stunAddr == "" {
log.Fatal().
Expand All @@ -316,9 +316,9 @@ func GetDERPConfig() DERPConfig {

paths := viper.GetStringSlice("derp.paths")

if serverEnabled && manual_derp_map && len(paths) == 0 {
if serverEnabled && !automatically_add_embedded_derp_region && len(paths) == 0 {
log.Fatal().
Msg("Enabling derp.server.manual_derp_map requires to configure the derp server in derp.paths")
Msg("Disabling derp.server.automatically_add_embedded_derp_region requires to configure the derp server in derp.paths")
}

autoUpdate := viper.GetBool("derp.auto_update_enabled")
Expand All @@ -334,9 +334,9 @@ func GetDERPConfig() DERPConfig {
Paths: paths,
AutoUpdate: autoUpdate,
UpdateFrequency: updateFrequency,
IPv4: IPv4,
IPv6: IPv6,
ManualDerpMap: manual_derp_map,
IPv4: ipv4,
IPv6: ipv6,
AutomaticallyAddEmbeddedDerpRegion: automatically_add_embedded_derp_region,
}
}

Expand Down

0 comments on commit 46d2890

Please sign in to comment.