Tags: patch Here's the patch, as merged upstream.
-- Zen Fu
>From ea8e5dc25dfd4f86bd58c3d5b680d101071bf70b Mon Sep 17 00:00:00 2001 From: Nicola Taddei <[email protected]> Date: Wed, 13 May 2026 15:58:11 +0200 Subject: [PATCH] Allow Geographical Sorting to be disabled with this option, geoip is only used to *filter* which mirrors are eligible, but it isn't used to *rank* mirrors. Eligible mirrors (that is, mirrors which pass all filters, and are nearer than nearestMirror * WeightDistributionRange) are picked randomly, based on their Score only. --- config/config.go | 2 ++ http/selection.go | 61 ++++++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/config/config.go b/config/config.go index b09c4218..39a798f6 100644 --- a/config/config.go +++ b/config/config.go @@ -45,6 +45,7 @@ func defaultConfig() Configuration { LogDir: "", TraceFileLocation: "", GeoipDatabasePath: "/usr/share/GeoIP/", + GeographicalSort: true, ConcurrentSync: 5, ScanInterval: 30, CheckInterval: 1, @@ -80,6 +81,7 @@ type Configuration struct { LogDir string `yaml:"LogDir"` TraceFileLocation string `yaml:"TraceFileLocation"` GeoipDatabasePath string `yaml:"GeoipDatabasePath"` + GeographicalSort bool `yaml:"GeographicalSort"` ConcurrentSync int `yaml:"ConcurrentSync"` ScanInterval int `yaml:"ScanInterval"` CheckInterval int `yaml:"CheckInterval"` diff --git a/http/selection.go b/http/selection.go index ad312e55..97630832 100644 --- a/http/selection.go +++ b/http/selection.go @@ -83,33 +83,50 @@ func (h DefaultEngine) Selection(ctx *Context, cache *mirrors.Cache, fileInfo *f for i := 0; i < len(mlist); i++ { m := &mlist[i] - m.ComputedScore = baseScore - int(m.Distance) + 1 - - if m.Distance <= closestMirror*GetConfig().WeightDistributionRange { - score := (float32(baseScore) - m.Distance) - if !network.IsPrimaryCountry(clientInfo, m.CountryFields) { - score /= 2 - } - m.ComputedScore += int(score) - } else if network.IsPrimaryCountry(clientInfo, m.CountryFields) { - m.ComputedScore += int(float32(baseScore) - (m.Distance * 5)) - } else if network.IsAdditionalCountry(clientInfo, m.CountryFields) { - m.ComputedScore += int(float32(baseScore) - closestMirror) + if m.Distance > closestMirror*GetConfig().WeightDistributionRange { + log.Debugf("[%s] ignored: too far (%.1f; maximum: %.1f)", m.Name, m.Distance, closestMirror*GetConfig().WeightDistributionRange) + m.ComputedScore = 0 + continue } - if m.Asnum == clientInfo.ASNum { - m.ComputedScore += baseScore / 2 - } + if GetConfig().GeographicalSort { + m.ComputedScore = baseScore - int(m.Distance) + 1 + + if m.Distance <= closestMirror*GetConfig().WeightDistributionRange { + score := (float32(baseScore) - m.Distance) + if !network.IsPrimaryCountry(clientInfo, m.CountryFields) { + score /= 2 + m.ComputedScore += int(score) + } else if network.IsPrimaryCountry(clientInfo, m.CountryFields) { + m.ComputedScore += int(float32(baseScore) - (m.Distance * 5)) + } else if network.IsAdditionalCountry(clientInfo, m.CountryFields) { + m.ComputedScore += int(float32(baseScore) - closestMirror) + } + + if m.Asnum == clientInfo.ASNum { + m.ComputedScore += baseScore / 2 + } - floatingScore := float64(m.ComputedScore) + (float64(m.ComputedScore) * (float64(m.Score) / 100)) + 0.5 + floatingScore := float64(m.ComputedScore) + (float64(m.ComputedScore) * (float64(m.Score) / 100)) + 0.5 - // The minimum allowed score is 1 - m.ComputedScore = int(math.Max(floatingScore, 1)) + // The minimum allowed score is 1 + m.ComputedScore = int(math.Max(floatingScore, 1)) - if m.ComputedScore > baseScore { - // The weight must always be > 0 to not break the randomization below - totalScore += m.ComputedScore - baseScore - weights[m.ID] = m.ComputedScore - baseScore + if m.ComputedScore > baseScore { + // The weight must always be > 0 to not break the randomization below + totalScore += m.ComputedScore - baseScore + weights[m.ID] = m.ComputedScore - baseScore + } + } + } else { // GetConfig().GeographicalSort == false + if m.Score <= 0 { + m.ComputedScore = 0 + } else { + totalScore += m.Score + m.Weight = float32(m.Score) + m.ComputedScore = m.Score + weights[m.ID] = m.Score + } } }

