6 # Copyright (c) 2005 Dirk Koopman G1TLH
13 use vars qw($VERSION $BRANCH);
15 main::mkver($VERSION = q$Revision$);
22 use Time::HiRes qw(gettimeofday tv_interval);
25 use vars qw(@ISA %ping);
33 unless ($thing->{Aranea}) {
34 $thing->{Aranea} = Aranea::genmsg($thing, qw(id));
36 return $thing->{Aranea};
50 return $thing->{DXProt};
64 my $thing = ref $_[0] ? shift : $_[0]->SUPER::new();
79 if ($thing->{group} eq $main::mycall) {
80 if ($thing->{out} == 1) {
81 my $repthing = $thing->new_reply;
83 $repthing->{id} = $thing->{id};
84 $repthing->send($dxchan) if $repthing;
87 # it's a reply, look in the ping list for this one
88 my $ref = $ping{$thing->{id}} || $thing->find;
90 my $t = tv_interval($thing->{t}, [ gettimeofday ]);
91 if (my $dxc = DXChannel::get($thing->{user} || $thing->{origin})) {
93 my $tochan = DXChannel::get($thing->{touser} || $thing->{group});
96 my $s = sprintf "%.2f", $t;
97 my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
98 $dxc->send($dxc->msg('pingi', ($thing->{touser} || $thing->{group}), $s, $ave))
99 } elsif ($dxc->is_node) {
101 my $nopings = $tochan->user->nopings || $DXProt::obscount;
102 push @{$tochan->{pingtime}}, $t;
103 shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
105 # cope with a missed ping, this means you must set the pingint large enough
106 if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
107 $t -= $tochan->{pingint};
110 # calc smoothed RTT a la TCP
111 if (@{$tochan->{pingtime}} == 1) {
112 $tochan->{pingave} = $t;
114 $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
116 $tochan->{nopings} = $nopings; # pump up the timer
123 $thing->broadcast($dxchan);
127 # this just creates a ping for onward transmission
128 # remember it if you want to ping someone from here
132 my $thing = $pkg->SUPER::new(@_);
135 # do this for pings we generate ourselves
139 $thing->{t} = [ gettimeofday ];
141 $thing->{id} = ++$id;
142 my $u = DXUser->get_current($thing->{to});
144 $u->lastping(($thing->{user} || $thing->{group}), $main::systime);
150 # remove any pings outstanding that we have remembered for this
151 # callsign, return the number of forgotten pings
157 foreach my $thing (values %ping) {
158 if (($thing->{user} || $thing->{group}) eq $call) {
160 delete $ping{$thing->{id}};
169 foreach my $thing (values %ping) {
170 if (($thing->{user} || $thing->{origin}) eq $call) {