6 # Copyright (c) 2005 Dirk Koopman G1TLH
13 use vars qw($VERSION $BRANCH);
15 main::mkver($VERSION = q$Revision$);
23 use vars qw(@ISA @ping);
31 unless ($thing->{Aranea}) {
32 $thing->{Aranea} = Aranea::genmsg($thing);
34 return $thing->{Aranea};
48 return $thing->{DXProt};
62 my $thing = ref $_[0] ? shift : $thing->SUPER::new();
77 if ($thing->{group} eq $main::mycall) {
78 if ($thing->{out} == 1) {
80 if ($thing->{touser}) {
81 if (my $dxchan = DXChannel::get($thing->{touser})) {
82 if ($dxchan->is_node) {
83 $thing->send($dxchan);
85 $repthing = Thingy::Ping->new_reply($thing);
89 $repthing = Thingy::Ping->new_reply($thing);
91 $repthing->send($dxchan) if $repthing;
94 # it's a reply, look in the ping list for this one
95 my $ref = $pings{$from};
97 my $tochan = DXChannel::get($from);
100 my $dxchan = DXChannel::get($r->{call});
102 my $t = tv_interval($r->{t}, [ gettimeofday ]);
103 if ($dxchan->is_user) {
104 my $s = sprintf "%.2f", $t;
105 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
106 $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
107 } elsif ($dxchan->is_node) {
109 my $nopings = $tochan->user->nopings || $obscount;
110 push @{$tochan->{pingtime}}, $t;
111 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
113 # cope with a missed ping, this means you must set the pingint large enough
114 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
115 $t -= $tochan->{pingint};
118 # calc smoothed RTT a la TCP
119 if (@{$tochan->{pingtime}} == 1) {
120 $tochan->{pingave} = $t;
122 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
124 $tochan->{nopings} = $nopings; # pump up the timer
125 if (my $ivp = Investigate::get($from, $origin)) {
128 } elsif (my $rref = Route::Node::get($r->{call})) {
129 if (my $ivp = Investigate::get($from, $origin)) {
138 $thing->broadcast($dxchan);
142 # this just creates a ping for onward transmission
143 # remember it if you want to ping someone from here
147 my $thing = $pkg->SUPER::new(@_);
150 # do this for pings we generate ourselves
154 $thing->{t} = [ gettimeofday ];
156 $thing->{id} = ++$id;
157 my $u = DXUser->get_current($thing->{to});
159 $u->lastping(($thing->{group} || $thing->{user}), $main::systime);
165 # remove any pings outstanding that we have remembered for this
166 # callsign, return the number of forgotten pings
173 if ($thing->{user} eq $call) {
190 if ($_->{user} eq $from && $_->{to} eq $to) {
192 return $_ if $_->{group} eq $via;