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
28 use vars qw(%list %valid $default);
32 $default = 99; # the number of hops to use if we don't know
35 item => "0,Interfaces,parray",
36 t => '0,Last Seen,atime',
38 count => '0,Times Seen',
45 return bless {call => $call, list => {}}, (ref $pkg || $pkg);
51 my @out = _sorted(shift);
52 return @out ? $out[0]->{call} : undef;
55 # get all of them in sorted order
58 my @out = _sorted(shift);
59 return @out ? map { $_->{call} } @out : ();
62 # get them all, sorted into reverse occurance order (latest first)
63 # with the smallest hops
67 my $ref = $list{$call};
68 return () unless $ref;
70 if ($a->{hops} == $b->{hops}) {
73 $a->{hops} <=> $b->{hops};
75 } values %{$ref->{item}};
79 # add or update this call on this interface
81 # RouteDB::update($call, $interface, $hops, time);
86 my $interface = shift;
87 my $hops = shift || $default;
88 my $ref = $list{$call} || RouteDB->new($call);
89 my $iref = $ref->{item}->{$interface} ||= RouteDB::Item->new($interface, $hops);
91 $iref->{hops} = $hops if $hops < $iref->{hops};
92 $iref->{t} = shift || $main::systime;
93 $ref->{item}->{$interface} ||= $iref;
94 $list{$call} ||= $ref;
100 my $interface = shift;
101 my $ref = $list{$call};
102 delete $ref->{item}->{$interface} if $ref;
107 my $interface = shift;
108 foreach my $ref (values %list) {
109 delete $ref->{item}->{$interface};
114 # generic AUTOLOAD for accessors
119 my $name = $AUTOLOAD;
120 return if $name =~ /::DESTROY$/;
123 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
125 # this clever line of code creates a subroutine which takes over from autoload
126 # from OO Perl - Conway
127 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
132 package RouteDB::Item;
141 my $hops = shift || $RouteDB::default;
142 return bless {call => $call, hops => $hops}, (ref $pkg || $pkg);