--- loncom/loncnew 2004/02/17 09:43:21 1.42
+++ loncom/loncnew 2004/06/17 22:37:06 1.49
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# lonc maintains the connections to remote computers
#
-# $Id: loncnew,v 1.42 2004/02/17 09:43:21 foxr Exp $
+# $Id: loncnew,v 1.49 2004/06/17 22:37:06 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -103,6 +103,7 @@ my $RecentLogEntry = "";
my $ConnectionRetries=2; # Number of connection retries allowed.
my $ConnectionRetriesLeft=2; # Number of connection retries remaining.
my $LondVersion = "unknown"; # Version of lond we talk with.
+my $KeyMode = ""; # e.g. ssl, local, insecure from last connect.
#
# The hash below gives the HTML format for log messages
@@ -110,10 +111,10 @@ my $LondVersion = "unknown"; # Versi
#
my %LogFormats;
-$LogFormats{"CRITICAL"} = "CRITICAL: %s";
-$LogFormats{"SUCCESS"} = "SUCCESS: %s";
-$LogFormats{"INFO"} = "INFO: %s";
-$LogFormats{"WARNING"} = "WARNING: %s";
+$LogFormats{"CRITICAL"} = "CRITICAL: %s";
+$LogFormats{"SUCCESS"} = "SUCCESS: %s";
+$LogFormats{"INFO"} = "INFO: %s";
+$LogFormats{"WARNING"} = "WARNING: %s";
$LogFormats{"DEFAULT"} = " %s ";
@@ -156,9 +157,9 @@ host and the time will be formatted into
=cut
sub Log {
- my $severity = shift;
- my $message = shift;
-
+
+ my ($severity, $message) = @_;
+
if(!$LogFormats{$severity}) {
$severity = "DEFAULT";
}
@@ -193,8 +194,10 @@ Returns the name of the host that a sock
=cut
sub GetPeername {
- my $connection = shift;
- my $AdrFamily = shift;
+
+
+ my ($connection, $AdrFamily) = @_;
+
my $peer = $connection->peername();
my $peerport;
my $peerip;
@@ -217,18 +220,20 @@ Invoked to issue a debug message.
=cut
sub Debug {
- my $level = shift;
- my $message = shift;
+
+ my ($level, $message) = @_;
+
if ($level <= $DebugLevel) {
Log("INFO", "-Debug- $message host = $RemoteHost");
}
}
sub SocketDump {
- my $level = shift;
- my $socket= shift;
+
+ my ($level, $socket) = @_;
+
if($level <= $DebugLevel) {
- $socket->Dump();
+ $socket->Dump(-1); # Ensure it will get dumped.
}
}
@@ -261,9 +266,9 @@ sub SocketTimeout {
my $Socket = shift;
Log("WARNING", "A socket timeout was detected");
Debug(0, " SocketTimeout called: ");
- $Socket->Dump();
+ $Socket->Dump(0);
if(exists($ActiveTransactions{$Socket})) {
- FailTransaction($ActiveTransactions{$Socket});
+ FailTransaction($ActiveTransactions{$Socket});
}
KillSocket($Socket); # A transaction timeout also counts as
# a connection failure:
@@ -288,7 +293,8 @@ sub Tick {
my $client;
if($ConnectionRetriesLeft > 0) {
ShowStatus(GetServerHost()." Connection count: ".$ConnectionCount
- ." Retries remaining: ".$ConnectionRetriesLeft);
+ ." Retries remaining: ".$ConnectionRetriesLeft
+ ." ($KeyMode)");
} else {
ShowStatus(GetServerHost()." >> DEAD <<");
}
@@ -343,6 +349,9 @@ sub Tick {
}
}
+ if ($ConnectionCount == 0) {
+ $KeyMode = "";
+ }
}
=pod
@@ -383,6 +392,7 @@ long enough, it will be shut down and re
sub ServerToIdle {
my $Socket = shift; # Get the socket.
+ $KeyMode = $Socket->{AuthenticationMode};
delete($ActiveTransactions{$Socket}); # Server has no transaction
&Debug(5, "Server to idle");
@@ -515,8 +525,8 @@ The transaction that is being completed.
sub CompleteTransaction {
&Debug(5,"Complete transaction");
- my $Socket = shift;
- my $Transaction = shift;
+
+ my ($Socket, $Transaction) = @_;
if (!$Transaction->isDeferred()) { # Normal transaction
my $data = $Socket->GetReply(); # Data to send.
@@ -550,9 +560,8 @@ sub CompleteTransaction {
=cut
sub StartClientReply {
- my $Transaction = shift;
- my $data = shift;
+ my ($Transaction, $data) = @_;
my $Client = $Transaction->getClient();
@@ -959,16 +968,16 @@ sub LondWritable {
# so that the writing states are actually NO-OPs.
if ($Socket->Writable() != 0) {
- # The write resulted in an error.
- # We'll treat this as if the socket got disconnected:
- Log("WARNING", "Connection to ".$RemoteHost.
- " has been disconnected");
- if(exists($ActiveTransactions{$Socket})) {
- FailTransaction($ActiveTransactions{$Socket});
- }
- $Watcher->cancel();
- KillSocket($Socket);
- return;
+ # The write resulted in an error.
+ # We'll treat this as if the socket got disconnected:
+ Log("WARNING", "Connection to ".$RemoteHost.
+ " has been disconnected");
+ if(exists($ActiveTransactions{$Socket})) {
+ FailTransaction($ActiveTransactions{$Socket});
+ }
+ $Watcher->cancel();
+ KillSocket($Socket);
+ return;
}
@@ -1164,8 +1173,8 @@ The text of the request to send.
=cut
sub StartRequest {
- my $Lond = shift;
- my $Request = shift; # This is a LondTransaction.
+
+ my ($Lond, $Request) = @_;
Debug(6, "StartRequest: ".$Request->getRequest());
@@ -1269,7 +1278,7 @@ sub ClientRequest {
Debug(8,"Data: ".$data." this read: ".$thisread);
$data = $data.$thisread; # Append new data.
$watcher->data($data);
- if($data =~ /(.*\n)/) { # Request entirely read.
+ if($data =~ /\n$/) { # Request entirely read.
if($data eq "close_connection_exit\n") {
Log("CRITICAL",
"Request Close Connection ... exiting");
@@ -1416,6 +1425,7 @@ into the status file.
We also use this to reset the retries count in order to allow the
client to retry connections with a previously dead server.
=cut
+
sub ChildStatus {
my $event = shift;
my $watcher = $event->w;
@@ -1428,16 +1438,18 @@ sub ChildStatus {
#
# Write out information about each of the connections:
#
- print $fh "Active connection statuses: \n";
- my $i = 1;
- print STDERR "================================= Socket Status Dump:\n";
- foreach my $item (keys %ActiveConnections) {
- my $Socket = $ActiveConnections{$item}->data;
- my $state = $Socket->GetState();
- print $fh "Connection $i State: $state\n";
- print STDERR "---------------------- Connection $i \n";
- $Socket->Dump();
- $i++;
+ if ($DebugLevel > 2) {
+ print $fh "Active connection statuses: \n";
+ my $i = 1;
+ print STDERR "================================= Socket Status Dump:\n";
+ foreach my $item (keys %ActiveConnections) {
+ my $Socket = $ActiveConnections{$item}->data;
+ my $state = $Socket->GetState();
+ print $fh "Connection $i State: $state\n";
+ print STDERR "---------------------- Connection $i \n";
+ $Socket->Dump(-1); # Ensure it gets dumped..
+ $i++;
+ }
}
$ConnectionRetriesLeft = $ConnectionRetries;
}