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);
33 unless ($thing->{Aranea}) {
35 if ($ref = $thing->{anodes}) {
36 $thing->{a} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
38 if ($ref = $thing->{anodes}) {
39 $thing->{n} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
41 if ($ref = $thing->{ausers}) {
42 $thing->{u} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
44 $thing->{Aranea} = Aranea::genmsg($thing, [qw(s a n u)]);
46 return $thing->{Aranea};
62 my $sub = "handle_$thing->{s}";
63 if ($thing->can($sub)) {
65 $thing = $thing->$sub($dxchan);
68 $thing->broadcast($dxchan) if $thing;
72 # this handles the standard local configuration, it
73 # will reset all the config, make / break links and
74 # will generate pc sentences as required for nodes and users
79 my $origin = $thing->{user} || $thing->{origin};
80 my $chan_call = $dxchan->{call};
82 my $parent = Route::Node::get($origin);
84 dbg("Thingy::Rt::cf: received from $thing->{origin}/$origin on $chan_call unknown") if isdbg('chanerr');
92 %in = (map {my ($here, $call) = unpack("A1 A*", $_); ($call, $here)} split /:/, $thing->{n});
93 my ($tdel, $tadd) = $parent->diff_nodes(keys %in);
98 %in = (map {my ($here, $call) = unpack("A1 A*", $_); ($call, $here)} split /:/, $thing->{a});
99 my ($tdel, $tadd) = $parent->diff_nodes(keys %in);
103 if (@$add || @$del) {
107 foreach $call (@$del) {
108 RouteDB::delete($call, $chan_call);
109 my $ref = Route::Node::get($call);
110 push @pc21, $ref->del($parent) if $ref;
112 $thing->{pc21n} = \@pc21 if @pc21;
115 foreach $call (@$add) {
116 RouteDB::update($call, $chan_call);
117 my $ref = Route::Node::get($call);
118 push @pc19, $parent->add($call, 0, $in{$call}) unless $ref;
120 $thing->{pc19n} = \@pc19 if @pc19;
125 %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{u});
126 ($del, $add) = $parent->diff_users(keys %in);
131 foreach $call (@$del) {
132 RouteDB::delete($call, $chan_call);
133 my $ref = Route::User::get($call);
135 $parent->del_user($ref);
138 dbg("Thingy::Rt::lcf: del user $call not known, ignored") if isdbg('chanerr');
143 $thing->{pc17n} = $parent;
144 $thing->{pc17u} = \@pc17;
148 foreach $call (@$add) {
149 RouteDB::update($call, $chan_call);
150 push @pc16, _add_user($parent, $call, $in{$call});
153 $thing->{pc16n} = $parent;
154 $thing->{pc16u} = \@pc16;
168 my @out = $node->add_user($user, $flag);
169 my $ur = _upd_user_rec($user, $node);
177 my $parentcall = shift;
179 # add this station to the user database, if required
180 my $user = DXUser->get_current($call);
181 $user = DXUser->new($call) if !$user;
182 $user->homenode($parentcall) if !$user->homenode;
183 $user->node($parentcall);
184 $user->lastin($main::systime) unless DXChannel::get($call);
189 # Generate a configuration for onward broadcast
191 # Basically, this creates a thingy with list of nodes and users that
192 # are on this node. This the normal method of spreading this
193 # info whenever a node connects and also periodically.
199 my $thing = $pkg->SUPER::new(@_);
201 $thing->{'s'} = 'cf';
207 foreach my $dxchan (DXChannel::get_all()) {
208 next if $dxchan == $main::me;
209 if ($dxchan->is_node) {
210 my $ref = Route::Node::get($dxchan->{call});
211 push @pnodes, $ref if $ref;
212 } elsif ($dxchan->is_aranea) {
213 my $ref = Route::Node::get($dxchan->{call});
214 push @anodes, $ref if $ref;
216 my $ref = Route::User::get($dxchan->{call});
217 push @users, $ref if $ref;
220 $thing->{anodes} = \@anodes if @anodes;
221 $thing->{pnodes} = \@pnodes if @pnodes;
222 $thing->{ausers} = \@users if @users;
227 # copy out the PC16 data for a node into the
228 # pc16n and u slots if there are any users
235 $thing->{'s'} = 'cf';
237 my @u = $uref->users;
239 $thing->{pc16n} = $uref;
240 $thing->{pc16u} = [map {Route::User::get($_)} @u];