--- loncom/lonnet/perl/lonnet.pm 2007/03/28 00:12:58 1.852 +++ loncom/lonnet/perl/lonnet.pm 2007/04/03 00:49:14 1.857 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.852 2007/03/28 00:12:58 albertel Exp $ +# $Id: lonnet.pm,v 1.857 2007/04/03 00:49:14 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -145,12 +145,12 @@ sub logperm { } sub create_connection { - my ($server) = @_; + my ($hostname,$lonid) = @_; my $client=IO::Socket::UNIX->new(Peer => $perlvar{'lonSockCreate'}, Type => SOCK_STREAM, Timeout => 10); return 0 if (!$client); - print $client ("$server\n"); + print $client (join(':',$hostname,$lonid,&machine_ids($lonid))."\n"); my $result = <$client>; chomp($result); return 1 if ($result eq 'done'); @@ -185,7 +185,7 @@ sub subreply { if($client) { last; # Connected! } else { - &create_connection(&hostname($server)); + &create_connection(&hostname($server),$server); } sleep(1); # Try again later if failed connection. } @@ -7426,7 +7426,11 @@ sub hreflocation { } sub current_machine_domains { - my $hostname=&hostname($perlvar{'lonHostID'}); + return &machine_domains(&hostname($perlvar{'lonHostID'})); +} + +sub machine_domains { + my ($hostname) = @_; my @domains; my %hostname = &all_hostnames(); while( my($id, $name) = each(%hostname)) { @@ -7439,7 +7443,12 @@ sub current_machine_domains { } sub current_machine_ids { - my $hostname=&hostname($perlvar{'lonHostID'}); + return &machine_ids(&hostname($perlvar{'lonHostID'})); +} + +sub machine_ids { + my ($hostname) = @_; + $hostname ||= &hostname($perlvar{'lonHostID'}); my @ids; my %hostname = &all_hostnames(); while( my($id, $name) = each(%hostname)) { @@ -7580,6 +7589,7 @@ sub goodbye { } BEGIN { + # ----------------------------------- Read loncapa.conf and loncapa_apache.conf unless ($readit) { { @@ -7752,6 +7762,8 @@ sub get_dns { { my %iphost; + my %name_to_ip; + my %lonid_to_ip; sub get_hosts_from_ip { my ($ip) = @_; my %iphosts = &get_iphost(); @@ -7760,10 +7772,23 @@ sub get_dns { } return; } + + sub get_host_ip { + my ($lonid) = @_; + if (exists($lonid_to_ip{$lonid})) { + return $lonid_to_ip{$lonid}; + } + my $name=&hostname($lonid); + my $ip = gethostbyname($name); + return if (!$ip || length($ip) ne 4); + $ip=inet_ntoa($ip); + $name_to_ip{$name} = $ip; + $lonid_to_ip{$lonid} = $ip; + return $ip; + } sub get_iphost { if (%iphost) { return %iphost; } - my %name_to_ip; my %hostname = &all_hostnames(); foreach my $id (keys(%hostname)) { my $name=$hostname{$id}; @@ -7779,6 +7804,7 @@ sub get_dns { } else { $ip = $name_to_ip{$name}; } + $lonid_to_ip{$id} = $ip; push(@{$iphost{$ip}},$id); } return %iphost;