make Route::findroutes the basis of all routing
[spider.git] / perl / Route.pm
index 1106892a167c8641147ac76fa02d9118a13057eb..72bb5db44b8afb42b7c3319dabfd41ab21b9430d 100644 (file)
@@ -298,16 +298,19 @@ sub findroutes
        return () if $seen->{$call};
        if (my $dxchan = DXChannel::get($call)) {
                $seen->{$call}++;
-               push @out, [$level, $dxchan];
+               push @out, $level ? [$level, $dxchan] : $dxchan;
                return @out;
        }
+       $seen->{$call}++;
 
        # deal with more nodes
-       my $nref = Route::Node::get($call);
-       foreach my $ncall (@{$nref->{nodes}}) {
-               dbg("recursing from $call -> $ncall") if isdbg('routec');
-               my @rout = findroute($ncall, $level+1, $seen);
-               push @out, @rout;
+       my $nref = Route::get($call);
+       foreach my $ncall (@{$nref->{parent}}) {
+               unless ($seen->{$ncall}) {
+                       dbg("recursing from $call -> $ncall") if isdbg('routec');
+                       my @rout = findroutes($ncall, $level+1, $seen);
+                       push @out, @rout;
+               }
        }
 
        return $level == 0 ? map {$_->[1]} sort {$a->[0] <=> $b->[0]} @out : @out;
@@ -317,30 +320,7 @@ sub findroutes
 sub alldxchan
 {
        my $self = shift;
-       my @dxchan;
-#      dbg("Trying node $self->{call}") if isdbg('routech');
-
-       my $dxchan = DXChannel::get($self->{call});
-       push @dxchan, $dxchan if $dxchan;
-
-       # it isn't, build up a list of dxchannels and possible ping times
-       # for all the candidates.
-       unless (@dxchan) {
-               foreach my $p (@{$self->{parent}}) {
-#                      dbg("Trying parent $p") if isdbg('routech');
-                       next if $p eq $main::mycall; # the root
-                       my $dxchan = DXChannel::get($p);
-                       if ($dxchan) {
-                               push @dxchan, $dxchan unless grep $dxchan == $_, @dxchan;
-                       } else {
-                               next if grep $p eq $_, @_;
-                               my $ref = Route::Node::get($p);
-#                              dbg("Next node $p " . ($ref ? 'Found' : 'NOT Found') if isdbg('routech') );
-                               push @dxchan, $ref->alldxchan($self->{call}, @_) if $ref;
-                       }
-               }
-       }
-#      dbg('routech', "Got dxchan: " . join(',', (map{ $_->call } @dxchan)) );
+       my @dxchan = findroutes($self->{call});
        return @dxchan;
 }
 
@@ -356,16 +336,18 @@ sub dxchan
        return undef unless @dxchan;
 
        # determine the minimum ping channel
-       my $minping = 99999999;
-       foreach my $dxc (@dxchan) {
-               my $p = $dxc->pingave;
-               if (defined $p  && $p < $minping) {
-                       $minping = $p;
-                       $dxchan = $dxc;
-               }
-       }
-       $dxchan = shift @dxchan unless $dxchan;
-       return $dxchan;
+#      my $minping = 99999999;
+#      foreach my $dxc (@dxchan) {
+#              my $p = $dxc->pingave;
+#              if (defined $p  && $p < $minping) {
+#                      $minping = $p;
+#                      $dxchan = $dxc;
+#              }
+#      }
+#      $dxchan = shift @dxchan unless $dxchan;
+
+       # dxchannels are now returned in order of "closeness"
+       return $dxchan[0];
 }