+sub _distance
+{
+ my $self = shift;
+ my $ah = shift;
+ my $call = $self->{call};
+
+ if (DXChannel->get($call)) {
+ my $n = scalar @_ || 0;
+ my $o = $ah->{$call} || 9999;
+ $ah->{$call} = $n if $n < $o;
+ dbg("_distance hit: $call = $n") if isdbg('routech');
+ return;
+ }
+
+ dbg("_distance miss $call: " . join(',', @_)) if isdbg('routech');
+
+ foreach my $c (@{$self->{links}}) {
+ next if $c eq $call || $c eq $main::mycall;
+ next if grep $c eq $_, @_;
+
+ my $n = get($c);
+ _distance($n, $ah, @_, $c);
+ }
+ return;
+}
+
+sub _ordered_routes
+{
+ my $self = shift;
+ my @routes;
+
+ if (exists $self->{dxchan}) {
+ dbg("stored routes for $self->{call}: " . join(',', @{$self->{dxchan}})) if isdbg('routech');
+ return @{$self->{dxchan}} if exists $self->{dxchan};
+ }
+
+ my %ah;
+ _distance($self, \%ah);
+
+ @routes = sort {$ah{$a} <=> $ah{$b}} keys %ah;
+ $self->{dxchan} = \@routes;
+ dbg("new routes for $self->{call}: " . join(',', @routes)) if isdbg('routech');
+ return @routes;
+}
+