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 my $inv = Verify->new($f[7]);
158 unless ($inv->verify($f[8], $main::me->user->passphrase, $main::mycall, $self->call)) {
159 $self->sendnow('D','Sorry...');
162 if ($self->{outbound}) {
163 $self->send($self->genI);
165 if ($self->{sort} ne 'S' && $f[4] eq 'DXSpider') {
166 $self->{user}->{sort} = $self->{sort} = 'S';
167 $self->{user}->{priv} = $self->{priv} = 1 unless $self->{priv};
169 $self->{version} = $f[5];
170 $self->{build} = $f[6];
171 $self->state('init1');
172 $self->{lastping} = 0;
178 my $inp = Verify->new;
179 return frame('I', $self->call, "DXSpider", ($main::version + 53) * 100, $main::build, $inp->challenge, $inp->response($self->user->passphrase, $self->call, $main::mycall));
213 for (; @_ && length $str <= 230;) {
215 my $call = $ref->call;
218 $flag += 1 if $ref->here;
219 $flag += 2 if $ref->conf;
221 my $ping = int($ref->pingave * 10);
222 $str .= "^N$flag$call,$ping";
223 my $v = $ref->build || $ref->version;
224 $str .= ",$v" if defined $v;
226 $str .= "^U$flag$call";
229 push @out, $str if $str;
232 my $h = get_hops(90);
233 @out = map { sprintf "PC90^%s^%X^%s%d%s^%s^", $node->call, $main::systime, $sort, --$n, $_, $h } @out;