use Verify;
use DXDupe;
use Thingy;
+use Thingy::Rt;
+use Thingy::Hello;
+use Thingy::Bye;
use RouteDB;
+use DXProt;
+use DXCommandmode;
use vars qw($VERSION $BRANCH);
main::mkver($VERSION = q$Revision$);
-use vars qw(@ISA $ntpflag $dupeage);
+use vars qw(@ISA $ntpflag $dupeage $cf_interval $hello_interval);
@ISA = qw(DXChannel);
$ntpflag = 0; # should be set in startup if NTP in use
$dupeage = 12*60*60; # duplicates stored half a day
+$cf_interval = 30*60; # interval between config broadcasts
+$hello_interval = 3*60*60; # interval between hello broadcasts for me and local users
my $seqno = 0;
my $dayno = 0;
# add this node to the table, the values get filled in later
my $pkg = shift;
my $call = shift;
- $main::routeroot->add($call, '5251', Route::here(1)) if $call ne $main::mycall;
$self->{'sort'} = 'W';
return $self;
}
# log it
my $host = $self->{conn}->{peerhost} || "unknown";
Log('Aranea', "$call connected from $host");
-
+
# remember type of connection
$self->{consort} = $line;
$self->{outbound} = $sort eq 'O';
# send info to all logged in thingies
$self->tell_login('loginn');
+ # broadcast our configuration to the world
+ unless ($self->{outbound}) {
+ my $thing = Thingy::Rt->new_cf;
+ $thing->broadcast;
+ $self->lastcf($main::systime);
+ }
+
# run a script send the output to the debug file
my $script = new Script(lc $call) || new Script('node_default');
$script->run($self) if $script;
}
#
-# periodic processing
+# periodic processing (every second)
#
+my $lastmin = 0;
+
sub process
{
$dayno = $d;
$daystart = $main::systime - ($main::systime % 86400);
}
+ if ($main::systime >= $lastmin + 60) {
+ if ($lastmin) {
+ per_minute();
+ $lastmin = $main::systime;
+ }
+ }
+}
+
+sub per_minute
+{
+ # send hello and cf packages periodically
+ foreach my $dxchan (DXChannel::get_all()) {
+ next if $dxchan == $main::me;
+ next if $dxchan->is_aranea;
+ if ($main::systime > $dxchan->lasthello + $hello_interval) {
+ my $thing = Thingy::Hello->new(user => $dxchan->call, h => $dxchan->here);
+ $thing->broadcast($dxchan);
+ $dxchan->lasthello($main::systime);
+ }
+ if ($dxchan->is_node) {
+ if ($main::systime > $dxchan->lasthello + $hello_interval) {
+ my $call = $dxchan->call;
+ my $thing = Thingy::Rt->new(user => $call);
+ if (my $nref = Route::Node::get($call)) {
+ $thing->copy_pc16_data($nref);
+ $thing->broadcast($dxchan);
+ $dxchan->lastcf($main::systime);
+ } else {
+ dbg("Aranea::per_minute: Route::Node for $call disappeared");
+ $dxchan->disconnect;
+ }
+ }
+ }
+ }
}
sub disconnect
return if $self->{disconnecting}++;
my $thing = Thingy::Bye->new(origin=>$main::mycall, user=>$call);
- $thing->process($self);
+ $thing->broadcast($self);
# get rid of any PC16/17/19
DXProt::eph_del_regex("^PC1[679]*$call");
$mref->stop_msg($call) if $mref;
# broadcast to all other nodes that all the nodes connected to via me are gone
-# $self->route_pc21($main::mycall, undef, @rout) if @rout;
+ DXProt::route_pc21($self, $main::mycall, undef, @rout) if @rout;
# remove outstanding pings
# delete $pings{$call};
{
my $s = shift;
$s =~ s/([\%=|,\'\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
- $s = "'$s'" if $s =~ / /;
+# $s = "'$s'" if $s =~ / /;
return $s;
}
my $s = shift;
$s =~ s/^'(.*)'$/$1/;
$s =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
- return $s;
+ return length $s ? $s : '';
}
sub genmsg
{
my $thing = shift;
- my $name = shift;
+ my $list = ref $_[0] ? shift : \@_;
+ my ($name) = uc ref $thing;
+ $name =~ /::(\w+)$/;
+ $name = $1;
my $head = genheader($thing->{origin},
($thing->{group} || $thing->{touser} || $thing->{tonode}),
($thing->{user} || $thing->{fromuser} || $thing->{fromnode})
);
- my $data = "$name,";
- while (@_) {
- my $k = lc shift;
- my $v = tencode(shift);
- $data .= "$k=$v,";
+
+ my $data = uc $name . ',';
+ while (@$list) {
+ my $k = lc shift @$list;
+ my $v = $thing->{$k};
+ $data .= "$k=" . tencode($v) . ',' if defined $v;
}
chop $data;
return "$head|$data";
$err .= "missing cmd or data," unless $cmd && $data;
$err .= "invalid command ($cmd)," unless $cmd =~ /^[A-Z][A-Z0-9]*$/;
my ($gp, $tus) = split /:/, $group, 2 if $group;
-
+
+ $err .= "from me," if $origin eq $main::mycall;
$err .= "invalid group ($gp)," if $gp && $gp !~ /^[A-Z0-9]{2,}$/;
$err .= "invalid tocall ($tus)," if $tus && !is_callsign($tus);
$err .= "invalid fromcall ($user)," if $user && !is_callsign($user);