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;
28 @ISA = qw(Thingy Thingy::RouteFilter);
35 unless ($thing->{Aranea}) {
37 if ($ref = $thing->{anodes}) {
38 $thing->{a} = join(':', map {"$_->{flags}$_->{call}"} @$ref) || '';
40 if ($ref = $thing->{pnodes}) {
41 $thing->{n} = join(':', map {"$_->{flags}$_->{call}"} @$ref) || '';
43 if ($ref = $thing->{ausers}) {
44 $thing->{u} = join(':', map {"$_->{flags}$_->{call}"} @$ref) || '';
46 $thing->{Aranea} = Aranea::genmsg($thing, [qw(s a n u)]);
49 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->{origin};
85 my $chan_call = $dxchan->{call};
90 my $parent = Route::Node::get($origin);
92 dbg("Thingy::Rt::cf: new (unconnected) node $origin arrived") if isdbg('chanerr');
93 $parent = Route::Node::new($origin, 0, 1);
98 # move the origin over to the user, if required
100 $origin = $thing->{user};
101 my $ref = Route::Node::get($origin);
105 # auto vivify a node that has come that we don't know about
106 push @pc19, $parent->add($origin, 0, 1);
107 $parent = Route::Node::get($origin); # reparent to me now.
115 for (split(/:/, $thing->{n})) {
116 my ($here, $call) = unpack("A1 A*", $_);
117 next if $call eq $main::mycall;
122 for (split(/:/, $thing->{a})) {
123 my ($here, $call) = unpack("A1 A*", $_);
124 next if $call eq $main::mycall;
128 my ($del, $add) = $parent->diff_nodes(keys %in);
130 foreach my $call (@$del) {
131 next if $call eq $main::mycall;
132 RouteDB::delete($call, $chan_call);
133 my $ref = Route::Node::get($call);
135 push @pc21, grep {$_} $ref->del($parent);
140 foreach my $call (@$add) {
141 next if $call eq $main::mycall;
142 RouteDB::update($call, $chan_call);
143 my $here = $in{$call};
144 push @pc19, grep {$_} $parent->add($call, 0, $here);
147 $thing->{pc21n} = \@pc21 if @pc21;
148 $thing->{pc19n} = \@pc19 if @pc19;
152 %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{u});
153 ($del, $add) = $parent->diff_users(keys %in);
158 foreach $call (@$del) {
159 RouteDB::delete($call, $chan_call);
160 my $ref = Route::User::get($call);
162 $parent->del_user($ref);
165 dbg("Thingy::Rt::lcf: del user $call not known, ignored") if isdbg('chanerr');
170 $thing->{pc17n} = $parent;
171 $thing->{pc17u} = \@pc17;
175 foreach $call (@$add) {
176 RouteDB::update($call, $chan_call);
177 push @pc16, _add_user($parent, $call, $in{$call});
180 $thing->{pc16n} = $parent;
181 $thing->{pc16u} = \@pc16;
195 my @out = $node->add_user($user, $flag);
196 my $ur = _upd_user_rec($user, $node->{call});
204 my $parentcall = shift;
206 # add this station to the user database, if required
207 my $user = DXUser->get_current($call);
208 $user = DXUser->new($call) if !$user;
209 $user->homenode($parentcall) if !$user->homenode;
210 $user->node($parentcall);
211 $user->lastin($main::systime) unless DXChannel::get($call);
216 # Generate a configuration for onward broadcast
218 # Basically, this creates a thingy with list of nodes and users that
219 # are on this node. This the normal method of spreading this
220 # info whenever a node connects and also periodically.
226 my $thing = $pkg->SUPER::new(@_);
228 $thing->{'s'} = 'cf';
234 foreach my $dxchan (DXChannel::get_all()) {
235 next if $dxchan == $main::me;
236 if ($dxchan->is_node) {
237 my $ref = Route::Node::get($dxchan->{call});
238 push @pnodes, $ref if $ref;
239 } elsif ($dxchan->is_aranea) {
240 my $ref = Route::Node::get($dxchan->{call});
241 push @anodes, $ref if $ref;
243 my $ref = Route::User::get($dxchan->{call});
244 push @users, $ref if $ref;
247 $thing->{anodes} = \@anodes if @anodes;
248 $thing->{pnodes} = \@pnodes if @pnodes;
249 $thing->{ausers} = \@users if @users;
254 # copy out the PC16 data for a node into the
255 # pc16n and u slots if there are any users
262 $thing->{'s'} = 'cf';
264 my @u = map {Route::User::get($_)} $uref->users;
265 $thing->{ausers} = \@u if @u;