X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FThingy%2FPing.pm;h=02fc5cef51bea6caf1176bce93e4a98d4729d08a;hb=c3ba5929db3bd5343ae4ac17c4420155745be511;hp=edcd8fe741927acec6282f0ecd666cd195582ce6;hpb=dca951f539a50c396d7a94ad9f513a19892d54ad;p=spider.git diff --git a/perl/Thingy/Ping.pm b/perl/Thingy/Ping.pm index edcd8fe7..02fc5cef 100644 --- a/perl/Thingy/Ping.pm +++ b/perl/Thingy/Ping.pm @@ -31,7 +31,7 @@ sub gen_Aranea { my $thing = shift; unless ($thing->{Aranea}) { - $thing->{Aranea} = Aranea::genmsg($thing, qw(id)); + $thing->{Aranea} = Aranea::genmsg($thing, qw(id out o)); } return $thing->{Aranea}; } @@ -47,6 +47,21 @@ 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->{o}; + $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}; } @@ -81,45 +96,46 @@ sub handle my $repthing = $thing->new_reply; $repthing->{out} = 0; $repthing->{id} = $thing->{id}; + $repthing->{o} = $thing->{o} if $thing->{o}; $repthing->send($dxchan) if $repthing; } else { # it's a reply, look in the ping list for this one - my $ref = $ping{$thing->{id}} || $thing->find; + my $ref = $ping{$thing->{id}} if exists $thing->{id}; + $ref ||= find(($thing->{user}||$thing->{origin}), ($thing->{touser}||$thing->{group})); if ($ref) { - my $t = tv_interval($thing->{t}, [ gettimeofday ]); - if (my $dxc = DXChannel::get($thing->{user} || $thing->{origin})) { + my $t = tv_interval($ref->{t}, [ gettimeofday ]); + my $tochan = DXChannel::get($ref->{touser} || $ref->{group}); + if ($tochan) { + my $nopings = $tochan->user->nopings || $DXProt::obscount; + push @{$tochan->{pingtime}}, $t; + shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6; - my $tochan = DXChannel::get($thing->{touser} || $thing->{group}); + # 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 $dxc = DXChannel::get($ref->{user} || $ref->{origin})) { if ($dxc->is_user) { my $s = sprintf "%.2f", $t; my $ave = sprintf "%.2f", $tochan ? ($tochan->{pingave} || $t) : $t; - $dxc->send($dxc->msg('pingi', ($thing->{touser} || $thing->{group}), $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 - } - } + $dxc->send($dxc->msg('pingi', ($ref->{touser} || $ref->{group}), $s, $ave)) + } } + delete $ping{$ref->{id}}; } } } else { + $thing->{route} = $thing->{o} if $thing->{o}; $thing->broadcast($dxchan); } } @@ -165,10 +181,17 @@ sub forget sub find { - my $call = shift; + my $to = shift; + my $from = shift; + my $user = shift; + foreach my $thing (values %ping) { - if (($thing->{user} || $thing->{origin}) eq $call) { - return $thing; + if ($thing->{origin} eq $from && $thing->{group} eq $to) { + if ($user) { + return if $thing->{user} && $thing->{user} eq $user; + } else { + return $thing; + } } } return undef;