X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute.pm;h=72bb5db44b8afb42b7c3319dabfd41ab21b9430d;hb=3fb4b66f6009196cf901f0f88fbf4837a8b8b6f9;hp=afce3a042d850200af3b9478d8e6b88cd8527403;hpb=6230850db2f82835e5ef75da4f418615ba4261da;p=spider.git diff --git a/perl/Route.pm b/perl/Route.pm index afce3a04..72bb5db4 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -285,34 +285,42 @@ sub get return Route::Node::get($call) || Route::User::get($call); } +sub findroutes +{ + 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); + 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; +} + # find all the possible dxchannels which this object might be on 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; } @@ -328,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]; }