summaryrefslogtreecommitdiffstats
path: root/perl-install/crypto.pm
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2002-01-07 18:22:33 +0000
committerFrancois Pons <fpons@mandriva.com>2002-01-07 18:22:33 +0000
commit9177dce7f6cfbff349253c02e67df3733d8c4c50 (patch)
treee17f81bf0cbf187abcc894603d144b46b6e28d48 /perl-install/crypto.pm
parentcebf60005f12633de1986f7389f4af96e5c6d142 (diff)
downloaddrakx-9177dce7f6cfbff349253c02e67df3733d8c4c50.tar
drakx-9177dce7f6cfbff349253c02e67df3733d8c4c50.tar.gz
drakx-9177dce7f6cfbff349253c02e67df3733d8c4c50.tar.bz2
drakx-9177dce7f6cfbff349253c02e67df3733d8c4c50.tar.xz
drakx-9177dce7f6cfbff349253c02e67df3733d8c4c50.zip
added bestMirror method to retrieve a good mirror (according to timezone) and
add salt with random number to avoid using always the same.
Diffstat (limited to 'perl-install/crypto.pm')
-rw-r--r--perl-install/crypto.pm45
1 files changed, 40 insertions, 5 deletions
diff --git a/perl-install/crypto.pm b/perl-install/crypto.pm
index 749538bab..4d9033e28 100644
--- a/perl-install/crypto.pm
+++ b/perl-install/crypto.pm
@@ -8,7 +8,7 @@ use common;
use log;
use ftp;
-my %url2lang = (
+my %url2land = (
fr => _("France"),
cr => _("Costa Rica"),
be => _("Belgium"),
@@ -19,6 +19,17 @@ my %url2lang = (
se => _("Sweden"),
);
+my %land2tzs = (
+ _("France") => [ 'Europe/Paris', 'Europe/Brussels', 'Europe/Berlin' ],
+ _("Belgium") => [ 'Europe/Brussels', 'Europe/Paris', 'Europe/Berlin' ],
+ _("Czech Republic") => [ 'Europe/Prague', 'Europe/Berlin' ],
+ _("Germany") => [ 'Europe/Berlin', 'Europe/Prague' ],
+ _("Grece") => [ 'Europe/Athens', 'Europe/Prague' ],
+ _("Norway") => [ 'Europe/Oslo', 'Europe/Stockholm' ],
+ _("Sweden") => [ 'Europe/Stockholm', 'Europe/Oslo' ],
+ _("United States") => [ 'America/New_York', 'Canada/Atlantic', 'Asia/Tokyo', 'Australia/Sydney', 'Europe/Paris' ],
+ );
+
my %static_mirrors = (
# "ackbar" => [ "Ackbar", "/updates", "a", "a" ],
);
@@ -44,12 +55,12 @@ sub mirrors {
my ($arch, $url, $dir) = m|updates([^:]*):ftp://([^/]*)(/\S*)| or next;
MDK::Common::System::compat_arch($arch) or
log::l("ignoring updates from $url because of incompatible arch: $arch"), next;
- my $lang = _("United States");
- foreach (keys %url2lang) {
+ my $land = _("United States");
+ foreach (keys %url2land) {
my $qu = quotemeta $_;
- $url =~ /\.$qu(?:\..*)?$/ and $lang = $url2lang{$_};
+ $url =~ /\.$qu(?:\..*)?$/ and $land = $url2land{$_};
}
- $mirrors{$url} = [ $lang, $dir ];
+ $mirrors{$url} = [ $land, $dir ];
}
http::getFile('/XXX'); #- close connection.
@@ -59,6 +70,30 @@ sub mirrors {
keys %mirrors;
}
+sub bestMirror {
+ my ($string) = @_;
+ my %mirror2value;
+
+ foreach my $url (mirrors()) {
+ my $value = 0;
+ my $cvalue = mirrors();
+
+ $mirror2value{$url} ||= 1 + $cvalue;
+ foreach (@{$land2tzs{$mirrors{$url}[0]} || []}) {
+ $_ eq $string and $mirror2value{$url} > $value and $mirror2value{$url} = $value;
+ (split '/')[0] eq (split '/', $string)[0] and $mirror2value{$url} > $cvalue and $mirror2value{$url} = $cvalue;
+ ++$value;
+ }
+ }
+ my ($min_value) = sort { $a <=> $b } values %mirror2value;
+
+ my @possible = grep { $mirror2value{$_} == $min_value } keys %mirror2value;
+ push @possible, grep { $mirror2value{$_} == $min_value } keys %mirror2value;
+ push @possible, grep { $mirror2value{$_} == 1 + $min_value } keys %mirror2value;
+
+ $possible[rand @possible];
+}
+
#sub dir { $mirrors{$_[0]}[1] . '/' . $::VERSION }
sub dir { $mirrors{$_[0]}[1] . '/' . '8.1' }
sub ftp($) { ftp::new($_[0], dir($_[0])) }