Fix: Randomize source URLs (#1593)

This commit is contained in:
lifenjoiner 2021-01-22 22:06:49 +08:00 committed by GitHub
parent 0ab9e30fa9
commit a9cf16b33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -788,6 +788,9 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) erro
func (config *Config) loadSources(proxy *Proxy) error {
for cfgSourceName, cfgSource_ := range config.SourcesConfig {
cfgSource := cfgSource_
rand.Shuffle(len(cfgSource.URLs), func(i, j int) {
cfgSource.URLs[i], cfgSource.URLs[j] = cfgSource.URLs[j], cfgSource.URLs[i]
})
if err := config.loadSource(proxy, cfgSourceName, &cfgSource); err != nil {
return err
}

View File

@ -197,9 +197,6 @@ func NewSource(name string, xTransport *XTransport, urls []string, minisignKeySt
return source, err
}
source.parseURLs(urls)
rand.Shuffle(len(source.urls), func(i, j int) {
source.urls[i], source.urls[j] = source.urls[j], source.urls[i]
})
if _, err = source.fetchWithCache(xTransport, timeNow()); err == nil {
dlog.Noticef("Source [%s] loaded", name)
}