2 # This module impliments the new protocal mode for a dx cluster
4 # Copyright (c) 2001 Dirk Koopman G1TLH
11 @ISA = qw(DXChannel DXProt);
25 use Time::HiRes qw(gettimeofday tv_interval);
36 use vars qw($VERSION $BRANCH);
37 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
38 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
39 $main::build += $VERSION;
40 $main::branch += $BRANCH;
44 my $user = DXUser->get($main::mycall);
45 $DXProt::myprot_version += $main::version*100;
46 $main::me = QXProt->new($main::mycall, 0, $user);
47 $main::me->{here} = 1;
48 $main::me->{state} = "indifferent";
49 $main::me->{sort} = 'S'; # S for spider
50 $main::me->{priv} = 9;
51 $main::me->{metric} = 0;
52 $main::me->{pingave} = 0;
53 $main::me->{registered} = 1;
54 $main::me->{version} = $main::version;
55 $main::me->{build} = $main::build;
57 # $Route::Node::me->adddxchan($main::me);
63 $self->SUPER::start(@_);
70 $self->send($self->genI);
75 if ($_[1] =~ /^PC\d\d\^/) {
79 my ($sort, $tonode, $fromnode, $msgid, $incs);
80 return unless ($sort, $tonode, $fromnode, $msgid, $incs) = $_[1] =~ /^QX([A-Z])\^(\*|[-A-Z0-9]+)\^([-A-Z0-9]+)\^([0-9A-F]{1,4})\^.*\^([0-9A-F]{2})$/;
83 my $noderef = Route::Node::get($fromnode);
84 $noderef = Route::Node::new($fromnode) unless $noderef;
86 my $il = length $incs;
87 my $cs = sprintf("%02X", unpack("%32C*", substr($_[1], 0, length($_[1]) - ($il+1))) & 255);
89 dbg("QXPROT: Checksum fail in: $incs ne calc: $cs" ) if isdbg('chanerr');
93 return unless $noderef->newid($msgid);
95 $_[0]->handle($sort, $tonode, $fromnode, $msgid, $_[1]);
104 my $sub = "handle$sort";
105 $self->$sub(@_) if $self->can($sub);
114 my $sub = "gen$sort";
115 $self->$sub(@_) if $self->can($sub);
119 my $last_node_update = 0;
120 my $node_update_interval = 60*15;
124 if ($main::systime >= $last_node_update+$node_update_interval) {
127 $last_node_update = $main::systime;
134 $self->DXProt::disconnect(@_);
142 my $to = shift || "*";
145 $ht = sprintf "%X", $msgid;
146 my $line = join '^', "QX$sort", $to, $main::mycall, $ht, @_;
147 my $cs = sprintf "%02X", unpack("%32C*", $line) & 255;
148 $msgid = 1 if ++$msgid > 0xffff;
156 my @f = split /\^/, $_[3];
157 if ($self->passphrase && $f[7] && $f[8]) {
158 my $inv = Verify->new($f[7]);
159 unless ($inv->verify($f[8], $main::me->user->passphrase, $main::mycall, $self->call)) {
160 $self->sendnow('D','Sorry...');
163 $self->{verified} = 1;
165 $self->{verified} = 0;
167 if ($self->{outbound}) {
168 $self->send($self->genI);
170 if ($self->{sort} ne 'S' && $f[4] eq 'DXSpider') {
171 $self->{user}->{sort} = $self->{sort} = 'S';
172 $self->{user}->{priv} = $self->{priv} = 1 unless $self->{priv};
174 $self->{version} = $f[5];
175 $self->{build} = $f[6];
176 $self->state('init1');
177 $self->{lastping} = 0;
183 my @out = ('I', $self->call, "DXSpider", ($main::version + 53) * 100, $main::build);
184 if (my $pass = $self->user->passphrase) {
185 my $inp = Verify->new;
186 push @out, $inp->challenge, $inp->response($pass, $self->call, $main::mycall);
222 for (; @_ && length $str <= 230;) {
224 my $call = $ref->call;
227 $flag += 1 if $ref->here;
228 $flag += 2 if $ref->conf;
230 my $ping = int($ref->pingave * 10);
231 $str .= "^N$flag$call,$ping";
232 my $v = $ref->build || $ref->version;
233 $str .= ",$v" if defined $v;
235 $str .= "^U$flag$call";
238 push @out, $str if $str;
241 my $h = get_hops(90);
242 @out = map { sprintf "PC90^%s^%X^%s%d%s^%s^", $node->call, $main::systime, $sort, --$n, $_, $h } @out;