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