detail changes
[spider.git] / perl / DXProt.pm
index 9df3b3d1d4f1d0eb9b416252acdd53bab0d9c568..9227652c43801b7879142b8728782034ac705a67 100644 (file)
@@ -44,7 +44,7 @@ $main::build += $VERSION;
 $main::branch += $BRANCH;
 
 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
-                       $last_hour $last10 %eph  %pings %rcmds $ann_to_talk
+                       $last_hour $last10 %eph  %pings %rcmds $ann_to_talk $pc19_version
                        $pingint $obscount %pc19list $chatdupeage $investigation_int
                        %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
                        $allowzero $decode_dk0wcy $send_opernam @checklist);
@@ -73,6 +73,8 @@ $pingint = 5*60;
 $obscount = 2;
 $chatdupeage = 20 * 60 * 60;
 $investigation_int = 7*86400;  # time between checks to see if we can see this node
+$pc19_version = 5466;                  # the visible version no for outgoing PC19s generated from pc59
+
 
 @checklist = 
 (
@@ -231,7 +233,7 @@ sub new
        my $uref = Route::Node::get($call) || Route::Node->new($call);
        $uref->here(1);
        $uref->conf(0);
-       $uref->version(5000);
+       $uref->version($pc19_version);
        $main::routeroot->link_node($uref, $self);
        return $self;
 }
@@ -710,6 +712,9 @@ sub handle_16
 
        # do we believe this call? 
        unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
+               if (my $ivp = Investigate::get($ncall, $self->{call})) {
+                       $ivp->store_pcxx($pcno,$line,$origin,@_);
+               }
                dbg("PCPROT: We don't believe $ncall on $self->{call}");
                return;
        }
@@ -790,6 +795,9 @@ sub handle_17
 
        # do we believe this call? 
        unless ($ncall eq $self->{call} || $self->is_believed($ncall)) {
+               if (my $ivp = Investigate::get($ncall, $self->{call})) {
+                       $ivp->store_pcxx($pcno,$line,$origin,@_);
+               }
                dbg("PCPROT: We don't believe $ncall on $self->{call}");
                return;
        }
@@ -928,10 +936,11 @@ sub handle_19
                # do we believe this call? 
                unless ($call eq $self->{call} || $self->is_believed($call)) {
                        my $pt = $user->lastping || 0;
-                       if ($pt+$investigation_int < $main::systime && !Investigate::get($call)) {
-                               my $iref = Investigate->new($call);
-                               $iref->version($ver);
-                               $iref->here($here);
+                       if ($pt+$investigation_int < $main::systime && !Investigate::get($call, $self->{call})) {
+                               my $ivp  = Investigate->new($call, $self->{call});
+                               $ivp->version($ver);
+                               $ivp->here($here);
+                               $ivp->store_pcxx($pcno,$line,$origin,'PC19',$here,$call,$conf,$ver,$_[-1]);
                        }
                        dbg("PCPROT: We don't believe $call on $self->{call}");
                        next;
@@ -985,6 +994,9 @@ sub handle_21
        return if $call eq $main::mycall;  # don't allow malicious buggers to disconnect me (or ignore loops)!
 
        unless ($call eq $self->{call} || $self->is_believed($call)) {
+               if (my $ivp = Investigate::get($call, $self->{call})) {
+                       $ivp->store_pcxx($pcno,$line,$origin,@_);
+               }
                dbg("PCPROT: We don't believe $call on $self->{call}");
                return;
        }
@@ -1015,11 +1027,11 @@ sub handle_21
                # input filter it
                return unless $self->in_filter_route($node);
                push @rout, $node;
-               push @new, $node->link_node($parent, $self);
+               push @new, $parent->remove_route($node, $self);
        }
 
        $self->route_pc21($origin, $line, @new) if @new;
-       $self->route_pc59('D', 0, $self->{call}, @rout) if @rout;
+       $self->route_pc59('D', hexstamp(), $self->{call}, @rout) if @rout;
 
        # get rid of orphaned nodes;
        $_->delete for @new;
@@ -1413,12 +1425,18 @@ sub handle_51
                                                        my $rref = Route::Node::get($tochan->{call});
                                                        $rref->pingtime($tochan->{pingave}) if $rref;
                                                        $tochan->{nopings} = $nopings; # pump up the timer
+                                                       if (my $ivp = Investigate::get($from, $self->{call})) {
+                                                               $ivp->handle_ping;
+                                                       }
                                                } elsif (my $rref = Route::Node::get($r->{call})) {
                                                        if (defined $rref->pingtime) {
                                                                $rref->pingtime($rref->pingtime + (($t - $rref->pingtime) / 6));
                                                        } else {
                                                                $rref->pingtime($t);
                                                        }
+                                                       if (my $ivp = Investigate::get($from, $self->{call})) {
+                                                               $ivp->handle_ping;
+                                                       }
                                                }
                                        } 
                                }
@@ -1547,7 +1565,7 @@ sub handle_59
                                my $new = $node->link_node($ref, $self);
                                push @addnode, $new if $new;
                        } elsif ($ref->isa('Route::User')) {
-                               push @adduser, $node->del_user($ref);
+                               push @adduser, $node->add_user($ref);
                        }
                }
        }
@@ -1581,6 +1599,7 @@ sub handle_59
                                push @au, $r unless grep $r->call eq $_, $node->users;
                        }
                }
+               push @addnode, $node if $self->{state} =~ /^init/;
                push @delnode, $node->unlink_node($_, $self) for @dn;
                push @deluser, $node->del_user($_) for @du;
                push @addnode, $node->link_node($_, $self) for @an;
@@ -1589,8 +1608,8 @@ sub handle_59
 
        $self->route_pc21($origin, $line, @delnode) if @delnode;
        $self->route_pc19($origin, $line, @addnode) if @addnode;
-       $self->route_pc17($origin, $line, @deluser) if @deluser;
-       $self->route_pc16($origin, $line, @adduser) if @adduser;
+       $self->route_pc17($origin, $line, $node, @deluser) if @deluser;
+       $self->route_pc16($origin, $line, $node, @adduser) if @adduser;
        
        $self->route_pc59($sort, $hextime, $ncall, @refs) if @refs;
        $_->delete for @delnode, @deluser;
@@ -1692,6 +1711,8 @@ sub handle_default
 # This is called from inside the main cluster processing loop and is used
 # for despatching commands that are doing some long processing job
 #
+# It is called once per second
+#
 sub process
 {
        my $t = time;
@@ -1725,6 +1746,8 @@ sub process
                }
        }
 
+       Investigate::process();
+       
        # every ten seconds
        if ($t - $last10 >= 10) {       
                # clean out ephemera 
@@ -2165,16 +2188,23 @@ sub load_hops
 # add a ping request to the ping queues
 sub addping
 {
-       my ($from, $to) = @_;
+       my ($from, $to, $via) = @_;
        my $ref = $pings{$to} || [];
        my $r = {};
        $r->{call} = $from;
        $r->{t} = [ gettimeofday ];
-       route(undef, $to, pc51($to, $main::mycall, 1));
+       if ($via && (my $dxchan = DXChannel->get($via))) {
+               $dxchan->send(pc51($to, $main::mycall, 1));
+       } else {
+               route(undef, $to, pc51($to, $main::mycall, 1));
+       }
        push @$ref, $r;
        $pings{$to} = $ref;
        my $u = DXUser->get_current($to);
-       $u->lastping($main::systime) if $u;
+       if ($u) {
+               $u->lastping($main::systime);
+               $u->put;
+       }
 }
 
 sub process_rcmd