2 # Route Thingy handling
4 # Note that this is a generator of pc(16|17|19|21)n and pc(16|17)u
5 # and a consumer of the fpc versions of the above
9 # Copyright (c) 2005 Dirk Koopman G1TLH
16 use vars qw($VERSION $BRANCH);
18 main::mkver($VERSION = q$Revision$);
24 use Thingy::RouteFilter;
27 use vars qw(@ISA $update_interval);
28 @ISA = qw(Thingy Thingy::RouteFilter);
30 $update_interval = 30 * 60; # the interval between 'cf' updates for an interface
37 unless ($thing->{Aranea}) {
39 if ($ref = $thing->{anodes}) {
40 $thing->{a} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
42 if ($ref = $thing->{anodes}) {
43 $thing->{n} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
45 if ($ref = $thing->{ausers}) {
46 $thing->{u} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
48 $thing->{Aranea} = Aranea::genmsg($thing, [qw(s a n u)]);
51 return $thing->{Aranea};
67 my $sub = "handle_$thing->{s}";
68 if ($thing->can($sub)) {
70 $thing = $thing->$sub($dxchan);
73 $thing->broadcast($dxchan) if $thing;
77 # this handles the standard local configuration, it
78 # will reset all the config, make / break links and
79 # will generate pc sentences as required for nodes and users
84 my $origin = $thing->{user} || $thing->{origin};
85 my $chan_call = $dxchan->{call};
87 my $parent = Route::Node::get($origin);
89 dbg("Thingy::Rt::cf: received from $thing->{origin}/$origin on $chan_call unknown") if isdbg('chanerr');
97 %in = (map {my ($here, $call) = unpack("A1 A*", $_); ($call, $here)} split /:/, $thing->{n});
98 my ($tdel, $tadd) = $parent->diff_nodes(keys %in);
103 %in = (map {my ($here, $call) = unpack("A1 A*", $_); ($call, $here)} split /:/, $thing->{a});
104 my ($tdel, $tadd) = $parent->diff_nodes(keys %in);
110 foreach my $call (@$del) {
111 RouteDB::delete($call, $chan_call);
112 my $ref = Route::Node::get($call);
113 push @pc21, $ref->del($parent) if $ref;
115 $thing->{pc21n} = \@pc21 if @pc21;
119 foreach my $call (@$add) {
120 RouteDB::update($call, $chan_call);
121 my $ref = Route::Node::get($call);
122 push @pc19, $parent->add($call, 0, $in{$call}) unless $ref;
124 $thing->{pc19n} = \@pc19 if @pc19;
129 %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{u});
130 ($del, $add) = $parent->diff_users(keys %in);
135 foreach $call (@$del) {
136 RouteDB::delete($call, $chan_call);
137 my $ref = Route::User::get($call);
139 $parent->del_user($ref);
142 dbg("Thingy::Rt::lcf: del user $call not known, ignored") if isdbg('chanerr');
147 $thing->{pc17n} = $parent;
148 $thing->{pc17u} = \@pc17;
152 foreach $call (@$add) {
153 RouteDB::update($call, $chan_call);
154 push @pc16, _add_user($parent, $call, $in{$call});
157 $thing->{pc16n} = $parent;
158 $thing->{pc16u} = \@pc16;
172 my @out = $node->add_user($user, $flag);
173 my $ur = _upd_user_rec($user, $node);
181 my $parentcall = shift;
183 # add this station to the user database, if required
184 my $user = DXUser->get_current($call);
185 $user = DXUser->new($call) if !$user;
186 $user->homenode($parentcall) if !$user->homenode;
187 $user->node($parentcall);
188 $user->lastin($main::systime) unless DXChannel::get($call);
193 # Generate a configuration for onward broadcast
195 # Basically, this creates a thingy with list of nodes and users that
196 # are on this node. This the normal method of spreading this
197 # info whenever a node connects and also periodically.
203 my $thing = $pkg->SUPER::new(@_);
205 $thing->{'s'} = 'cf';
211 foreach my $dxchan (DXChannel::get_all()) {
212 next if $dxchan == $main::me;
213 if ($dxchan->is_node) {
214 my $ref = Route::Node::get($dxchan->{call});
215 push @pnodes, $ref if $ref;
216 } elsif ($dxchan->is_aranea) {
217 my $ref = Route::Node::get($dxchan->{call});
218 push @anodes, $ref if $ref;
220 my $ref = Route::User::get($dxchan->{call});
221 push @users, $ref if $ref;
224 $thing->{anodes} = \@anodes if @anodes;
225 $thing->{pnodes} = \@pnodes if @pnodes;
226 $thing->{ausers} = \@users if @users;
231 # copy out the PC16 data for a node into the
232 # pc16n and u slots if there are any users
239 $thing->{'s'} = 'cf';
241 my @u = $uref->users;
243 $thing->{ausers} = [map {Route::User::get($_)} @u];