Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func defaultConfig() Configuration {
LogDir: "",
TraceFileLocation: "",
GeoipDatabasePath: "/usr/share/GeoIP/",
GeographicalSort: true,
ConcurrentSync: 5,
ScanInterval: 30,
CheckInterval: 1,
Expand Down Expand Up @@ -81,6 +82,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"`
Expand Down
61 changes: 39 additions & 22 deletions http/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
Loading