]> dxcluster.org Git - spider.git/commitdiff
added some more pc16/17 routing code
authorminima <minima>
Sat, 19 Feb 2005 01:52:03 +0000 (01:52 +0000)
committerminima <minima>
Sat, 19 Feb 2005 01:52:03 +0000 (01:52 +0000)
perl/Aranea.pm
perl/DXProt.pm
perl/Route.pm
perl/Thingy.pm
perl/Thingy/Rt.pm

index c68b211686b72b83bbd7ad18e7f4c82385de003d..fc77cc13122fe6f1a7f330c11992e5aedb1ac59f 100644 (file)
@@ -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;
index 508303bdcfb604d6dc1cdd14a50cc74fefafbd97..89f8f9d524e70a828b88c29e05c79c3137501ec3 100644 (file)
@@ -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);
 }
                
index 0f52e39b4023285ad994ad533feb18d66ad11f19..b4e11b4d1da5a295ef3566e798409f9e209b3339 100644 (file)
@@ -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
index 0921abd818414d2c2dac083fd5aab6033224cedc..c91edc0ce3d0d1d1429d7365338988884f796f94 100644 (file)
@@ -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);
                }
        }
index 75528d0aa885473fc57271b2f771e17dde733252..eb20fcabed17aba45fa23eb176fe8d46a97d2e87 100644 (file)
@@ -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;