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;
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->gen1);
75 if ($_[1] =~ /^PC\d\d\^/) {
79 my ($id, $fromnode, $msgid, $incs);
80 return unless ($id, $fromnode, $msgid, $incs) = $_[1] =~ /^QX(\d\d)\^([-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($id, $fromnode, $msgid, $_[1]);
104 my $sub = "handle$id";
105 $self->$sub(@_) if $self->can($sub);
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(@_);
153 $ht = sprintf "%X", $msgid;
154 my $line = join '^', sprintf("QX%02d", $pcno), $main::mycall, $ht, @_;
155 my $cs = sprintf "%02X", unpack("%32C*", $line) & 255;
156 $msgid = 1 if ++$msgid > 0xffff;
164 my @f = split /\^/, $_[2];
165 my $inv = Verify->new($f[7]);
166 unless ($inv->verify($f[8], $main::me->user->passphrase, $main::mycall, $self->call)) {
167 $self->sendnow('D','Sorry...');
170 if ($self->{outbound}) {
171 $self->send($self->gen1);
173 if ($self->{sort} ne 'S' && $f[4] eq 'DXSpider') {
174 $self->{user}->{sort} = $self->{sort} = 'S';
175 $self->{user}->{priv} = $self->{priv} = 1 unless $self->{priv};
177 $self->{version} = $f[5];
178 $self->{build} = $f[6];
179 $self->state('normal');
180 $self->{lastping} = 0;
186 my $inp = Verify->new;
187 return frame(1, 1, "DXSpider", ($main::version + 53) * 100, $main::build, $inp->challenge, $inp->response($self->user->passphrase, $self->call, $main::mycall));
206 for (; @_ && length $str <= 230;) {
208 my $call = $ref->call;
211 $flag += 1 if $ref->here;
212 $flag += 2 if $ref->conf;
214 my $ping = int($ref->pingave * 10);
215 $str .= "^N$flag$call,$ping";
216 my $v = $ref->build || $ref->version;
217 $str .= ",$v" if defined $v;
219 $str .= "^U$flag$call";
222 push @out, $str if $str;
225 my $h = get_hops(90);
226 @out = map { sprintf "PC90^%s^%X^%s%d%s^%s^", $node->call, $main::systime, $sort, --$n, $_, $h } @out;