try to make sure that local nodes take precedence over external ones
[spider.git] / perl / DXProtHandle.pm
index b4d80ab09957fccdea84ccceeaa7d5ef077a587e..5e3f0597d9405d2279ad1d7fab742a3da36b39ff 100644 (file)
@@ -46,7 +46,8 @@ use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restim
                        $eph_pc15_restime $pc9x_past_age $pc9x_future_age
                   );
 
-$pc9x_past_age = 15*60;                        # maximum age in the past of a px9x
+$pc9x_past_age = 62*60;                        # maximum age in the past of a px9x (a config record might be the only
+                                                               # thing a node might send - once an hour)
 $pc9x_future_age = 5*60;               # maximum age in the future ditto
 
 # incoming talk commands
@@ -582,7 +583,9 @@ sub handle_18
 #              $self->{handle_xml}++ if DXXml::available() && $_[1] =~ /\bxml/;
                if ($_[1] =~ /\bpc9x/) {
                        if ($self->{isolate}) {
-                               dbg("pc9x recognised, but is isolated, using old protocol");
+                               dbg("pc9x recognised, but $self->{call} is isolated, using old protocol");
+                       } elsif (!$self->user->wantpc9x) {
+                               dbg("pc9x explicitly switched off on $self->{call}, using old protocol");
                        } else {
                                $self->{do_pc9x} = 1;
                                dbg("Do px9x set on $self->{call}");
@@ -1420,14 +1423,19 @@ sub check_pc9x_t
                if ($parent->call ne $main::mycall) {
                        my $lastid = $parent->lastid->{$pc} || 0;
                        if ($t < $lastid) {
-                               if ($lastid-86400+$t > $pc9x_past_age) {
-                                       dbg("PCPROT: dup id on $t <= $lastid (midnight rollover), ignored") if isdbg('chanerr');
+                               if ($t+86400-$lastid > $pc9x_past_age) {
+                                       dbg("PCPROT: dup id on $t <= $lastid, ignored") if isdbg('chanerr');
                                        return;
                                }
-                       }
-                       if ($lastid >= $t) {
-                               dbg("PCPROT: dup id on $call $lastid >= $t, ignored") if isdbg('chanerr');
+                       } elsif ($t == $lastid) {
+                               dbg("PCPROT: dup id on $t == $lastid, ignored") if isdbg('chanerr');
                                return;
+                       } else {
+                               # $t > $lastid, check that the timestamp offered isn't too far away from 'now'
+                               if ($t+$main::systime_daystart-$main::systime > $pc9x_future_age ) {
+                                       dbg("PCPROT: id $t too far in the future, ignored") if isdbg('chanerr');
+                                       return;
+                               }
                        }
                }
        } elsif ($create) {
@@ -1462,9 +1470,17 @@ sub handle_92
        }
 
        if ($pcall eq $self->{call} && $self->{state} eq 'init') {
-               $self->state('init92');
-               $self->{do_pc9x} = 1;
-               dbg("Do pc9x set on $pcall");
+               if ($self->{isolate}) {
+                       dbg("PC9x received, but $pcall is isolated, ignored");
+                       return;
+               } elsif (!$self->user->wantpc9x) {
+                       dbg("PC9x explicitly switched off on $pcall, ignored");
+                       return;
+               } else {
+                       $self->state('init92');
+                       $self->{do_pc9x} = 1;
+                       dbg("Do pc9x set on $pcall");
+               }
        }
        unless ($self->{do_pc9x}) {
                dbg("PCPROT: PC9x come in from non-PC9x node, ignored") if isdbg('chanerr');
@@ -1544,12 +1560,14 @@ sub handle_92
                                                dbg("PCPROT: $call looped back onto $main::mycall, ignored") if isdbg('chanerr');
                                                return;
                                        }
+                                       # this is only accepted from my "self".
+                                       # this also kills configs from PC92 nodes with external PC19 nodes that are also
+                                       # locally connected. Local nodes always take precedence.
+                                       if (DXChannel::get($call) && $call ne $self->{call}) {
+                                               dbg("PCPROT: locally connected node $call from other another node $self->{call}, ignored") if isdbg('chanerr');
+                                               return;
+                                       }
                                        if ($is_extnode) {
-                                               # this is only accepted from my "self"
-                                               if (DXChannel::get($call) && $call ne $self->{call}) {
-                                                       dbg("PCPROT: locally connected node config for $call from other another node $self->{call}, ignored") if isdbg('chanerr');
-                                                       return;
-                                               }
                                                # reparent to external node (note that we must have received a 'C' or 'A' record
                                                # from the true parent node for this external before we get one for the this node
                                                unless ($parent = Route::Node::get($call)) {
@@ -1677,6 +1695,12 @@ sub handle_93
                dbg("PCPROT: invalid callsign string '$_[1]', ignored") if isdbg('chanerr');
                return;
        }
+
+       unless ($self->{do_pc9x}) {
+               dbg("PCPROT: PC9x come in from non-PC9x node, ignored") if isdbg('chanerr');
+               return;
+       }
+
        my $t = $_[2];
        my $parent = check_pc9x_t($pcall, $t, 93, 1) || return;
 
@@ -1742,7 +1766,7 @@ sub handle_93
                my $wx = uc $to eq 'WX' ? '1' : '0';
                my $local = $via eq 'LOCAL' ? '*' : $via;
 
-               $self->send_announce(1, pc12($from, $text, $local, $via, $sysop, $wx, $pcall), $from, $local, $text, $sysop, $pcall, $wx, $via eq 'LOCAL' ? $via : undef);
+               $self->send_announce(1, pc12($from, $text, $local, $sysop, $wx, $pcall), $from, $local, $text, $sysop, $pcall, $wx, $via eq 'LOCAL' ? $via : undef);
                return if $via eq 'LOCAL';
        } else {
                # chat messages to non-pc9x nodes