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($VERSION $BRANCH);
29 main::mkver($VERSION = q$Revision$);
31 use vars qw(%list %valid $default);
34 $default = 99; # the number of hops to use if we don't know
37 item => "0,Interfaces,parray",
38 t => '0,Last Seen,atime',
40 count => '0,Times Seen',
47 return bless {call => $call, list => {}}, (ref $pkg || $pkg);
53 my @out = _sorted(shift);
54 return @out ? $out[0]->{call} : undef;
57 # get all of them in sorted order
60 my @out = _sorted(shift);
61 return @out ? map { $_->{call} } @out : ();
64 # get them all, sorted into reverse occurance order (latest first)
65 # with the smallest hops
69 my $ref = $list{$call};
70 return () unless $ref;
72 if ($a->{hops} == $b->{hops}) {
75 $a->{hops} <=> $b->{hops};
77 } values %{$ref->{item}};
81 # add or update this call on this interface
83 # RouteDB::update($call, $interface, $hops, time);
88 my $interface = shift;
89 my $hops = shift || $default;
90 my $ref = $list{$call} || RouteDB->new($call);
91 my $iref = $ref->{item}->{$interface} ||= RouteDB::Item->new($interface);
93 $iref->{hops} = $hops if $hops < $iref->{hops};
94 $iref->{t} = shift || $main::systime;
95 $ref->{item}->{$interface} ||= $iref;
96 $list{$call} ||= $ref;
102 my $interface = shift;
103 my $ref = $list{$call};
104 delete $ref->{item}->{$interface} if $ref;
109 my $interface = shift;
110 foreach my $ref (values %list) {
111 delete $ref->{item}->{$interface};
116 # generic AUTOLOAD for accessors
121 my $name = $AUTOLOAD;
122 return if $name =~ /::DESTROY$/;
125 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
127 # this clever line of code creates a subroutine which takes over from autoload
128 # from OO Perl - Conway
129 *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
134 package RouteDB::Item;
143 return bless {call => $call, hops => $RouteDB::default}, (ref $pkg || $pkg);