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->{n} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
38 if ($ref = $thing->{ausers}) {
39 $thing->{u} = join(':', map {"$_->{flags}$_->{call}"} @$ref);
41 $thing->{Aranea} = Aranea::genmsg($thing, [qw(s n u)]);
43 return $thing->{Aranea};
59 my $sub = "handle_$thing->{s}";
60 if ($thing->can($sub)) {
62 $thing = $thing->$sub($dxchan);
65 $thing->broadcast($dxchan) if $thing;
69 # this handles the standard local configuration, it
70 # will reset all the config, make / break links and
71 # will generate pc sentences as required for nodes and users
76 my $origin = $thing->{origin};
77 my $chan_call = $dxchan->{call};
79 my $parent = Route::Node::get($origin);
81 dbg("Thingy::Rt::lcf: received from $origin on $chan_call unknown") if isdbg('chanerr');
87 my %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{n});
88 my ($del, $add) = $parent->diff_nodes(keys %in);
93 foreach $call (@$del) {
94 RouteDB::delete($call, $chan_call);
95 my $ref = Route::Node::get($call);
96 push @pc21, $ref->del($parent) if $ref;
98 $thing->{pc21n} = \@pc21 if @pc21;
101 foreach $call (@$add) {
102 RouteDB::update($call, $chan_call);
103 my $ref = Route::Node::get($call);
104 push @pc19, $parent->add($call, 0, $in{$call}) unless $ref;
106 $thing->{pc19n} = \@pc19 if @pc19;
111 my %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{u});
112 my ($del, $add) = $parent->diff_users(keys %in);
117 foreach $call (@$del) {
118 RouteDB::delete($call, $chan_call);
119 my $ref = Route::User::get($call);
121 $parent->del_user($ref);
124 dbg("Thingy::Rt::lcf: del user $call not known, ignored") if isdbg('chanerr');
129 $thing->{pc17n} = $parent;
130 $thing->{pc17u} = \@pc17;
134 foreach $call (@$add) {
135 RouteDB::update($call, $chan_call);
136 push @pc16, _add_user($parent, $call, $in{$call});
139 $thing->{pc16n} = $parent;
140 $thing->{pc16u} = \@pc16;
153 my @out = $node->add_user($user, $flag);
154 my $ur = _upd_user_rec($user, $node);
162 my $parentcall = shift;
164 # add this station to the user database, if required
165 $call =~ s/-\d+$//o; # remove ssid for users
166 my $user = DXUser->get_current($call);
167 $user = DXUser->new($call) if !$user;
168 $user->homenode($parentcall) if !$user->homenode;
169 $user->node($parentcall);
170 $user->lastin($main::systime) unless DXChannel::get($call);
175 # Generate a configuration for onward broadcast
177 # Basically, this creates a thingy with list of nodes and users that
178 # are on this node. This the normal method of spreading this
179 # info whenever a node connects and also periodically.
185 my $thing = $pkg->SUPER::new(@_);
187 $thing->{'s'} = 'lcf';
192 foreach my $dxchan (DXChannel::get_all()) {
193 if ($dxchan->is_node || $dxchan->is_aranea) {
194 my $ref = Route::Node::get($dxchan->{call});
195 push @nodes, $ref if $ref;
197 my $ref = Route::User::get($dxchan->{call});
198 push @users, $ref if $ref;
201 $thing->{anodes} = \@nodes if @nodes;
202 $thing->{ausers} = \@users if @users;