Skip to content

Commit

Permalink
add ipv6 servers to all zones
Browse files Browse the repository at this point in the history
  • Loading branch information
daerSeebaer committed Jul 16, 2024
1 parent f701f1b commit 03e0ce8
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions lib/NP/Model/DnsRoot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,72 +110,72 @@ sub populate_country_zones {
$name = '' if $name eq '@';
$name = "$name." if $name;

if (my $entries = $zone->active_servers('v4')) {

my $min_non_duplicate_size = 2;
my $response_records = 3;
my @zones = ("0.", "1.", "2.", "3.");
my $zone_count = scalar @zones;

# add all servers to the non-numbered "NTP" zone
(my $pgeodns_group = "${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{a}}, $_ for @$entries;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
my @ip_versions = ('v4', 'v6');
my %record_types = (v4 => 'a',
v6 => 'aaaa');

$min_non_duplicate_size = int(@$entries / $zone_count)
if (@$entries / $zone_count > $min_non_duplicate_size);
foreach my $ip_version (@ip_versions) {

# print $fh "# " . scalar @$entries . " active servers in ", $zone->name, "\n";
my $record_type = $record_types{$ip_version};

if ($#$entries < ($min_non_duplicate_size * $zone_count - 1)) {
if (my $entries = $zone->active_servers($ip_version)) {

# possible duplicates, not enough servers
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
my $min_non_duplicate_size = 2;
my $response_records = 3;
my @zones = ("0.", "1.", "2.", "3.");
my $zone_count = scalar @zones;

# already has an alias, so don't add more data
if ($data->{$pgeodns_group}->{alias}) {
next;
}
# add all servers to the non-numbered "NTP" zone
(my $pgeodns_group = "${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{$record_type}}, $_ for @$entries;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}

$data->{$pgeodns_group}->{a} = [];
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
@$entries = shuffle(@$entries);
foreach my $e (@$entries) {
push @{$data->{$pgeodns_group}->{a}}, $e;
$min_non_duplicate_size = int(@$entries / $zone_count)
if (@$entries / $zone_count > $min_non_duplicate_size);

# print $fh "# " . scalar @$entries . " active servers in ", $zone->name, "\n";

if ($#$entries < ($min_non_duplicate_size * $zone_count - 1)) {

# possible duplicates, not enough servers
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;

# already has an alias, so don't add more data
if ($data->{$pgeodns_group}->{alias}) {
next;
}

$data->{$pgeodns_group}->{$record_type} = [];
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
@$entries = shuffle(@$entries);
foreach my $e (@$entries) {
push @{$data->{$pgeodns_group}->{$record_type}}, $e;
}
}
}
}
else {

# 'big' zone without duplicates
@$entries = shuffle(@$entries);
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{a} = [];
for (my $i = 0; $i < $min_non_duplicate_size; $i++) {
my $e = shift @$entries;
push @{$data->{$pgeodns_group}->{a}}, $e;
else {

# 'big' zone without duplicates
@$entries = shuffle(@$entries);
foreach my $z (@zones) {
(my $pgeodns_group = "$z${name}") =~ s/\.$//;
if ($ttl) {
$data->{$pgeodns_group}->{ttl} = $ttl;
}
$data->{$pgeodns_group}->{$record_type} = [];
for (my $i = 0; $i < $min_non_duplicate_size; $i++) {
my $e = shift @$entries;
push @{$data->{$pgeodns_group}->{$record_type}}, $e;
}
}
}
}
}

if (my $entries = $zone->active_servers('v6')) {
@$entries = shuffle(@$entries);

# for now just put all IPv6 servers in the '2' zone
(my $pgeodns_group = "2.${name}") =~ s/\.$//;
push @{$data->{$pgeodns_group}->{aaaa}}, $_ for @$entries;
}

}
}

Expand Down

0 comments on commit 03e0ce8

Please sign in to comment.