mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-19 11:57:07 +09:00
feat: add DERPHomeParams settings
This commit is contained in:
1 parent
f2a9b71d50
commit
0f2e68fd1d
1 file changed
+10
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user