- 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;
+ my $call = shift;
+ my $level = shift || 0;
+ my $seen = shift || {};
+ my @out;
+
+ dbg("findroutes: $call level: $level calls: " . join(',', @_)) if isdbg('routec');
+
+ # recursion detector
+ return () if $seen->{$call};
+ if (my $dxchan = DXChannel::get($call)) {
+ $seen->{$call}++;
+ push @out, $level ? [$level, $dxchan] : $dxchan;
+ return @out;
+ }
+ $seen->{$call}++;
+
+ # deal with more nodes
+ my $nref = Route::get($call);
+ return () unless $nref;
+ 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;
+ }
+ }
+
+ if ($level == 0) {
+ my @nout = map {$_->[1]} sort {$a->[0] <=> $b->[0]} @out;
+ my $last;
+ if ($nref->isa('Route::Node')) {
+ my $ncall = $nref->PC92C_dxchan;
+ $last = DXChannel::get($ncall) if $ncall;
+ } else {
+ my $pcall = $nref->{parent}->[0];
+ my ($ref, $ncall);
+ $ref = Route::Node::get($pcall) if $pcall;
+ $ncall = $ref->PC92C_dxchan if $ref;
+ $last = DXChannel::get($ncall) if $ncall;
+ }
+
+ if (isdbg('findroutes')) {
+ if (@out) {
+ foreach (sort {$a->[0] <=> $b->[0]} @out) {
+ dbg("ROUTE: findroute $call -> $_->[0] " . $_->[1]->call);
+ }