AC-MrGamoo
view release on metacpan or search on metacpan
lib/AC/MrGamoo/Kibitz/Peers.pm view on Meta::CPAN
}
################################################################
# pick best ip addr from array (ACPIPPort)
sub pick_best_addr_for_peer {
my $ipinfo = shift;
_nat_init() unless $natinit;
my $public;
my $private;
for my $i ( @$ipinfo ){
$public = $i unless $i->{natdom};
$private = $i if $i->{natdom} eq $natdom;
}
# prefer private addr if available (cheaper)
my $prefer = $private || $public;
return unless $prefer;
return ( inet_itoa($prefer->{ipv4}), $prefer->{port} );
}
sub _nat_init {
# determine my local NAT domain
my $nat = my_network_info();
lib/AC/MrGamoo/MySelf.pm view on Meta::CPAN
Note: map/reduce jobs are extremely network intensive. it is not
recommended to spread your servers out. you really want them all
plugged into one big switch. one big fast switch.
=head2 my_network_info
return information about the various networks this server has.
sub my_network_info {
my $public_ip = inet_ntoa(scalar gethostbyname(hostname()));
my $privat_ip = inet_ntoa(scalar gethostbyname('internal-' . hostname()));
return [
# use this IP for communication with servers this datacenter (same natdom)
{ ip => $privat_ip, natdom => my_datacenter() },
# otherwise use this IP
{ ip => $public_ip },
]
}
=head2 init
inialization function called at startup. typically used to lookup hostanmes, IP addresses,
and such and store them in variables to make the above functions faster.
my $HOSTNAME;
my $DOMAIN;
( run in 0.299 second using v1.01-cache-2.11-cpan-64827b87656 )