X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute.pm;h=0150d5bfd3b92b7c7d3cf8c391ce30ca1f089756;hb=3517495c96b980bf3b9364ae2b218505b2b40582;hp=47b87dac8a6fcfd8cf82af6f687a37f6036f566f;hpb=d7a259b56406b17ce5179aac85a3b1f07664147d;p=spider.git diff --git a/perl/Route.pm b/perl/Route.pm index 47b87dac..0150d5bf 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -15,23 +15,51 @@ package Route; use DXDebug; +use DXChannel; +use Prefix; use strict; -use vars qw(%list %valid); +use vars qw(%list %valid $filterdef); %valid = ( call => "0,Callsign", flags => "0,Flags,phex", + dxcc => '0,Country Code', + itu => '0,ITU Zone', + cq => '0,CQ Zone', ); +$filterdef = bless ([ + # tag, sort, field, priv, special parser + ['channel', 'c', 0], + ['channel_dxcc', 'n', 1], + ['channel_itu', 'n', 2], + ['channel_zone', 'n', 3], + ['call', 'c', 4], + ['call_dxcc', 'n', 5], + ['call_itu', 'n', 6], + ['call_zone', 'n', 7], + ], 'Filter::Cmd'); + + sub new { my ($pkg, $call) = @_; + $pkg = ref $pkg if ref $pkg; - dbg('routelow', "create " . (ref($pkg) || $pkg) ." with $call"); + my $self = bless {call => $call}, $pkg; + dbg('routelow', "create $pkg with $call"); + + # add in all the dxcc, itu, zone info + my @dxcc = Prefix::extract($call); + if (@dxcc > 0) { + $self->{dxcc} = $dxcc[1]->dxcc; + $self->{itu} = $dxcc[1]->itu; + $self->{cq} = $dxcc[1]->cq; + } - return bless {call => $call}, (ref $pkg || $pkg); + return $self; } # @@ -89,9 +117,9 @@ sub here my $self = shift; my $r = shift; return $self ? 2 : 0 unless ref $self; - return $self->{flags} & 2 unless $r; - $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0)); - return $r; + return ($self->{flags} & 2) ? 1 : 0 unless $r; + $self->{flags} = (($self->{flags} & ~2) | ($r ? 1 : 0)); + return $r ? 1 : 0; } sub conf @@ -99,9 +127,15 @@ sub conf my $self = shift; my $r = shift; return $self ? 1 : 0 unless ref $self; - return $self->{flags} & 1 unless $r; + return ($self->{flags} & 1) ? 1 : 0 unless $r; $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0)); - return $r; + return $r ? 1 : 0; +} + +sub parents +{ + my $self = shift; + return @{$self->{parent}}; } # @@ -123,53 +157,121 @@ sub config my @out; my $line; my $call = $self->user_call; + my $printit = 1; - $line = ' ' x ($level*2) . "$call"; - $call = ' ' x length $call; - unless ($nodes_only) { - if (@{$self->{users}}) { - $line .= '->'; - foreach my $ucall (sort @{$self->{users}}) { - my $uref = Route::User::get($ucall); - my $c; - if ($uref) { - $c = $uref->user_call; - } else { - $c = "$ucall?"; - } - if ((length $line) + (length $c) + 1 < 79) { - $line .= $c . ' '; - } else { - $line =~ s/\s+$//; - push @out, $line; - $line = ' ' x ($level*2) . "$call->"; + # allow ranges + if (@_) { + $printit = grep $call =~ m|$_|, @_; + } + + if ($printit) { + $line = ' ' x ($level*2) . "$call"; + $call = ' ' x length $call; + unless ($nodes_only) { + if (@{$self->{users}}) { + $line .= '->'; + foreach my $ucall (sort @{$self->{users}}) { + my $uref = Route::User::get($ucall); + my $c; + if ($uref) { + $c = $uref->user_call; + } else { + $c = "$ucall?"; + } + if ((length $line) + (length $c) + 1 < 79) { + $line .= $c . ' '; + } else { + $line =~ s/\s+$//; + push @out, $line; + $line = ' ' x ($level*2) . "$call->$c "; + } } } } + $line =~ s/->$//g; + $line =~ s/\s+$//; + push @out, $line if length $line; } - $line =~ s/->$//g; - $line =~ s/\s+$//; - push @out, $line if length $line; foreach my $ncall (sort @{$self->{nodes}}) { my $nref = Route::Node::get($ncall); - next if @_ && !grep $ncall =~ m|$_|, @_; - + if ($nref) { my $c = $nref->user_call; push @out, $nref->config($nodes_only, $level+1, @_); } else { - push @out, ' ' x (($level+1)*2) . "$ncall?"; + push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_); } } return @out; } +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); +} + +# find all the possible dxchannels which this object might be on +sub alldxchan +{ + my $self = shift; + my @dxchan; + 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. + foreach my $p (@{$self->{parent}}) { + my $dxchan = DXChannel->get($p); + if ($dxchan) { + push @dxchan, $dxchan if grep $dxchan ne $_, @dxchan; + } else { + next if $p eq $main::mycall; # the root + my $ref = $self->get($p); + push @dxchan, $ref->alldxchan if $ref; + } + } + return @dxchan; +} + +sub dxchan +{ + my $self = shift; + my $dxchan = DXChannel->get($self->{call}); + return $dxchan = $dxchan; + + my @dxchan = $self->alldxchan; + 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; +} # # track destruction