feat: add DERPHomeParams settings

This commit is contained in:
Samy Djemaï authored and Kristoffer Dalby committed 2026-11-05 14:11:33 +01:00
1 parent f2a9b71d50
commit 0f2e68fd1d
1 file changed
+10
+10
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"hash/crc64"
"io"
"maps"
"math/rand"
"net/http"
"net/url"
@@ -80,10 +81,13 @@ func loadDERPMapFromURL(addr url.URL) (*tailcfg.DERPMap, error) {
func mergeDERPMaps(derpMaps []*tailcfg.DERPMap) *tailcfg.DERPMap {
result := tailcfg.DERPMap{
OmitDefaultRegions: false,
HomeParams: &tailcfg.DERPHomeParams{},
Regions: map[tailcfg.DERPRegionID]*tailcfg.DERPRegion{},
}
for _, derpMap := range derpMaps {
maps.Copy(result.HomeParams.RegionScore, derpMap.HomeParams.RegionScore)
// Clone each region: copying the pointer would let a later in-place
// shuffle alias regions shared with the source map or a previously
// served map, racing concurrent readers.
@@ -99,6 +103,12 @@ func mergeDERPMaps(derpMaps []*tailcfg.DERPMap) *tailcfg.DERPMap {
}
}
for id, regionScore := range result.HomeParams.RegionScore {
if regionScore <= 0 {
delete(result.HomeParams.RegionScore, id)
}
}
return &result
}