X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy%2FPing.pm;h=30359a422e7b6b89e22fef22c9a074d51a96a29c;hb=5def24d66561e13e76b7af3109810be21deeeffb;hp=39fd55bac40499b40d414c951f86553f6d70b56d;hpb=7d72afb65bc994c04c208095b66abddee41de7e9;p=spider.git diff --git a/perl/Thingy/Ping.pm b/perl/Thingy/Ping.pm index 39fd55ba..30359a42 100644 --- a/perl/Thingy/Ping.pm +++ b/perl/Thingy/Ping.pm @@ -11,26 +11,27 @@ use strict; package Thingy::Ping; use vars qw($VERSION $BRANCH); -$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += $VERSION; -$main::branch += $BRANCH; + +main::mkver($VERSION = q$Revision$); use DXChannel; use DXDebug; use DXUtil; use Thingy; use Spot; +use Time::HiRes qw(gettimeofday tv_interval); + -use vars qw(@ISA); +use vars qw(@ISA %ping); @ISA = qw(Thingy); +my $id; + sub gen_Aranea { my $thing = shift; unless ($thing->{Aranea}) { - my @items; - $thing->{Aranea} = Aranea::genmsg($thing, 'Rloc', @items); + $thing->{Aranea} = Aranea::genmsg($thing, qw(id out)); } return $thing->{Aranea}; } @@ -46,6 +47,19 @@ sub gen_DXProt { my $thing = shift; my $dxchan = shift; + unless ($thing->{DXProt}) { + # we need to tease out the nodes out of all of this. + # bear in mind that a proxied PC prot node could be in + # {user} as well as a true user and also it may not + # have originated here. + + my $from = $thing->{user} if Route::Node::get($thing->{user}); + $from ||= $thing->{origin}; + my $to = $thing->{touser} if Route::Node::get($thing->{touser}); + $to ||= $thing->{group}; + + $thing->{DXProt} = DXProt::pc51($to, $from, $thing->{out}); + } return $thing->{DXProt}; } @@ -60,12 +74,12 @@ sub gen_DXCommandmode sub from_DXProt { - my $thing = shift; + my $thing = ref $_[0] ? shift : $_[0]->SUPER::new(); + while (@_) { my $k = shift; $thing->{$k} = shift; } - ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt}; return $thing; } @@ -74,41 +88,110 @@ sub handle my $thing = shift; my $dxchan = shift; - $thing->broadcast($dxchan); + # is it for us? + if ($thing->{group} eq $main::mycall) { + if ($thing->{out} == 1) { + my $repthing = $thing->new_reply; + $repthing->{out} = 0; + $repthing->{id} = $thing->{id}; + $repthing->send($dxchan) if $repthing; + } else { + + # it's a reply, look in the ping list for this one + my $ref = $ping{$thing->{id}} if exists $thing->{id}; + $ref ||= find($thing->{origin}, $thing->{group}); + if ($ref) { + my $t = tv_interval($ref->{t}, [ gettimeofday ]); + if (my $dxc = DXChannel::get($ref->{user} || $ref->{origin})) { + + my $tochan = DXChannel::get($ref->{touser} || $ref->{group}); + + if ($dxc->is_user) { + my $s = sprintf "%.2f", $t; + my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t; + $dxc->send($dxc->msg('pingi', $ref->{user}, $s, $ave)) + } elsif ($dxc->is_node) { + if ($tochan ) { + my $nopings = $tochan->user->nopings || $DXProt::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 + } + } + } + } + } + } else { + $thing->broadcast($dxchan); + } } -sub in_filter +# 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(@_); +} + +# do this for pings we generate ourselves +sub remember { my $thing = shift; - my $dxchan = shift; - - # global route filtering on INPUT - if ($dxchan->{inroutefilter}) { - my ($filter, $hops) = $dxchan->{inroutefilter}->it($thing->{routedata}); - unless ($filter) { - dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr'); - return; + $thing->{t} = [ gettimeofday ]; + $thing->{out} = 1; + $thing->{id} = ++$id; + my $u = DXUser->get_current($thing->{to}); + if ($u) { + $u->lastping(($thing->{user} || $thing->{group}), $main::systime); + $u->put; + } + $ping{$id} = $thing; +} + +# remove any pings outstanding that we have remembered for this +# callsign, return the number of forgotten pings +sub forget +{ + my $call = shift; + my $count = 0; + my @out; + foreach my $thing (values %ping) { + if (($thing->{user} || $thing->{group}) eq $call) { + $count++; + delete $ping{$thing->{id}}; } } - return 1; + return $count; } -sub out_filter +sub find { - my $thing = shift; - my $dxchan = shift; + my $to = shift; + my $from = shift; + my $user = shift; - # global route filtering on INPUT - if ($dxchan->{routefilter}) { - my ($filter, $hops) = $dxchan->{routefilter}->it($thing->{routedata}); - unless ($filter) { - dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr'); - return; + foreach my $thing (values %ping) { + if ($thing->{origin} eq $from && $thing->{group} eq $to) { + if ($user) { + return if $thing->{user} && $thing->{user} eq $user; + } else { + return $thing; + } } - $thing->{hops} = $hops if $hops; - } elsif ($dxchan->{isolate}) { - return; } - return 1; + return undef; } 1;