From dcbafa96df9fbad90df86076b6ee9fa6a673a61c Mon Sep 17 00:00:00 2001 From: minima Date: Sat, 19 Feb 2005 01:52:03 +0000 Subject: [PATCH] added some more pc16/17 routing code --- perl/Aranea.pm | 3 +- perl/DXProt.pm | 42 +++++----------- perl/Route.pm | 12 +++-- perl/Thingy.pm | 7 ++- perl/Thingy/Rt.pm | 119 +++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 139 insertions(+), 44 deletions(-) diff --git a/perl/Aranea.pm b/perl/Aranea.pm index c68b2116..fc77cc13 100644 --- a/perl/Aranea.pm +++ b/perl/Aranea.pm @@ -25,6 +25,7 @@ use Script; use Verify; use DXDupe; use Thingy; +use RouteDB; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); @@ -325,7 +326,7 @@ sub input $thing->{touser} = $tus if $tus; $thing->{user} = $user if $user; $thing->{hopsaway} = $hop; - + for (split(/,/, $rdata)) { if (/=/) { my ($k,$v) = split /=/, $_, 2; diff --git a/perl/DXProt.pm b/perl/DXProt.pm index 508303bd..89f8f9d5 100644 --- a/perl/DXProt.pm +++ b/perl/DXProt.pm @@ -739,7 +739,7 @@ sub handle_16 my $i; - my @rout; + my $rout; for ($i = 2; $i < $#_; $i++) { my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o; next unless $call && $conf && defined $here && is_callsign($call); @@ -747,40 +747,20 @@ sub handle_16 eph_del_regex("^PC17\\^$call\\^$ncall"); - $conf = 1; - - my $r = Route::User::get($call); - my $flags = Route::here($here)|Route::conf($conf); - - if ($r) { - my $au = $r->addparent($parent); - if ($r->flags != $flags) { - $r->flags($flags); - $au = $r; - } - push @rout, $r if $au; - } else { - push @rout, $parent->add_user($call, $flags); - } - - - # add this station to the user database, if required - $call =~ s/-\d+$//o; # remove ssid for users - my $user = DXUser->get_current($call); - $user = DXUser->new($call) if !$user; - $user->homenode($parent->call) if !$user->homenode; - $user->node($parent->call); - $user->lastin($main::systime) unless DXChannel->get($call); - $user->put; + my $flags = $here ? 1 : 0; + $rout .= ":U$flags$call"; } + - if (@rout) { - my $thing = Thingy::Rt->new(origin=>$main::mycall); - $thing->from_DXProt(t=>'ea', n=>$ncall, u=>join(':',map {"$_->{flags}$_->{call}"} @rout), DXProt=>$line); + if ($rout) { + my $thing = Thingy::Rt->new(origin=>$main::mycall, user=>$self->{call}); + $thing->from_DXProt(t=>'eau', d=>"N1$ncall$rout", DXProt=>$line); $thing->queue($self); } else { dbg("PCPROT: No usable users") if isdbg('chanerr'); } + } else { + dbg("PCPROT: no PC19 seen for $ncall" ) if isdbg('chanerr'); } } @@ -840,8 +820,8 @@ sub handle_17 } $uref = Route->new($ucall) unless $uref; # throw away - my $thing = Thingy::Rt->new(origin=>$main::mycall); - $thing->from_DXProt(t=>'ed', n=>$ncall, u=>"1$ucall", DXProt=>$line); + my $thing = Thingy::Rt->new(origin=>$main::mycall, user=>$self->{call}); + $thing->from_DXProt(t=>'edu', d=>"N1$ncall:U1$ucall", DXProt=>$line); $thing->queue($self); } diff --git a/perl/Route.pm b/perl/Route.pm index 0f52e39b..b4e11b4d 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -141,9 +141,11 @@ sub is_empty # These can be called in various ways:- # # Route::here or $ref->here returns 1 or 0 depending on value of the here flag -# Route::here(1) returns 2 (the bit value of the here flag) +# Route::here(1) returns 1 (the bit value of the here flag) # $ref->here(1) or $ref->here(0) sets the here flag # +# these are now redundant really as we are not interested in conferences +# and here is back to being '1'. sub here { @@ -151,7 +153,7 @@ sub here my $r = shift; return $self ? 2 : 0 unless ref $self; return ($self->{flags} & 2) ? 1 : 0 unless defined $r; - $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0)); + $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0)); return $r ? 1 : 0; } @@ -159,10 +161,10 @@ sub conf { my $self = shift; my $r = shift; - return $self ? 1 : 0 unless ref $self; + return $self ? 2 : 0 unless ref $self; return ($self->{flags} & 1) ? 1 : 0 unless defined $r; - $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0)); - return $r ? 1 : 0; + $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0)); + return $r ? 2 : 0; } sub parents diff --git a/perl/Thingy.pm b/perl/Thingy.pm index 0921abd8..c91edc0c 100644 --- a/perl/Thingy.pm +++ b/perl/Thingy.pm @@ -63,7 +63,7 @@ sub send # do output filtering if ($thing->can('out_filter')) { - return unless $thing->out_filter; + return unless $thing->out_filter($dxchan); } # generate the line which may (or not) be cached @@ -112,6 +112,11 @@ sub process if ($thing->can('in_filter')) { next unless $thing->in_filter($dxchan); } + + # remember any useful routes + RouteDB::update($thing->{origin}, $dxchan->{call}, $thing->{hopsaway}); + RouteDB::update($thing->{user}, $dxchan->{call}, $thing->{hopsaway}) if exists $thing->{user}; + $thing->handle($dxchan); } } diff --git a/perl/Thingy/Rt.pm b/perl/Thingy/Rt.pm index 75528d0a..eb20fcab 100644 --- a/perl/Thingy/Rt.pm +++ b/perl/Thingy/Rt.pm @@ -30,7 +30,7 @@ sub gen_Aranea my $thing = shift; unless ($thing->{Aranea}) { my @items; - $thing->{Aranea} = Aranea::genmsg($thing, 'Rt', @items); + $thing->{Aranea} = Aranea::genmsg($thing, 'RT', @items); } return $thing->{Aranea}; } @@ -74,7 +74,89 @@ sub handle my $thing = shift; my $dxchan = shift; - $thing->broadcast($dxchan); + if ($thing->{t}) { + my $sub = "handle_$thing->{t}"; + if ($thing->can($sub)) { + no strict 'refs'; + $thing = $thing->$sub($dxchan); + } + + $thing->broadcast($dxchan) if $thing; + } +} + +sub handle_eau +{ + my $thing = shift; + my $dxchan = shift; + + if (my $d = $thing->{d}) { + for (split /:/, $d) { + my ($type, $here, $call) = unpack "A1 A1 A*", $_; + my $nref; + if ($type eq 'U') { + unless ($nref) { + dbg("Thingy::Rt::ea need a node before $call"); + return; + } + add_user($nref, $call, $here); + my $h = $dxchan->{call} eq $nref->{call} ? 3 : ($thing->{hops} || 99); + RouteDB::update($call, $dxchan->{call}, $h); + } elsif ($type eq 'N') { + $nref = Route::Node::get($call); + unless ($nref) { + dbg("Thingy::Rt::ea need a definition for $call"); + return; + } + my $h = $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99); + RouteDB::update($nref->{call}, $dxchan->{call}, $h); + } else { + dbg("Thingy::Rt::ea invalid type $type"); + return; + } + unless ($nref) { + dbg("Thingy::Rt::ea no node"); + return; + } + } + } + return $thing; +} + +sub handle_edu +{ + my $thing = shift; + my $dxchan = shift; + + if (my $d = $thing->{d}) { + for (split /:/, $d) { + my ($type, $here, $call) = unpack "A1 A1 A*", $_; + my $nref; + if ($type eq 'U') { + unless ($nref) { + dbg("Thingy::Rt::ed need a node before $call"); + return; + } + $nref->del_user($call); + RouteDB::delete($call, $dxchan->{call}); + } elsif ($type eq 'N') { + $nref = Route::Node::get($call); + unless ($nref) { + dbg("Thingy::Rt::ed need a definition for $call"); + return; + } + RouteDB::update($nref->{call}, $dxchan->{call}, $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99)); + } else { + dbg("Thingy::Rt::ed invalid type $type"); + return; + } + unless ($nref) { + dbg("Thingy::Rt::ed no node"); + return; + } + } + } + return $thing; } sub in_filter @@ -84,8 +166,8 @@ sub in_filter # global route filtering on INPUT if ($dxchan->{inroutefilter}) { - my $ref = Route::Node::get($thing->{origin}); - my ($filter, $hops) = $dxchan->{inroutefilter}->it($ref); + my $r = Route::Node::get($thing->{origin}); + my ($filter, $hops) = $dxchan->{inroutefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state}); unless ($filter) { dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr'); return; @@ -101,8 +183,8 @@ sub out_filter # global route filtering on OUTPUT if ($dxchan->{routefilter}) { - my $ref = Route::Node::get($thing->{origin}); - my ($filter, $hops) = $dxchan->{routefilter}->it($ref); + my $r = Route::Node::get($thing->{origin}); + my ($filter, $hops) = $dxchan->{routefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state}); unless ($filter) { dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr'); return; @@ -113,4 +195,29 @@ sub out_filter } return 1; } + +sub add_user +{ + my $node = shift; + my $user = shift; + my $flag = shift; + + $node->add_user($user, $flag); + my $ur = upd_user_rec($user, $node); + $ur->put; +} + +sub upd_user_rec +{ + my $call = shift; + my $parentcall = shift; + + # add this station to the user database, if required + $call =~ s/-\d+$//o; # remove ssid for users + my $user = DXUser->get_current($call); + $user = DXUser->new($call) if !$user; + $user->homenode($parentcall) if !$user->homenode; + $user->node($parentcall); + $user->lastin($main::systime) unless DXChannel->get($call); +} 1; -- 2.43.0