pre 1.13 release
[spider.git] / perl / DXProt.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the protocal mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXProt;
11
12 @ISA = qw(DXChannel);
13
14 use DXUtil;
15 use DXChannel;
16 use DXUser;
17 use DXM;
18 use DXCluster;
19 use DXProtVars;
20 use DXCommandmode;
21 use DXLog;
22 use Spot;
23 use DXProtout;
24 use Carp;
25
26 use strict;
27 use vars qw($me $pc11_max_age $pc11_dup_age %dup $last_hour %pings %rcmds %nodehops);
28
29 $me = undef;                                    # the channel id for this cluster
30 $pc11_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc11
31 $pc11_dup_age = 24*3600;                # the maximum time to keep the dup list for
32 %dup = ();                                              # the pc11 and 26 dup hash 
33 $last_hour = time;                              # last time I did an hourly periodic update
34 %pings = ();                    # outstanding ping requests outbound
35 %rcmds = ();                    # outstanding rcmd requests outbound
36 %nodehops = ();                 # node specific hop control
37
38
39 sub init
40 {
41         my $user = DXUser->get($main::mycall);
42         $DXProt::myprot_version += $main::version*100;
43         $me = DXProt->new($main::mycall, 0, $user); 
44         $me->{here} = 1;
45         $me->{state} = "indifferent";
46         do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
47         confess $@ if $@;
48         #  $me->{sort} = 'M';    # M for me
49 }
50
51 #
52 # obtain a new connection this is derived from dxchannel
53 #
54
55 sub new 
56 {
57         my $self = DXChannel::alloc(@_);
58         $self->{'sort'} = 'A';          # in absence of how to find out what sort of an object I am
59         return $self;
60 }
61
62 # this is how a pc connection starts (for an incoming connection)
63 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
64 # all the crap that comes between).
65 sub start
66 {
67         my ($self, $line, $sort) = @_;
68         my $call = $self->{call};
69         my $user = $self->{user};
70         
71         # remember type of connection
72         $self->{consort} = $line;
73         $self->{outbound} = $sort eq 'O';
74         $self->{priv} = $user->priv;
75         $self->{lang} = $user->lang;
76         $self->{isolate} = $user->{isolate};
77         $self->{consort} = $line;       # save the connection type
78         $self->{here} = 1;
79         
80         # set unbuffered
81         $self->send_now('B',"0");
82         
83         # send initialisation string
84         if (!$self->{outbound}) {
85                 $self->send(pc38()) if DXNode->get_all();
86                 $self->send(pc18());
87         }
88         $self->state('init');
89         $self->pc50_t(time);
90
91         Log('DXProt', "$call connected");
92 }
93
94 #
95 # This is the normal pcxx despatcher
96 #
97 sub normal
98 {
99         my ($self, $line) = @_;
100         my @field = split /[\^\~]/, $line;
101         
102         # ignore any lines that don't start with PC
103         return if !$field[0] =~ /^PC/;
104         
105         # process PC frames
106         my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
107         return unless $pcno;
108         return if $pcno < 10 || $pcno > 51;
109         
110  SWITCH: {
111                 if ($pcno == 10) {              # incoming talk
112                         
113                         # is it for me or one of mine?
114                         my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
115                         if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
116                                 
117                                 # yes, it is
118                                 my $text = unpad($field[3]);
119                                 Log('talk', $call, $field[1], $field[6], $text);
120                                 $call = $main::myalias if $call eq $main::mycall;
121                                 my $ref = DXChannel->get($call);
122                                 $ref->send("$call de $field[1]: $text") if $ref;
123                         } else {
124                                 route($field[2], $line); # relay it on its way
125                         }
126                         return;
127                 }
128                 
129                 if ($pcno == 11 || $pcno == 26) { # dx spot
130                         
131                         # if this is a 'nodx' node then ignore it
132                         last SWITCH if grep $field[7] =~ /^$_/,  @DXProt::nodx_node;
133                         
134                         # convert the date to a unix date
135                         my $d = cltounix($field[3], $field[4]);
136                         return if !$d || ($pcno == 11 && $d < $main::systime - $pc11_max_age); # bang out (and don't pass on) if date is invalid or the spot is too old
137                         
138                         # strip off the leading & trailing spaces from the comment
139                         my $text = unpad($field[5]);
140                         
141                         # store it away
142                         my $spotter = $field[6];
143                         $spotter =~ s/-\d+$//o; # strip off the ssid from the spotter
144                         
145                         # do some de-duping
146                         my $dupkey = "$field[1]$field[2]$d$text$field[6]";
147                         return if $dup{$dupkey};
148                         $dup{$dupkey} = $d;
149                         
150                         my $spot = Spot::add($field[1], $field[2], $d, $text, $spotter);
151                         
152                         # send orf to the users
153                         if ($spot && $pcno == 11) {
154                                 my $buf = Spot::formatb($field[1], $field[2], $d, $text, $spotter);
155                                 broadcast_users("$buf\a\a");
156                         }
157                         
158                         last SWITCH;
159                 }
160                 
161                 if ($pcno == 12) {              # announces
162                         
163                         if ($field[2] eq '*' || $field[2] eq $main::mycall) {
164                                 
165                                 # strip leading and trailing stuff
166                                 my $text = unpad($field[3]);
167                                 my $target;
168                                 my $to = 'To ';
169                                 my @list;
170                                 
171                                 if ($field[4] eq '*') { # sysops
172                                         $target = "SYSOP";
173                                         @list = map { $_->priv >= 5 ? $_ : () } get_all_users();
174                                 } elsif ($field[4] gt ' ') { # speciality list handling
175                                         my ($name) = split /\./, $field[4]; 
176                                         $target = "$name"; # put the rest in later (if bothered) 
177                                 } 
178                                 
179                                 if ($field[6] eq '1') {
180                                         $target = "WX"; 
181                                         $to = '';
182                                 }
183                                 $target = "All" if !$target;
184                                 
185                                 if (@list > 0) {
186                                         broadcast_list("$to$target de $field[1]: $text", @list);
187                                 } else {
188                                         broadcast_users("$target de $field[1]: $text");
189                                 }
190                                 Log('ann', $target, $field[1], $text);
191                                 
192                                 return if $field[2] eq $main::mycall; # it's routed to me
193                         } else {
194                                 route($field[2], $line);
195                                 return;                 # only on a routed one
196                         }
197                         
198                         last SWITCH;
199                 }
200                 
201                 if ($pcno == 13) {
202                         last SWITCH;
203                 }
204                 if ($pcno == 14) {
205                         last SWITCH;
206                 }
207                 if ($pcno == 15) {
208                         last SWITCH;
209                 }
210                 
211                 if ($pcno == 16) {              # add a user
212                         my $node = DXCluster->get_exact($field[1]); 
213                         last SWITCH if !$node; # ignore if havn't seen a PC19 for this one yet
214                         my $i;
215                         
216                         
217                         for ($i = 2; $i < $#field; $i++) {
218                                 my ($call, $confmode, $here) = $field[$i] =~ /^(\S+) (-) (\d)/o;
219                                 next if length $call < 3;
220                                 next if !$confmode;
221                                 $call = uc $call;
222                                 next if DXCluster->get_exact($call); # we already have this (loop?)
223                                 
224                                 $confmode = $confmode eq '*';
225                                 DXNodeuser->new($self, $node, $call, $confmode, $here);
226                                 
227                                 # add this station to the user database, if required
228                                 $call =~ s/-\d+$//o;        # remove ssid for users
229                                 my $user = DXUser->get_current($call);
230                                 $user = DXUser->new($call) if !$user;
231                                 $user->homenode($node->call) if !$user->homenode;
232                                 $user->node($node->call);
233                                 $user->lastin($main::systime);
234                                 $user->put;
235                         }
236                         
237                         # queue up any messages (look for privates only)
238                         DXMsg::queue_msg(1) if $self->state eq 'normal';     
239                         last SWITCH;
240                 }
241                 
242                 if ($pcno == 17) {              # remove a user
243                         
244                         my $ref = DXCluster->get_exact($field[1]);
245                         $ref->del() if $ref;
246                         last SWITCH;
247                 }
248                 
249                 if ($pcno == 18) {              # link request
250                         $self->send_local_config();
251                         $self->send(pc20());
252                         $self->state('init');   
253                         last SWITCH;
254                 }
255                 
256                 if ($pcno == 19) {              # incoming cluster list
257                         my $i;
258                         for ($i = 1; $i < $#field-1; $i += 4) {
259                                 my $here = $field[$i];
260                                 my $call = uc $field[$i+1];
261                                 my $confmode = $field[$i+2] eq '*';
262                                 my $ver = $field[$i+3];
263                                 
264                                 # now check the call over
265                                 next if DXCluster->get_exact($call); # we already have this
266                                 
267                                 # check for sane parameters
268                                 next if $ver < 5000; # only works with version 5 software
269                                 next if length $call < 3; # min 3 letter callsigns
270                                 DXNode->new($self, $call, $confmode, $here, $ver);
271                                 
272                                 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
273                                 my $mref = DXMsg::get_busy($call);
274                                 $mref->stop_msg($self) if $mref;
275                                 
276                                 # add this station to the user database, if required (don't remove SSID from nodes)
277                                 my $user = DXUser->get_current($call);
278                                 if (!$user) {
279                                         $user = DXUser->new($call);
280                                         $user->sort('A');
281                                         $user->priv(1);                   # I have relented and defaulted nodes
282                                         $self->{priv} = 1;                # to user RCMDs allowed
283                                         $user->homenode($call);
284                                         $user->node($call);
285                                 }
286                                 $user->lastin($main::systime);
287                                 $user->put;
288                         }
289                         
290                         # queue up any messages
291                         DXMsg::queue_msg(0) if $self->state eq 'normal';
292                         last SWITCH;
293                 }
294                 
295                 if ($pcno == 20) {              # send local configuration
296                         $self->send_local_config();
297                         $self->send(pc22());
298                         $self->state('normal');
299                         
300                         # queue mail
301                         DXMsg::queue_msg(0);
302                         return;
303                 }
304                 
305                 if ($pcno == 21) {              # delete a cluster from the list
306                         my $call = uc $field[1];
307                         if ($call ne $main::mycall) { # don't allow malicious buggers to disconnect me!
308                                 my $ref = DXCluster->get_exact($call);
309                                 $ref->del() if $ref;
310                         }
311                         last SWITCH;
312                 }
313                 
314                 if ($pcno == 22) {
315                         $self->state('normal');
316                         
317                         # queue mail
318                         DXMsg::queue_msg(0);
319                         return;
320                 }
321                 
322                 if ($pcno == 23 || $pcno == 27) { # WWV info
323                         Geomag::update(@field[1..$#field]);
324                         last SWITCH;
325                 }
326                 
327                 if ($pcno == 24) {              # set here status
328                         my $call = uc $field[1];
329                         my $ref = DXCluster->get_exact($call);
330                         $ref->here($field[2]) if $ref;
331                         last SWITCH;
332                 }
333                 
334                 if ($pcno == 25) {
335                         last SWITCH;
336                 }
337                 
338                 if (($pcno >= 28 && $pcno <= 33) || $pcno == 40 || $pcno == 42 || $pcno == 49) { # mail/file handling
339                         DXMsg::process($self, $line);
340                         return;
341                 }
342                 
343                 if ($pcno == 34 || $pcno == 36) { # remote commands (incoming)
344                         if ($field[1] eq $main::mycall) {
345                                 my $ref = DXUser->get_current($field[2]);
346                                 Log('rcmd', 'in', $ref->{priv}, $field[2], $field[3]);
347                                 unless ($field[3] =~ /rcmd/i) {    # not allowed to relay RCMDS!
348                                         if ($ref->{priv}) {     # you have to have SOME privilege, the commands have further filtering
349                                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
350                                                 my @in = (DXCommandmode::run_cmd($self, $field[3]));
351                                                 for (@in) {
352                                                         s/\s*$//og;
353                                                         $self->send(pc35($main::mycall, $field[2], "$main::mycall:$_"));
354                                                         Log('rcmd', 'out', $field[2], $_);
355                                                 }
356                                                 delete $self->{remotecmd};
357                                         }
358                                 } else {
359                                         $self->send(pc35($main::mycall, $field[2], "$main::mycall:Tut tut tut...!"));
360                                 }
361                         } else {
362                                 route($field[1], $line);
363                         }
364                         return;
365                 }
366                 
367                 if ($pcno == 35) {              # remote command replies
368                         if ($field[1] eq $main::mycall) {
369                                 my $s = $rcmds{$field[2]};
370                                 if ($s) {
371                                         my $dxchan = DXChannel->get($s->{call});
372                                         $dxchan->send($field[3]) if $dxchan;
373                                         delete $rcmds{$field[2]} if !$dxchan;
374                                 }
375                         } else {
376                                 route($field[1], $line);
377                         }
378                         return;
379                 }
380                 
381                 if ($pcno == 37) {
382                         last SWITCH;
383                 }
384                 
385                 if ($pcno == 38) {              # node connected list from neighbour
386                         return;
387                 }
388                 
389                 if ($pcno == 39) {              # incoming disconnect
390                         $self->disconnect();
391                         return;
392                 }
393                 
394                 if ($pcno == 41) {              # user info
395                         # add this station to the user database, if required
396                         my $user = DXUser->get_current($field[1]);
397                         if (!$user) {
398                                 # then try without an SSID
399                                 $field[1] =~ s/-\d+$//o;
400                                 $user = DXUser->get_current($field[1]);
401                         }
402                         $user = DXUser->new($field[1]) if !$user;
403                         
404                         if ($field[2] == 1) {
405                                 $user->name($field[3]);
406                         } elsif ($field[2] == 2) {
407                                 $user->qth($field[3]);
408                         } elsif ($field[2] == 3) {
409                                 my ($lat, $long) = DXBearing::stoll($field[3]);
410                                 $user->lat($lat);
411                                 $user->long($long);
412                         } elsif ($field[2] == 4) {
413                                 $user->homenode($field[3]);
414                         }
415                         $user->put;
416                         last SWITCH;
417                 }
418                 if ($pcno == 43) {
419                         last SWITCH;
420                 }
421                 if ($pcno == 44) {
422                         last SWITCH;
423                 }
424                 if ($pcno == 45) {
425                         last SWITCH;
426                 }
427                 if ($pcno == 46) {
428                         last SWITCH;
429                 }
430                 if ($pcno == 47) {
431                         last SWITCH;
432                 }
433                 if ($pcno == 48) {
434                         last SWITCH;
435                 }
436                 
437                 if ($pcno == 50) {              # keep alive/user list
438                         my $ref = DXCluster->get_exact($field[1]);
439                         $ref->update_users($field[2]) if $ref;
440                         last SWITCH;
441                 }
442                 
443                 if ($pcno == 51) {              # incoming ping requests/answers
444                         
445                         # is it for us?
446                         if ($field[1] eq $main::mycall) {
447                                 my $flag = $field[3];
448                                 if ($flag == 1) {
449                                         $self->send(pc51($field[2], $field[1], '0'));
450                                 } else {
451                                         # it's a reply, look in the ping list for this one
452                                         my $ref = $pings{$field[2]};
453                                         if ($ref) {
454                                                 my $r = shift @$ref;
455                                                 my $dxchan = DXChannel->get($r->{call});
456                                                 $dxchan->send($dxchan->msg('pingi', $field[2], atime($main::systime), $main::systime - $r->{t})) if $dxchan;
457                                         }
458                                 }
459                                 
460                         } else {
461                                 # route down an appropriate thingy
462                                 route($field[1], $line);
463                         }
464                         return;
465                 }
466         }
467          
468          # if get here then rebroadcast the thing with its Hop count decremented (if
469          # there is one). If it has a hop count and it decrements to zero then don't
470          # rebroadcast it.
471          #
472          # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
473          #        REBROADCAST!!!!
474          #
475          
476         if (!$self->{isolate}) {
477                 broadcast_ak1a($line, $self); # send it to everyone but me
478         }
479 }
480
481 #
482 # This is called from inside the main cluster processing loop and is used
483 # for despatching commands that are doing some long processing job
484 #
485 sub process
486 {
487         my $t = time;
488         my @dxchan = DXChannel->get_all();
489         my $dxchan;
490         
491         foreach $dxchan (@dxchan) {
492                 next unless $dxchan->is_ak1a();
493                 next if $dxchan == $me;
494                 
495                 # send a pc50 out on this channel
496                 if ($t >= $dxchan->pc50_t + $DXProt::pc50_interval) {
497                         $dxchan->send(pc50());
498                         $dxchan->pc50_t($t);
499                 }
500         }
501         
502         my $key;
503         my $val;
504         my $cutoff;
505         if ($main::systime - 3600 > $last_hour) {
506                 $cutoff  = $main::systime - $pc11_dup_age;
507                 while (($key, $val) = each %dup) {
508                         delete $dup{$key} if $val < $cutoff;
509                 }
510                 $last_hour = $main::systime;
511         }
512 }
513
514 #
515 # finish up a pc context
516 #
517 sub finish
518 {
519         my $self = shift;
520         my $call = $self->call;
521         my $ref = DXCluster->get_exact($call);
522         
523         # unbusy and stop and outgoing mail
524         my $mref = DXMsg::get_busy($call);
525         $mref->stop_msg($self) if $mref;
526         
527         # broadcast to all other nodes that all the nodes connected to via me are gone
528         my @gonenodes = map { $_->dxchan == $self ? $_ : () } DXNode::get_all();
529         my $node;
530         
531         foreach $node (@gonenodes) {
532                 next if $node->call eq $call; 
533                 broadcast_ak1a(pc21($node->call, 'Gone'), $self) unless $self->{isolate}; # done like this 'cos DXNodes don't have a pc21 method
534                 $node->del();
535         }
536
537         # remove outstanding pings
538         delete $pings{$call};
539         
540         # now broadcast to all other ak1a nodes that I have gone
541         broadcast_ak1a(pc21($call, 'Gone.'), $self);
542         
543         Log('DXProt', $call . " Disconnected");
544         $ref->del() if $ref;
545 }
546
547 #
548 # some active measures
549 #
550
551 sub send_local_config
552 {
553         my $self = shift;
554         my $n;
555         my @nodes;
556         
557         # send our nodes
558         if ($self->{isolate}) {
559                 @nodes = (DXCluster->get_exact($main::mycall));
560         } else {
561                 # create a list of all the nodes that are not connected to this connection
562                 @nodes = DXNode::get_all();
563                 @nodes = grep { $_->dxchan != $self } @nodes;
564         }
565
566         my @s = $me->pc19(@nodes);
567         for (@s) {
568                 my $routeit = adjust_hops($self, $_);
569                 $self->send($_) if $routeit;
570         }
571         
572         # get all the users connected on the above nodes and send them out
573         foreach $n (@nodes) {
574                 my @users = values %{$n->list};
575                 my @s = pc16($n, @users);
576                 for (@s) {
577                         my $routeit = adjust_hops($self, $_);
578                         $self->send($_) if $routeit;
579                 }
580         }
581 }
582
583 #
584 # route a message down an appropriate interface for a callsign
585 #
586 # is called route(to, pcline);
587 #
588 sub route
589 {
590         my ($call, $line) = @_;
591         my $cl = DXCluster->get_exact($call);
592         if ($cl) {
593                 my $hops;
594                 my $dxchan = $cl->{dxchan};
595                 if ($dxchan) {
596                         my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
597                         if ($routeit) {
598                                 $dxchan->send($line) if $dxchan;
599                         }
600                 }
601         }
602 }
603
604 # broadcast a message to all clusters [except those mentioned after buffer]
605 sub broadcast_ak1a
606 {
607         my $s = shift;                          # the line to be rebroadcast
608         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
609         my @dxchan = get_all_ak1a();
610         my $dxchan;
611         
612         # send it if it isn't the except list and isn't isolated and still has a hop count
613         foreach $dxchan (@dxchan) {
614                 next if grep $dxchan == $_, @except;
615                 my $routeit = adjust_hops($dxchan, $s);      # adjust its hop count by node name       
616                 $dxchan->send($s) unless $dxchan->{isolate} || !$routeit; 
617         }
618 }
619
620 # broadcast to all users
621 sub broadcast_users
622 {
623         my $s = shift;                          # the line to be rebroadcast
624         my @except = @_;                        # to all channels EXCEPT these (dxchannel refs)
625         my @dxchan = get_all_users();
626         my $dxchan;
627         
628         foreach $dxchan (@dxchan) {
629                 next if grep $dxchan == $_, @except;
630                 $s =~ s/\a//og if !$dxchan->{beep};
631                 $dxchan->send($s);              # send it if it isn't the except list or hasn't a passout flag
632         }
633 }
634
635 # broadcast to a list of users
636 sub broadcast_list
637 {
638         my $s = shift;
639         my $dxchan;
640         
641         foreach $dxchan (@_) {
642                 $dxchan->send($s);              # send it 
643         }
644 }
645
646 #
647 # gimme all the ak1a nodes
648 #
649 sub get_all_ak1a
650 {
651         my @list = DXChannel->get_all();
652         my $ref;
653         my @out;
654         foreach $ref (@list) {
655                 push @out, $ref if $ref->is_ak1a;
656         }
657         return @out;
658 }
659
660 # return a list of all users
661 sub get_all_users
662 {
663         my @list = DXChannel->get_all();
664         my $ref;
665         my @out;
666         foreach $ref (@list) {
667                 push @out, $ref if $ref->is_user;
668         }
669         return @out;
670 }
671
672 # return a list of all user callsigns
673 sub get_all_user_calls
674 {
675         my @list = DXChannel->get_all();
676         my $ref;
677         my @out;
678         foreach $ref (@list) {
679                 push @out, $ref->call if $ref->is_user;
680         }
681         return @out;
682 }
683
684 #
685 # obtain the hops from the list for this callsign and pc no 
686 #
687
688 sub get_hops
689 {
690         my ($pcno) = @_;
691         my $hops = $DXProt::hopcount{$pcno};
692         $hops = $DXProt::def_hopcount if !$hops;
693         return "H$hops";       
694 }
695
696
697 # adjust the hop count on a per node basis using the user loadable 
698 # hop table if available or else decrement an existing one
699 #
700
701 sub adjust_hops
702 {
703         my $self = shift;
704         my $call = $self->{call};
705         my $hops;
706         
707         if (($hops) = $_[0] =~ /\^H(\d+)\^~?$/o) {
708                 my ($pcno) = $_[0] =~ /^PC(\d\d)/o;
709                 confess "$call called adjust_hops with '$_[0]'" unless $pcno;
710                 my $ref = $nodehops{$call} if %nodehops;
711                 if ($ref) {
712                         my $newhops = $ref->{$pcno};
713                         return 0 if defined $newhops && $newhops == 0;
714                         $newhops = $ref->{default} unless $newhops;
715                         return 0 if defined $newhops && $newhops == 0;
716                         $newhops = $hops if !$newhops;
717                         $_[0] =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
718                 } else {
719                         # simply decrement it
720                         $hops--;
721                         return 0 if !$hops;
722                         $_[0] =~ s/\^H(\d+)(\^~?)$/\^H$hops$2/ if $hops;
723                 }
724         }
725         return 1;
726 }
727
728
729 # load hop tables
730 #
731 sub load_hops
732 {
733         my $self = shift;
734         return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
735         do "$main::data/hop_table.pl";
736         return $@ if $@;
737         return 0;
738 }
739
740 # remove leading and trailing spaces from an input string
741 sub unpad
742 {
743         my $s = shift;
744         $s =~ s/^\s+|\s+$//;
745         return $s;
746 }
747
748 # add a ping request to the ping queues
749 sub addping
750 {
751         my ($from, $to) = @_;
752         my $ref = $pings{$to};
753         $ref = $pings{$to} = [] if !$ref;
754         my $r = {};
755         $r->{call} = $from;
756         $r->{t} = $main::systime;
757         route($to, pc51($to, $main::mycall, 1));
758         push @$ref, $r;
759 }
760
761 # add a rcmd request to the rcmd queues
762 sub addrcmd
763 {
764         my ($from, $to, $cmd) = @_;
765         my $r = {};
766         $r->{call} = $from;
767         $r->{t} = $main::systime;
768         $r->{cmd} = $cmd;
769         route($to, pc34($main::mycall, $to, $cmd));
770         $rcmds{$to} = $r;
771 }
772 1;
773 __END__