[LON-CAPA-cvs] cvs: newloncapa / enctest.pl

foxr lon-capa-cvs@mail.lon-capa.org
Sat, 12 Apr 2003 02:49:05 -0000


foxr		Fri Apr 11 22:49:05 2003 EDT

  Added files:                 
    /newloncapa	enctest.pl 
  Log:
  Tests the new lonc with a few encoded transactions.
  
  

Index: newloncapa/enctest.pl
+++ newloncapa/enctest.pl
#!//usr/bin/perl
#
#   Tests the ability to perform requests to lonc that are encrypted.
#   The only difference between this and enctest is that the transactions
#   are packaged with encrypt:length:data which forces the connection 
#   object to encrypt it.
#    


use POSIX;
use Socket;
use IO::Socket;
use IO::Socket::UNIX;

print "Host to test with?: ";
$host = <STDIN>;
chomp $host;
$socketpath = "/home/foxr/pipes/".$host;
$system     = "lonkashy.nscl.msu.edu";

sub MakeConnection {
    my $Socket = IO::Socket::UNIX->new(Peer => $socketpath,
				    type => SOCK_STREAM,
				    Timeout => 100);
    return $Socket;
}


sub Transaction {
    my $Socket  = shift;
    my $Request = shift;

 
    $Request = "encrypt:$Request";
    
    print "Transaction: ".$Request."\n";

    $Request    = $Request."\n";	# Transactions end in newline.

    $Socket->send($Request, 0);

    my $reply = <$Socket>;
    return $reply;
}

sub Load {
    my $Socket = shift;
    return Transaction ($Socket, "load");
}

sub Ping {
    my $Socket = shift;
    return Transaction($Socket, "ping");
}

sub Pong {
    my $Socket = shift;
    return Transaction($Socket, "pong");
}


# See if we can get two transactions in flight at the same time forcing
# two connections:

sub Double {

    my $Socket = shift;
    my $Sock1  = shift;
    my $Data   = shift;
    my $Data1  = shift;
    $Data      = "encrypt:".$Data."\n";
    $Data1     = "encrypt:".$Data1."\n";

    $Socket->send($Data);
    $Sock1->send($Data1);
    my $r1;
    my $r2;
    $r1 = "";
    $r2 = "";
    
    $r1 = <$Socket>;
    $r2 = <$Sock1>;

    return ($r1, $r2);

}


# Do it all with a single connection:

$Socket = MakeConnection;
$Sock1  = MakeConnection;

$reply = Load($Sock1);
print("Load request on sock1 : ".$reply."\n");

$reply  = Load($Socket);	# Get load info:
print("Load request Socket returned: ".$reply."\n");

$reply = Ping($Socket);		# Ping...
print("Ping request returned: ".$reply."\n");


$reply = Pong($Socket);		# pong
print("Pong Request returned: ".$reply."\n");

#  Now see if we can force two lond connections from lonc:

@reply = Double($Socket, $Sock1, "load", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "load", "ping");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "ping", "pong");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "pong", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");
@reply = Double($Socket, $Sock1, "load", "load");
print("Double op got me: ".$reply[0]." ".$reply[1]."\n");