X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute.pm;h=1106892a167c8641147ac76fa02d9118a13057eb;hb=916f0deef0e085647471d5959a55c2ddb815a044;hp=afce3a042d850200af3b9478d8e6b88cd8527403;hpb=1cbb4d2083af4212ff4ed84dc79b9e5a22387ab2;p=spider.git diff --git a/perl/Route.pm b/perl/Route.pm index afce3a04..1106892a 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -285,6 +285,34 @@ 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, $dxchan]; + return @out; + } + + # 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; + } + + 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 {