[LON-CAPA-cvs] cvs: loncom / lonc lond

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 27 Mar 2003 23:00:28 -0000


This is a MIME encoded message

--albertel1048806028
Content-Type: text/plain

albertel		Thu Mar 27 18:00:28 2003 EDT

  Modified files:              
    /loncom	lonc lond 
  Log:
  - added new command to lond
    sethost:machinenamewanted
       returns either ok or unable_to_set
    version:MY VERSION
       returns version:MY VERSION
  
  - init method comatible with older 0.6ish inti sequence
  
  - lonc properly uses sethost and version
  
  
  
  
--albertel1048806028
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030327180028.txt"

Index: loncom/lonc
diff -u loncom/lonc:1.48 loncom/lonc:1.49
--- loncom/lonc:1.48	Tue Mar 18 17:51:03 2003
+++ loncom/lonc	Thu Mar 27 18:00:28 2003
@@ -5,7 +5,7 @@
 # provides persistent TCP connections to the other servers in the network
 # through multiplexed domain sockets
 #
-# $Id: lonc,v 1.48 2003/03/18 22:51:03 albertel Exp $
+# $Id: lonc,v 1.49 2003/03/27 23:00:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -64,7 +64,8 @@
 $lastlog='';
 $conserver='SHELL';
 $DEBUG = 0;			# Set to 1 for annoyingly complete logs.
-
+$VERSION='$Revison$'; #' stupid emacs
+$remoteVERSION;
 # -------------------------------- Set signal handlers to record abnormal exits
 
 &status("Init exception handlers");
@@ -702,75 +703,89 @@
 
     my $conserver=shift;
 
-&status("Opening TCP $conserver");
+    &status("Opening TCP $conserver");
     my $st=120+int(rand(240)); # Sleep before opening:
 
-unless (
-  $remotesock = IO::Socket::INET->new(PeerAddr => $hostip{$conserver},
-                                      PeerPort => $perlvar{'londPort'},
-                                      Proto    => "tcp",
-                                      Type     => SOCK_STREAM)
-   ) { 
-
-       &logthis(
-"<font color=blue>WARNING: Couldn't connect to $conserver ($st secs): </font>");
-       sleep($st);
-       exit; 
-     };
+    unless (
+	    $remotesock = IO::Socket::INET->new(PeerAddr => $hostip{$conserver},
+						PeerPort => $perlvar{'londPort'},
+						Proto    => "tcp",
+						Type     => SOCK_STREAM)
+	   ) {
+
+	&logthis(
+		 "<font color=blue>WARNING: Couldn't connect to $conserver ($st secs): </font>");
+	sleep($st);
+	exit;
+    };
 # ----------------------------------------------------------------- Init dialog
 
-&logthis("<font color=green>INFO Connected to $conserver, initing </font>");
-&status("Init dialogue: $conserver");
+    &logthis("<font color=green>INFO Connected to $conserver, initing</font>");
+    &status("Init dialogue: $conserver");
 
-    $answer = londtransaction($remotesock, "init:$conserver", 60);
+    $answer = londtransaction($remotesock, "init", 60);
     chomp($answer);
     $answer = londtransaction($remotesock, $answer, 60);
     chomp($answer);
- 
-     if ($@=~/timeout/) {
-	 &logthis("Timed out during init.. exiting");
-         exit;
-     }
 
-if ($answer ne 'ok') {
-       &logthis("Init reply: >$answer<");
-       my $st=120+int(rand(240));
-       &logthis(
-"<font color=blue>WARNING: Init failed ($st secs)</font>");
-       sleep($st);
-       exit; 
-}
+    if ($@=~/timeout/) {
+	&logthis("Timed out during init.. exiting");
+	exit;
+    }
 
-sleep 5;
-&status("Ponging $conserver");
-print $remotesock "pong\n";
-$answer=<$remotesock>;
-chomp($answer);
-if ($answer!~/^$conserver/) {
-   &logthis("Pong reply: >$answer<");
-}
+    if ($answer ne 'ok') {
+	&logthis("Init reply: >$answer<");
+	my $st=120+int(rand(240));
+	&logthis("<font color=blue>WARNING: Init failed ($st secs)</font>");
+	sleep($st);
+	exit;
+    }
+
+    $answer = londtransaction($remotesock,"sethost:$conserver",60);
+    chomp($answer);
+    if ( $answer ne 'ok') {
+	&logthis('<font color="blue">WARNING: unable to specify remote host'.
+		 $answer.'</font>');
+    }
+
+    $answer = londtransaction($remotesock,"version:$VERSION",60);
+    chomp($answer);
+    if ($answer =~ /^version:/) {
+	$remoteVERSION=(split(/:/,$answer))[1];
+    } else {
+	&logthis('<font color="blue">WARNING: request remote version failed :'.
+		 $answer.': my version is :'.$VERSION.':</font>');
+    }
+
+    sleep 5;
+    &status("Ponging $conserver");
+    print $remotesock "pong\n";
+    $answer=<$remotesock>;
+    chomp($answer);
+    if ($answer!~/^$conserver/) {
+	&logthis("Pong reply: >$answer<");
+    }
 # ----------------------------------------------------------- Initialize cipher
 
