From 937b3f6592ae13be16dfe171b30817ee39d27bf0 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Tue, 18 Sep 2007 20:28:17 +0100 Subject: [PATCH] issue K records and start to use them Also halve the frequency of main::me node C records. This will eventually go to once a day. --- perl/DXProt.pm | 90 ++++++++++++++----------- perl/DXProtout.pm | 7 +- perl/Investigate.pm | 156 -------------------------------------------- perl/Version.pm | 2 +- 4 files changed, 59 insertions(+), 196 deletions(-) delete mode 100644 perl/Investigate.pm diff --git a/perl/DXProt.pm b/perl/DXProt.pm index 41f1debe..1cee4da0 100644 --- a/perl/DXProt.pm +++ b/perl/DXProt.pm @@ -40,7 +40,7 @@ use strict; 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 $pingint $obscount %pc19list $chatdupeage $chatimportfn - $investigation_int $pc19_version $myprot_version + $pc19_version $myprot_version %nodehops $baddx $badspotter $badnode $censorpc $allowzero $decode_dk0wcy $send_opernam @checklist $eph_pc15_restime $pc92_update_period $pc92_obs_timeout @@ -73,12 +73,11 @@ $pingint = 5*60; $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 = 5454; # the visible version no for outgoing PC19s generated from pc59 -$pc92_update_period = 24*60*60; # the period between outgoing PC92 C updates +$pc92_update_period = 2*60*60; # the period between outgoing PC92 C updates $pc92_short_update_period = 15*60; # shorten the update period after a connection or start up -$pc92_extnode_update_period = 2*60*60; # the update period for external nodes -$pc92_keepalive_period = 60*60; # frequency of PC92 K (keepalive) records +$pc92_extnode_update_period = 1*60*60; # the update period for external nodes +$pc92_keepalive_period = 1*60*60; # frequency of PC92 K (keepalive) records %pc92_find = (); # outstanding pc92 find operations $pc92_find_timeout = 30; # maximum time to wait for a reply @@ -249,6 +248,7 @@ sub init $main::me->{build} = "$main::subversion.$main::build"; $main::me->{do_pc9x} = 1; $main::me->update_pc92_next($pc92_short_update_period); + $main::me->update_pc92_keepalive; } # @@ -443,37 +443,10 @@ sub process my $dxchan; my $pc50s; - - foreach $dxchan (@dxchan) { - next unless $dxchan->is_node; - next if $dxchan->handle_xml; - next if $dxchan == $main::me; - - # send the pc50 - $dxchan->send($pc50s) if $pc50s; - - # send a ping out on this channel - if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) { - if ($dxchan->{nopings} <= 0) { - $dxchan->disconnect; - } else { - DXXml::Ping::add($main::me, $dxchan->call); - $dxchan->{nopings} -= 1; - $dxchan->{lastping} = $t; - $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}}; - } - } - - } - - Investigate::process(); - clean_pc92_find(); - # every ten seconds if ($t - $last10 >= 10) { # clean out ephemera - eph_clean(); import_chat(); @@ -487,6 +460,29 @@ sub process time_out_pc92_routes(); } + foreach $dxchan (@dxchan) { + next unless $dxchan->is_node; + next if $dxchan->handle_xml; + next if $dxchan == $main::me; + + # send the pc50 + $dxchan->send($pc50s) if !$dxchan->{do_pc9x} && $pc50s; + + # send a ping out on this channel + if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) { + if ($dxchan->{nopings} <= 0) { + $dxchan->disconnect; + } else { + DXXml::Ping::add($main::me, $dxchan->call); + $dxchan->{nopings} -= 1; + $dxchan->{lastping} = $t; + $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}}; + } + } + } + + clean_pc92_find(); + # send out config broadcasts foreach $dxchan (@dxchan) { next unless $dxchan->is_node; @@ -516,12 +512,12 @@ sub process if ($dxchan == $main::me || !$dxchan->{do_pc9x}) { dbg("ROUTE: pc92 keepalive candidate: $dxchan->{call}") if isdbg('obscount'); my $ref = Route::Node::get($dxchan->{call}); -# if ($dxchan == $main::me || ($ref && ($ref->measure_pc9x_t($main::systime-$main::systime_daystart)) >= $pc92_keepalive_period/2)) { -# $dxchan->broadcast_pc92_update($dxchan->{call}); -# } else { -# $dxchan->update_pc92_next($pc92_extnode_update_period); -# } -# } else { + if ($dxchan == $main::me || ($ref && ($ref->measure_pc9x_t($main::systime-$main::systime_daystart)) >= $pc92_keepalive_period/2)) { + $dxchan->broadcast_pc92_keepalive($dxchan->{call}); + } else { + $dxchan->update_pc92_keepalive; + } + } else { # $dxchan->update_pc92_next; # this won't actually do anything, it's just to be tidy $dxchan->update_pc92_keepalive; } @@ -968,6 +964,24 @@ sub broadcast_pc92_update $self->update_pc92_next; } +sub broadcast_pc92_keepalive +{ + my $self = shift; + my $call = shift; + + dbg("ROUTE: broadcast_pc92_keepalive $call") if isdbg('obscount'); + + my $nref = Route::Node::get($call); + unless ($nref) { + dbg("ERROR: broadcast_pc92_keepalive - Route::Node $call disappeared"); + return; + } + my $l = pc92k($nref); + $nref->lastid(last_pc9x_id()); + $main::me->broadcast_route_pc9x($main::mycall, undef, $l, 0); + $self->update_pc92_keepalive; +} + sub time_out_pc92_routes { my @nodes = grep {$_->call ne $main::mycall && ($_->do_pc9x || $_->via_pc92)} Route::Node::get_all(); diff --git a/perl/DXProtout.pm b/perl/DXProtout.pm index ec9abaa0..75903f02 100644 --- a/perl/DXProtout.pm +++ b/perl/DXProtout.pm @@ -419,7 +419,12 @@ sub pc92c # send a keep alive sub pc92k { - return _gen_pc92('K', 1, @_); + my $nref = shift; + my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^K"; + $s .= "^" . _encode_pc92_call($nref, 1); + $s .= "^" . scalar $nref->nodes; + $s .= "^" . scalar $nref->users; + return $s . '^H99^'; } # send a 'find' message diff --git a/perl/Investigate.pm b/perl/Investigate.pm deleted file mode 100644 index 52161a35..00000000 --- a/perl/Investigate.pm +++ /dev/null @@ -1,156 +0,0 @@ -# -# Investigate whether an external node is accessible -# -# If it is, make it believable otherwise mark as not -# to be believed. -# -# It is possible to store up state for a node to be -# investigated, so that if it is accessible, its details -# will be passed on to whomsoever might be interested. -# -# Copyright (c) 2004 Dirk Koopman, G1TLH -# -# -# - -use strict; - -package Investigate; - -use DXDebug; -use DXUtil; - - -use vars qw (%list %valid $pingint $maxpingwait); - -$pingint = 5; # interval between pings for each investigation - # this is to stop floods of pings -$maxpingwait = 120; # the maximum time we will wait for a reply to a ping -my $lastping = 0; # last ping done -%list = (); # the list of outstanding investigations -%valid = ( # valid fields - call => '0,Callsign', - start => '0,Started at,atime', - version => '0,Node Version', - build => '0,Node Build', - here => '0,Here?,yesno', - conf => '0,In Conf?,yesno', - pingsent => '0,Time ping sent,atime', - state => '0,State', - via => '0,Via Node', - pcxx => '0,Stored PCProt,parray', - ); - -my %via = (); - -sub new -{ - my $pkg = shift; - my $call = shift; - my $via = shift; - - my $self = $list{"$via,$call"}; - unless ($self) { - $self = bless { - call=>$call, - via=>$via, - start=>$main::systime, - state=>'start', - pcxx=>[], - }, ref($pkg) || $pkg; - $list{"$via,$call"} = $self; - } - dbg("Investigate: New $call via $via") if isdbg('investigate'); - return $self; -} - -sub get -{ - return $list{"$_[1],$_[0]"}; -} - -sub chgstate -{ - my $self = shift; - my $state = shift; - dbg("Investigate: $self->{call} via $self->{via} state $self->{state}->$state") if isdbg('investigate'); - $self->{state} = $state; -} - -sub handle_ping -{ - my $self = shift; - dbg("Investigate: ping received for $self->{call} via $self->{via}") if isdbg('investigate'); - if ($self->{state} eq 'waitping') { - $via{$self->{via}} = 0; # cue up next ping on this interface - delete $list{"$self->{via},$self->{call}"}; - my $user = DXUser->get_current($self->{via}); - if ($user) { - $user->set_believe($self->{call}); - $user->put; - } - my $dxchan = DXChannel::get($self->{via}); - if ($dxchan) { - dbg("Investigate: sending PC19 for $self->{call}") if isdbg('investigate'); - foreach my $pc (@{$self->{pcxx}}) { - no strict 'refs'; - my $handle = "handle_$pc->[0]"; - dbg("Investigate: sending PC$pc->[0] (" . join(',', @$pc) . ")") if isdbg('investigate'); - my $regex = $pc->[1]; - $regex =~ s/\^/\\^/g; - DXProt::eph_del_regex($regex); - $dxchan->$handle(@$pc); - } - } - } -} - -sub store_pcxx -{ - my $self = shift; - dbg("Investigate: Storing (". join(',', @_) . ")") if isdbg('investigate'); - push @{$self->{pcxx}}, [@_]; -} - -sub process -{ - while (my ($k, $v) = each %list) { - if ($v->{state} eq 'start') { - my $via = $via{$v->{via}} || 0; - if ($main::systime > $via+$pingint) { - DXXml::Ping::add($main::me, $v->{call}, $v->{via}); - $v->{start} = $lastping = $main::systime; - dbg("Investigate: ping sent to $v->{call} via $v->{via}") if isdbg('investigate'); - $v->chgstate('waitping'); - $via{$v->{via}} = $main::systime; - } - } elsif ($v->{state} eq 'waitping') { - if ($main::systime > $v->{start} + $maxpingwait) { - dbg("Investigate: ping timed out on $v->{call} via $v->{via}") if isdbg('investigate'); - delete $list{$k}; - my $user = DXUser->get_current($v->{via}); - if ($user) { - $user->lastping($v->{via}, $main::systime); - $user->put; - } - } - } - } -} - - -sub AUTOLOAD -{ - no strict; - my $name = $AUTOLOAD; - return if $name =~ /::DESTROY$/; - $name =~ s/^.*:://o; - - confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; - - # this clever line of code creates a subroutine which takes over from autoload - # from OO Perl - Conway - *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; - goto &$AUTOLOAD; -} -1; diff --git a/perl/Version.pm b/perl/Version.pm index b2ca6585..adfe2463 100644 --- a/perl/Version.pm +++ b/perl/Version.pm @@ -11,6 +11,6 @@ use vars qw($version $subversion $build); $version = '1.54'; $subversion = '0'; -$build = '145'; +$build = '146'; 1; -- 2.43.0