aacfae68e95b46df86f1ca20c8996b8c0a066b4b
[spider.git] / perl / QXProt / QXI.pm
1 #
2 # This module is part of the new protocal mode for a dx cluster
3 #
4 # This module handles the initialisation between two nodes
5 #
6 # Copyright (c) 2003 Dirk Koopman G1TLH
7 #
8 # $Id$
9
10
11 package QXI;
12
13 use strict;
14
15 use vars qw(@ISA $VERSION $BRANCH);
16 @ISA = qw(QXProt);
17
18 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
19 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
20 $main::build += $VERSION;
21 $main::branch += $BRANCH;
22
23
24 sub handle
25 {
26         my ($self, $to, $from, $msgid, $line) = @_;
27         
28         my @f = split /\^/, $line;
29         if ($self->user->passphrase && @f > 3) {
30                 my $inv = Verify->new($f[3]);
31                 unless ($inv->verify($f[4], $main::me->user->passphrase, $main::mycall, $self->call)) {
32                         $self->sendnow('D','Sorry...');
33                         $self->disconnect;
34                 }
35                 $self->{verified} = 1;
36         } else {
37                 $self->{verified} = 0;
38         }
39         if ($self->{outbound}) {
40                 $self->send($self->QXI::gen);
41         } 
42         if ($self->{sort} ne 'S' && $f[0] eq 'DXSpider') {
43                 $self->{user}->{sort} = $self->{sort} = 'S';
44                 $self->{user}->{priv} = $self->{priv} = 1 unless $self->{priv};
45         }
46         $self->{version} = $f[1];
47         $self->{build} = $f[2];
48         $self->state('init1');
49         $self->{lastping} = 0;
50 }
51
52 sub gen
53 {
54         my $self = shift;
55         my @out = ('I', $self->call, "DXSpider", ($main::version + 53) * 100, $main::build);
56         if (my $pass = $self->user->passphrase) {
57                 my $inp = Verify->new;
58                 push @out, $inp->challenge, $inp->response($pass, $self->call, $main::mycall);
59         }
60         return $self->frame(@out);
61 }
62
63 1;