-&status("Initialize cipher");
-print $remotesock "ekey\n";
-my $buildkey=<$remotesock>;
-my $key=$conserver.$perlvar{'lonHostID'};
-$key=~tr/a-z/A-Z/;
-$key=~tr/G-P/0-9/;
-$key=~tr/Q-Z/0-9/;
-$key=$key.$buildkey.$key.$buildkey.$key.$buildkey;
-$key=substr($key,0,32);
-my $cipherkey=pack("H32",$key);
-if ($cipher=new IDEA $cipherkey) {
-   &logthis("Secure connection initialized");
-} else {
-   my $st=120+int(rand(240));
-   &logthis(
-     "<font color=blue>WARNING: ".
-     "Could not establish secure connection ($st secs)!</font>");
-   sleep($st);
-   exit;
-}
+    &status("Initialize cipher");
+    print $remotesock "ekey\n";
+    my $buildkey=<$remotesock>;
+    my $key=$conserver.$perlvar{'lonHostID'};
+    $key=~tr/a-z/A-Z/;
+    $key=~tr/G-P/0-9/;
+    $key=~tr/Q-Z/0-9/;
+    $key=$key.$buildkey.$key.$buildkey.$key.$buildkey;
+    $key=substr($key,0,32);
+    my $cipherkey=pack("H32",$key);
+    if ($cipher=new IDEA $cipherkey) {
+	&logthis("Secure connection initialized");
+    } else {
+	my $st=120+int(rand(240));
+	&logthis("<font color=blue>WARNING: ".
+		 "Could not establish secure connection ($st secs)!</font>");
+	sleep($st);
+	exit;
+    }
     &logthis("<font color=green> Remote open success </font>");
 }
 
@@ -979,8 +994,8 @@
 	die("lonc - suiciding on send Timeout");
     }
     if ($@ =~ /timeout/) {
-	&logthis("lonc - suiciding on send Timeout");
-	die("lonc - suiciding on send Timeout");
+	&logthis("lonc - suiciding on read Timeout");
+	die("lonc - suiciding on read Timeout");
     }
     #
     # Restore the initial sigmask set.
Index: loncom/lond
diff -u loncom/lond:1.120 loncom/lond:1.121
--- loncom/lond:1.120	Wed Mar 26 14:34:42 2003
+++ loncom/lond	Thu Mar 27 18:00:28 2003
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.120 2003/03/26 19:34:42 www Exp $
+# $Id: lond,v 1.121 2003/03/27 23:00:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,6 +73,8 @@
 my $status='';
 my $lastlog='';
 
+my $VERSION='$Revision: 1.121 $'; #' stupid emacs
+my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
 #
@@ -515,22 +517,6 @@
     make_new_child($client);
 }
 
-sub init_host_and_domain {
-    my ($remotereq) = @_;
-    my (undef,$hostid)=split(/:/,$remotereq);
-    if (!defined($hostid)) { $hostid=$perlvar{'lonHostID'}; }
-    if ($hostip{$perlvar{'lonHostID'}} eq $hostip{$hostid}) {
-	$currenthostid=$hostid;
-	$currentdomainid=$hostdom{$hostid};
-	&logthis("Setting hostid to $hostid, and domain to $currentdomainid");
-    } else {
-	&logthis("Requested host id $hostid not an alias of ".
-		 $perlvar{'lonHostID'}." refusing connection");
-	return 0;
-    }
-    return 1;
-}
-
 sub make_new_child {
     my $client;
     my $pid;
@@ -592,14 +578,7 @@
 	      my $remotereq=<$client>;
               $remotereq=~s/[^\w:]//g;
               if ($remotereq =~ /^init/) {
-		  if (!&init_host_and_domain($remotereq)) {
-		      &status("Got bad init message, exiting");
-		      print $client "refused\n";
-		      $client->close();
-		      &logthis("<font color=blue>WARNING: "
-			       ."Bad init message $remotereq, closing connection</font>");
-		      exit;
-		  }
+		  &sethost("sethost:$perlvar{'lonHostID'}");
 		  my $challenge="$$".time;
                   print $client "$challenge\n";
                   &status(
@@ -1739,6 +1718,10 @@
                        $client->close();
 		       last;
 # ------------------------------------------------------------- unknown command
+		   } elsif ($userinput =~ /^sethost:/) {
+		       print $client &sethost($userinput)."\n";
+		   } elsif ($userinput =~/^version:/) {
+		       print $client &version($userinput)."\n";
                    } else {
                        # unknown command
                        print $client "unknown_cmd\n";
@@ -2052,6 +2035,28 @@
 	$result="auth_mode_error\n";
     }
     return $result;
+}
+
+sub sethost {
+    my ($remotereq) = @_;
+    my (undef,$hostid)=split(/:/,$remotereq);
+    if (!defined($hostid)) { $hostid=$perlvar{'lonHostID'}; }
+    if ($hostip{$perlvar{'lonHostID'}} eq $hostip{$hostid}) {
+	$currenthostid=$hostid;
+	$currentdomainid=$hostdom{$hostid};
+	&logthis("Setting hostid to $hostid, and domain to $currentdomainid");
+    } else {
+	&logthis("Requested host id $hostid not an alias of ".
+		 $perlvar{'lonHostID'}." refusing connection");
+	return 'unable_to_set';
+    }
+    return 'ok';
+}
+
+sub version {
+    my ($userinput)=@_;
+    $remoteVERSION=(split(/:/,$userinput))[1];
+    return "version:$VERSION";
 }
 
 # ----------------------------------- POD (plain old documentation, CPAN style)

--albertel1048806028--