+ # is it for us?
+ if ($thing->{group} eq $main::mycall) {
+ if ($thing->{out} == 1) {
+ my $repthing;
+ if ($thing->{touser}) {
+ if (my $dxchan = DXChannel::get($thing->{touser})) {
+ if ($dxchan->is_node) {
+ $thing->send($dxchan);
+ } else {
+ $repthing = Thingy::Ping->new_reply($thing);
+ }
+ }
+ } else {
+ $repthing = Thingy::Ping->new_reply($thing);
+ }
+ $repthing->send($dxchan) if $repthing;
+ } else {
+
+ # it's a reply, look in the ping list for this one
+ my $ref = $pings{$from};
+ if ($ref) {
+ my $tochan = DXChannel::get($from);
+ while (@$ref) {
+ my $r = shift @$ref;
+ my $dxchan = DXChannel::get($r->{call});
+ next unless $dxchan;
+ my $t = tv_interval($r->{t}, [ gettimeofday ]);
+ if ($dxchan->is_user) {
+ my $s = sprintf "%.2f", $t;
+ my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t;
+ $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
+ } elsif ($dxchan->is_node) {
+ if ($tochan) {
+ my $nopings = $tochan->user->nopings || $obscount;
+ push @{$tochan->{pingtime}}, $t;
+ shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
+
+ # cope with a missed ping, this means you must set the pingint large enough
+ if ($t > $tochan->{pingint} && $t < 2 * $tochan->{pingint} ) {
+ $t -= $tochan->{pingint};
+ }
+
+ # calc smoothed RTT a la TCP
+ if (@{$tochan->{pingtime}} == 1) {
+ $tochan->{pingave} = $t;
+ } else {
+ $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 6);
+ }
+ $tochan->{nopings} = $nopings; # pump up the timer
+ if (my $ivp = Investigate::get($from, $origin)) {
+ $ivp->handle_ping;
+ }
+ } elsif (my $rref = Route::Node::get($r->{call})) {
+ if (my $ivp = Investigate::get($from, $origin)) {
+ $ivp->handle_ping;
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ $thing->broadcast($dxchan);
+ }
+}
+
+# this just creates a ping for onward transmission
+# remember it if you want to ping someone from here
+sub new_ping
+{
+ my $pkg = shift;
+ my $thing = $pkg->SUPER::new(@_);