Change ping averaging to be like TCP and become a smoothed RTT.
[spider.git] / perl / DXProt.pm
index f5b6a81860d6a85a4ce5478d2322429f3ff3f86e..056402b9501257fc410ba747e72bfb3e49949e9b 100644 (file)
@@ -254,15 +254,14 @@ sub start
        $self->{pingint} = $ping;
        $self->{nopings} = $user->nopings || 2;
        $self->{pingtime} = [ ];
-       $self->{pingave} = 0;
+       $self->{pingave} = 999;
+       $self->{lastping} = $main::systime;
 
        # send initialisation string
        unless ($self->{outbound}) {
                $self->send(pc18());
-               $self->{lastping} = $main::systime;
-       } else {
-               $self->{lastping} = $main::systime + ($self->pingint / 2);
        }
+       
        $self->state('init');
        $self->{pc50_t} = $main::systime;
 
@@ -571,7 +570,15 @@ sub normal
                                
                                $conf = $conf eq '*';
 
-                               my $r = Route::User::get($call);
+                               # reject this if we think it is a node already
+                               my $r = Route::Node::get($call);
+                               my $u = DXUser->get_current($call) unless $r;
+                               if ($r || ($u && $u->is_node)) {
+                                       dbg("PCPROT: $call is a node") if isdbg('chanerr');
+                                       next;
+                               }
+                               
+                               $r = Route::User::get($call);
                                my $flags = Route::here($here)|Route::conf($conf);
                                
                                if ($r) {
@@ -622,17 +629,17 @@ sub normal
                                dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
                                return;
                        }
-                       my $parent = Route::Node::get($ncall);
-                       unless ($parent) {
-                               dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
-                               return;
-                       }
+
                        my $uref = Route::User::get($ucall);
                        unless ($uref) {
                                dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
                                return;
                        }
-                       
+                       my $parent = Route::Node::get($ncall);
+                       unless ($parent) {
+                               dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
+                               return;
+                       }                       
 
                        # input filter if required
                        return unless $self->in_filter_route($parent);
@@ -753,6 +760,7 @@ sub normal
                        $self->send_local_config();
                        $self->send(pc22());
                        $self->state('normal');
+                       $self->{lastping} = 0;
                        return;
                }
                
@@ -798,6 +806,7 @@ sub normal
                
                if ($pcno == 22) {
                        $self->state('normal');
+                       $self->{lastping} = 0;
                        return;
                }
                                
@@ -1037,7 +1046,12 @@ sub normal
                                                                        for (@{$tochan->{pingtime}}) {
                                                                                $st += $_;
                                                                        }
-                                                                       $tochan->{pingave} = $st / @{$tochan->{pingtime}};
+                                                                       if (@{$tochan->{pingtime}} == 1) {
+                                                                               $tochan->{pingave} = $t;
+                                                                       } else {
+                                                                               $tochan->{pingave} = $tochan->{pingave} + (($t - $tochan->{pingave}) / 8);
+                                                                       }
+#                                                                      $tochan->{pingave} = $st / @{$tochan->{pingtime}};
                                                                }
                                                        } 
                                                }