reduce the number of duplicate PC92 for Ext Nodes
authorDirk Koopman <djk@tobit.co.uk>
Sun, 16 Sep 2007 17:01:53 +0000 (18:01 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sun, 16 Sep 2007 17:01:53 +0000 (18:01 +0100)
Try to reduce the no of duplicate PC92C for external PC protocol
nodes by listening for others that are out there and bumping up our
update time instead of us transmitting more or less the same info
as well.

perl/DXProt.pm
perl/DXProtHandle.pm
perl/DXProtout.pm
perl/Route/Node.pm
perl/Version.pm

index e1bfd6ec6a59236e0c9218a463ccc2ba623d6073..e9fa42b6d4384418b84da43f319aa738638cf1bf 100644 (file)
@@ -72,7 +72,7 @@ $obscount = 2;
 $chatdupeage = 20 * 60;
 $chatimportfn = "$main::root/chat_import";
 $investigation_int = 12*60*60; # time between checks to see if we can see this node
-$pc19_version = 5466;                  # the visible version no for outgoing PC19s generated from pc59
+$pc19_version = 5454;                  # the visible version no for outgoing PC19s generated from pc59
 $pc92_update_period = 60*60;   # the period between outgoing PC92 C updates
 $pc92_short_update_period = 15*60; # shorten the update period after a connection
 %pc92_find = ();                               # outstanding pc92 find operations
@@ -481,11 +481,20 @@ sub process
                        next unless $dxchan->is_node;
 
                        # send out a PC92 config record if required for me and
-                       # all my non pc9x dependent nodes.
+                       # all my non pc9x dependent nodes. But for dependent nodes we only do
+                       # this if we have not seen any from anyone else for at least half
+                       # of one update period. This should stop quite a bit of excess C
+                       # records. Someone will win, it does not really matter who, because
+                       # we always believe "us".
                        if ($main::systime >= $dxchan->{next_pc92_update}) {
                                dbg("ROUTE: pc92 broadcast candidate: $dxchan->{call}") if isdbg('obscount');
                                if ($dxchan == $main::me || !$dxchan->{do_pc9x}) {
-                                       $dxchan->broadcast_pc92_update($dxchan->{call});
+                                       my $ref = Route::Node::get($dxchan->{call});
+                                       if ($dxchan == $main::me || ($ref && ($ref->measure_pc9x_t($main::systime-$main::systime_daystart)) >= $pc92_update_period/2)) {
+                                               $dxchan->broadcast_pc92_update($dxchan->{call});
+                                       } else {
+                                               $dxchan->update_pc92_next($pc92_update_period - rand(60));
+                                       }
                                }
                        }
                }
@@ -925,6 +934,7 @@ sub broadcast_pc92_update
                return;
        }
        my $l = $nref->last_PC92C(gen_my_pc92_config($nref));
+       $nref->lastid(last_pc9x_id());
        $main::me->broadcast_route_pc9x($main::mycall, undef, $l, 0);
        $self->update_pc92_next($pc92_update_period);
 }
index 6b8a4cd8e00dfe3063759c05d085b4e585f44e3b..4d69b1aa872b4cadb45feb6786091d5721faea4e 100644 (file)
@@ -592,16 +592,6 @@ sub handle_18
                        $self->sort('S');
                }
 #              $self->{handle_xml}++ if DXXml::available() && $_[1] =~ /\bxml/;
-               if ($_[1] =~ /\bpc9x/) {
-                       if ($self->{isolate}) {
-                               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}");
-                       }
-               }
        } else {
                dbg("Unknown software");
                $self->version(50.0);
@@ -609,6 +599,17 @@ sub handle_18
                $self->user->version($self->version);
        }
 
+       if ($_[1] =~ /\bpc9x/) {
+               if ($self->{isolate}) {
+                       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}");
+               }
+       }
+
        # first clear out any nodes on this dxchannel
        my @rout = $parent->del_nodes;
        $self->route_pc21($origin, $line, @rout, $parent) if @rout;
@@ -1440,16 +1441,22 @@ sub clear_pc92_changes
 
 my $_last_time;
 my $_last_occurs;
+my $_last_pc9x_id;
+
+sub last_pc9x_id
+{
+       return $_last_pc9x_id;
+}
 
 sub gen_pc9x_t
 {
        if (!$_last_time || $_last_time != $main::systime) {
                $_last_time = $main::systime;
                $_last_occurs = 0;
-               return $_last_time - $main::systime_daystart;
+               return $_last_pc9x_id = $_last_time - $main::systime_daystart;
        } else {
                $_last_occurs++;
-               return sprintf "%d.%02d", $_last_time - $main::systime_daystart, $_last_occurs;
+               return $_last_pc9x_id = sprintf "%d.%02d", $_last_time - $main::systime_daystart, $_last_occurs;
        }
 }
 
@@ -1613,8 +1620,10 @@ sub handle_92
                                }
                                # 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.
+                               # locally connected. Local nodes always take precedence. But we remember the lastid
+                               # to try to reduce the number of dupe PC92s for this external node.
                                if (DXChannel::get($call) && $call ne $self->{call}) {
+                                       $parent = check_pc9x_t($call, $t, 92); # this will update the lastid time
                                        dbg("PCPROT: locally connected node $call from other another node $self->{call}, ignored") if isdbg('chanerr');
                                        return;
                                }
@@ -1639,7 +1648,7 @@ sub handle_92
                                return;
                        }
                        $parent->here(Route::here($here));
-                       $parent->version($version) if $version && $version > $parent->version;
+                       $parent->version($version || $pc19_version) if $version;
                        $parent->build($build) if $build && $build > $parent->build;
                        $parent->PC92C_dxchan($self->{call}) unless $self->{call} eq $parent->call;
                        shift @ent;
index c024724f44ee51f8ac48d5f092c6a85dbdae41d2..4f4da1e50677953c3d1a8235703f0e22849abff2 100644 (file)
@@ -19,7 +19,7 @@ use DXDebug;
 
 use strict;
 
-use vars qw($sentencelth);
+use vars qw($sentencelth $pc19_version);
 
 $sentencelth = 180;
 
@@ -137,6 +137,8 @@ sub pc19
                my $here = $ref->here;
                my $conf = $ref->conf;
                my $version = $ref->version;
+               $version = $pc19_version unless $version =~ /^\d\d\d\d$/;
+
                my $str = "^$here^$call^$conf^$version";
                if (length($s) + length($str) > $sentencelth) {
                        push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
index c1fcc5435f05d33505d1f2df3d3045dc6c30b7b9..6e7d931541c89d48722085be2c8363848e640b93 100644 (file)
@@ -360,6 +360,18 @@ sub reset_obs
        $self->{obscount} = $obscount;
 }
 
+sub measure_pc9x_t
+{
+       my $parent = shift;
+       my $t = shift;
+       my $lastid = $parent->{lastid};
+       if ($lastid) {
+               return ($t < $lastid) ? $t+86400-$lastid : $t - $lastid;
+       } else {
+               return 86400;
+       }
+}
+
 sub DESTROY
 {
        my $self = shift;
index 97d0adb57e847dca4b825c88097e0232765274bd..fce61901b2f5ca740a91f09adf0cde69f4213734 100644 (file)
@@ -11,6 +11,6 @@ use vars qw($version $subversion $build);
 
 $version = '1.54';
 $subversion = '0';
-$build = '141';
+$build = '142';
 
 1;