+sub cluster
+{
+ my $nodes = Route::Node::count();
+ my $tot = Route::User::count();
+ my $users = scalar DXCommandmode::get_all();
+ my $maxusers = Route::User::max();
+ my $uptime = main::uptime();
+
+ return " $nodes nodes, $users local / $tot total users Max users $maxusers Uptime $uptime";
+}
+
+#
+# routing things
+#
+
+sub get
+{
+ my $call = shift;
+ return Route::Node::get($call) || Route::User::get($call);
+}
+
+sub get_all
+{
+ return (Route::Node::get_all(), Route::User::get_all());
+}
+
+# find all the possible dxchannels which this object might be on
+sub alldxchan
+{
+ my $self = shift;
+
+ my $dxchan = DXChannel->get($self->{call});
+ if ($dxchan) {
+ dbg("alldxchan for $self->{call} = $dxchan->{call}") if isdbg('routelow');
+ return $dxchan if $dxchan;
+ }
+
+ my @nodes;
+ if ($self->isa('Route::User')) {
+ push @nodes, map{Route::Node::get($_)} @{$self->{nodes}};
+ } elsif ($self->isa('Route::Node')) {
+ push @nodes, $self;
+ }
+
+ # it isn't, build up a list of dxchannels and possible ping times
+ # for all the candidates.
+ my @dxchan;
+ foreach my $nref (@nodes) {
+ next unless $nref;
+ foreach my $p (@{$nref->{dxchan}}) {
+# dbg("Trying dxchan $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("alldxchan for $self->{call} = (" . join(',', @dxchan) . ")") if isdbg('routelow');
+ return @dxchan;
+}
+
+sub bestdxchan
+{
+ my $self = shift;
+
+ # ALWAYS return the locally connected channel if present;
+ my $dxchan = DXChannel->get($self->call);
+ return $dxchan if $dxchan;
+
+ my @dxchan = sort { ($a->pingave || 9999999) <=> ($b->pingave || 9999999) } $self->alldxchan;
+ return undef unless @dxchan;
+
+ return shift @dxchan;
+}
+