1 # This module is used to keep a list of where things come from
3 # all interfaces add/update entries in here to allow casual
6 # It is up to the protocol handlers in here to make sure that
7 # this information makes sense.
9 # This is (for now) just an adjunct to the normal routing
10 # and is experimental. It will override filtering for
11 # things that are explicitly routed (pings, talks and
14 # Copyright (c) 2004 Dirk Koopman G1TLH
27 use vars qw(%list %valid $default);
30 $default = 99; # the number of hops to use if we don't know
33 item => "0,Interfaces,parray",
34 t => '0,Last Seen,atime',
36 count => '0,Times Seen',
43 return bless {call => $call, list => {}}, (ref $pkg || $pkg);
49 my @out = _sorted(shift);
50 return @out ? $out[0]->{call} : undef;
53 # get all of them in sorted order
56 my @out = _sorted(shift);
57 return @out ? map { $_->{call} } @out : ();
60 # get them all, sorted into reverse occurance order (latest first)
61 # with the smallest hops
65 my $ref = $list{$call};
66 return () unless $ref;
68 if ($a->{hops} == $b->{hops}) {
71 $a->{hops} <=> $b->{hops};
73 } values %{$ref->{item}};
77 # add or update this call on this interface
79 # RouteDB::update($call, $interface, $hops, time);
84 my $interface = shift;
85 my $hops = shift || $default;
86 my $ref = $list{$call} || RouteDB->new($call);
87 my $iref = $ref->{item}->{$interface} ||= RouteDB::Item->new($interface);
89 $iref->{hops} = $hops if $hops < $iref->{hops};
90 $iref->{t} = shift || $main::systime;
91 $ref->{item}->{$interface} ||= $iref;
92 $list{$call} ||= $ref;
98 my $interface = shift;
99 my $ref = $list{$call};
100 delete $ref->{item}->{$interface} if $ref;
105 my $interface = shift;
106 foreach my $ref (values %list) {
107 delete $ref->{item}->{$interface};
112 # generic AUTOLOAD for accessors
117 my $name = $AUTOLOAD;
118 return if $name =~ /::DESTROY$/;
121 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
123 # this clever line of code creates a subroutine which takes over from autoload
124 # from OO Perl - Conway
125 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
130 package RouteDB::Item;
139 return bless {call => $call, hops => $RouteDB::default}, (ref $pkg || $pkg);