--- loncom/LondConnection.pm 2006/09/15 20:49:24 1.43 +++ loncom/LondConnection.pm 2007/03/28 20:28:29 1.44 @@ -1,7 +1,7 @@ # This module defines and implements a class that represents # a connection to a lond daemon. # -# $Id: LondConnection.pm,v 1.43 2006/09/15 20:49:24 raeburn Exp $ +# $Id: LondConnection.pm,v 1.44 2007/03/28 20:28:29 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,9 +43,7 @@ use LONCAPA::lonssl; my $DebugLevel=0; -my %hostshash; my %perlvar; -my $LocalDns = ""; # Need not be defined for managers. my $InsecureOk; # @@ -71,67 +69,9 @@ sub ReadConfig { my $perlvarref = read_conf('loncapa.conf'); %perlvar = %{$perlvarref}; - my $hoststab = read_hosts( - "$perlvar{lonTabDir}/hosts.tab") || - die "Can't read host table!!"; - %hostshash = %{$hoststab}; $ConfigRead = 1; - my $myLonCapaName = $perlvar{lonHostID}; - Debug(8, "My loncapa name is $myLonCapaName"); - - if(defined $hostshash{$myLonCapaName}) { - Debug(8, "My loncapa name is in hosthash"); - my @ConfigLine = @{$hostshash{$myLonCapaName}}; - $LocalDns = $ConfigLine[3]; - Debug(8, "Got local name $LocalDns"); - } $InsecureOk = $perlvar{loncAllowInsecure}; - - Debug(3, "ReadConfig - LocalDNS = $LocalDns"); -} - -# -# Read a foreign configuration. -# This sub is intended for the cases where the package -# will be read from outside the LonCAPA environment, in that case -# the client will need to explicitly provide: -# - A file in hosts.tab format. -# - Some idea of the 'lonCAPA' name of the local host (for building -# the encryption key). -# -# Parameters: -# MyHost - Name of this host as far as LonCAPA is concerned. -# Filename - Name of a hosts.tab formatted file that will be used -# to build up the hosts table. -# -sub ReadForeignConfig { - - my ($MyHost, $Filename) = @_; - - &Debug(4, "ReadForeignConfig $MyHost $Filename\n"); - - $perlvar{lonHostID} = $MyHost; # Rmember my host. - my $hosttab = read_hosts($Filename) || - die "Can't read hosts table!!"; - %hostshash = %{$hosttab}; - if($DebugLevel > 3) { - foreach my $host (keys %hostshash) { - print STDERR "host $host => $hostshash{$host}\n"; - } - } - $ConfigRead = 1; - - my $myLonCapaName = $perlvar{lonHostID}; - - if(defined $hostshash{$myLonCapaName}) { - my @ConfigLine = @{$hostshash{$myLonCapaName}}; - $LocalDns = $ConfigLine[3]; - } - $InsecureOk = $perlvar{loncAllowInsecure}; - - Debug(3, "ReadForeignConfig - LocalDNS = $LocalDns"); - } sub Debug { @@ -213,7 +153,7 @@ host the remote lond is on. This host is =cut sub new { - my ($class, $DnsName, $Port) = @_; + my ($class, $DnsName, $Port, $lonid) = @_; if (!$ConfigRead) { ReadConfig(); @@ -227,19 +167,12 @@ sub new { # negotion. In the objec these become the Host and # LoncapaHim fields of the object respectively. # - if (!exists $hostshash{$DnsName}) { - &Debug(8, "No Such host $DnsName"); - return undef; # No such host!!! - } - my @ConfigLine = @{$hostshash{$DnsName}}; - my $Hostname = $ConfigLine[0]; # 0'th item is the msu id of host. - Debug(5, "Connecting to ".$DnsName); # if it is me use loopback for connection - if ($DnsName eq $LocalDns) { $DnsName="127.0.0.1"; } - Debug(8, "Connecting to $DnsName I am $LocalDns"); + if ($DnsName eq &main::my_hostname()) { $DnsName="127.0.0.1"; } + Debug(9, "Connecting to $DnsName"); # Now create the object... my $self = { Host => $DnsName, - LoncapaHim => $Hostname, + LoncapaHim => $lonid, Port => $Port, State => "Initialized", AuthenticationMode => "", @@ -251,7 +184,7 @@ sub new { TimeoutCallback => undef, TransitionCallback => undef, Timeoutable => 0, - TimeoutValue => 30, + TimeoutValue => 3, TimeoutRemaining => 0, LocalKeyFile => "", CipherKey => "", @@ -1136,31 +1069,6 @@ sub CompleteInsecure { } } -=pod - -=head2 GetHostIterator - -Returns a hash iterator to the host information. Each get from -this iterator returns a reference to an array that contains -information read from the hosts configuration file. Array elements -are used as follows: - - [0] - LonCapa host id. - [1] - LonCapa domain name. - [2] - Loncapa role (e.g. library or access). - [3] - DNS name server hostname. - [4] - IP address (result of e.g. nslookup [3]). - [5] - Maximum connection count. - [6] - Idle timeout for reducing connection count. - [7] - Minimum connection count. - -=cut - -sub GetHostIterator { - - return HashIterator->new(\%hostshash); -} - ########################################################### # # The following is an unashamed kludge that is here to @@ -1217,45 +1125,6 @@ sub read_conf return $perlvarref; } -#---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab -# formatted configuration file. -# -my $RequiredCount = 4; # Required item count in hosts.tab. -my $DefaultMaxCon = 5; # Default value for maximum connections. -my $DefaultIdle = 1000; # Default connection idle time in seconds. -my $DefaultMinCon = 0; # Default value for minimum connections. - -sub read_hosts { - my $Filename = shift; - my %HostsTab; - - open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); - while (my $line = ) { - if ($line !~ /^\s*\#/) { - $line=~s/\s*$//; - my @items = split(/:/, $line); - if(scalar @items >= $RequiredCount) { - if (scalar @items == $RequiredCount) { # Only required items: - $items[$RequiredCount] = $DefaultMaxCon; - } - if(scalar @items == $RequiredCount + 1) { # up through maxcon. - $items[$RequiredCount+1] = $DefaultIdle; - } - if(scalar @items == $RequiredCount + 2) { # up through idle. - $items[$RequiredCount+2] = $DefaultMinCon; - } - { - my @list = @items; # probably not needed but I'm unsure of - # about the scope of item so... - $HostsTab{$list[3]} = \@list; - } - } - } - } - close(CONFIG); - my $hostref = \%HostsTab; - return ($hostref); -} # # Get the version of our peer. Note that this is only well # defined if the state machine has hit the idle state at least @@ -1461,8 +1330,4 @@ true if the current state requires a wri true if the current state requires timeout support. -=item GetHostIterator: - -Returns an iterator into the host file hash. - =cut