try a better arc diddle
[spider.git] / perl / DXProt.pm
index c26016ee5048ce9205175a484ae042c3be8b1b31..d6ea691796e82c3078f04d8aa1c41cc6e4c50b5e 100644 (file)
@@ -1039,14 +1039,28 @@ sub normal
                                                                $dxchan->send($dxchan->msg('pingi', $from, $s, $ave))
                                                        } elsif ($dxchan->is_node) {
                                                                if ($tochan) {
-                                                                       $tochan->{nopings} = $tochan->user->nopings || 2; # pump up the timer
+                                                                       my $nopings = $tochan->user->nopings || 2;
                                                                        push @{$tochan->{pingtime}}, $t;
                                                                        shift @{$tochan->{pingtime}} if @{$tochan->{pingtime}} > 6;
-                                                                       my $st;
-                                                                       for (@{$tochan->{pingtime}}) {
-                                                                               $st += $_;
+
+                                                                       # cope with a missed ping, this means you must set the pingint large enough
+                                                                       my $miss = ($nopings-$tochan->{nopings}+1) * $tochan->{pingint}; 
+                                                                       if ($tochan->is_arcluster && $miss > 0 && $t > $miss  && $t < $miss + $tochan->{nopings} ) {
+                                                                               $t -= $miss;
+                                                                       }
+
+                                                                       # calc smoothed RTT a la TCP
+                                                                       if (@{$tochan->{pingtime}} == 1) {
+                                                                               $tochan->{pingave} = $t;
+                                                                       } else {
+                                                                               $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 8);
                                                                        }
-                                                                       $tochan->{pingave} = $st / @{$tochan->{pingtime}};
+#                                                                      my $st;
+#                                                                      for (@{$tochan->{pingtime}}) {
+#                                                                              $st += $_;
+#                                                                      }
+#                                                                      $tochan->{pingave} = $st / @{$tochan->{pingtime}};
+                                                                       $tochan->{nopings} = $nopings; # pump up the timer
                                                                }
                                                        } 
                                                }