2 # Generate route Thingies
6 # Copyright (c) 2004 Dirk Koopman G1TLH
13 use vars qw($VERSION $BRANCH);
14 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
15 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/,(0,0));
16 $main::build += $VERSION;
17 $main::branch += $BRANCH;
23 # this is node connect
30 my $t = $pkg->SUPER::new(_fromnode=>$fromnode,
32 id=>'DXSpider', v=>$main::version, b=>$main::build, t=>'nc', n=>\@n);
36 # this is node disconnect
37 sub new_node_disconnect
43 my $t = $pkg->SUPER::new(_fromnode=>$fromnode,
54 my @nodes = grep {$_ ne $main::mycall} DXChannel::get_all_node_calls();
55 my @users = DXChannel::get_all_user_calls();
57 my $t = $pkg->SUPER::new(t=>'nu',
58 id=>'DXSpider', v=>$main::version, b=>$main::build,
59 n=>\@nodes, u=>\@users);
69 my $t = $pkg->SUPER::new(_fromnode=>$fromnode,
75 sub new_user_discconnect
81 my $t = $pkg->SUPER::new(_fromnode=>$fromnode,
92 # node update (this will completely rewrite the node's info)
106 # first get the fromnode
107 my $dxchan = DXChannel->get($t->{_inon}) || return;
108 my $parent = Route::Node::get($t->{_fromnode});
111 push @rout, $parent = Route::Node->new($t->{_fromnode});
115 my ($here, $call) = unpack "AA*", $_;
117 # if it is a new node add it to the user database
118 my $user = DXUser->get_current($call);
120 $user = DXUser->new($call);
122 $user->priv(1); # I have relented and defaulted nodes
124 $user->homenode($call);
128 # add each of the nodes to this parent
131 # add this station to the user database, if required (don't remove SSID from nodes)
133 my $r = Route::Node::get($call);
134 my $flags = Route::here($here)|Route::conf($conf);
136 # modify the routing table if it is in it, otherwise store it in the pc19list for now
139 if ($call ne $parent->call) {
140 if ($self->in_filter_route($r)) {
141 $ar = $parent->add($call, $ver, $flags);
142 push @rout, $ar if $ar;
147 if ($r->version ne $ver || $r->flags != $flags) {
150 push @rout, $r unless $ar;
154 # if he is directly connected or allowed then add him, otherwise store him up for later
155 if ($call eq $self->{call} || $user->wantroutepc19) {
156 my $new = Route->new($call); # throw away
157 if ($self->in_filter_route($new)) {
158 my $ar = $parent->add($call, $ver, $flags);
159 $user->wantroutepc19(1) unless defined $user->wantroutepc19;
160 push @rout, $ar if $ar;
165 $pc19list{$call} = [] unless exists $pc19list{$call};
166 my $nl = $pc19list{$call};
167 push @{$pc19list{$call}}, [$self->{call}, $ver, $flags] unless grep $_->[0] eq $self->{call}, @$nl;
171 # unbusy and stop and outgoing mail (ie if somehow we receive another PC19 without a disconnect)
172 my $mref = DXMsg::get_busy($call);
173 $mref->stop_msg($call) if $mref;
175 $user->lastin($main::systime) unless DXChannel->get($call);
180 $self->route_pc19($origin, $line, @rout) if @rout;
196 my $newline = "PC16^";
197 my $parent = Route::Node::get($t->{_fromnode});
199 # if there is a parent, proceed, otherwise if there is a latent PC19 in the PC19list,
200 # fix it up in the routing tables and issue it forth before the PC16
202 my $nl = $pc19list{$ncall};
204 if ($nl && @_ > 3) { # 3 because of the hop count!
206 # this is a new (remembered) node, now attach it to me if it isn't in filtered
207 # and we haven't disallowed it
208 my $user = DXUser->get_current($ncall);
210 $user = DXUser->new($ncall);
212 $user->priv(1); # I have relented and defaulted nodes
214 $user->homenode($ncall);
218 my $wantpc19 = $user->wantroutepc19;
219 if ($wantpc19 || !defined $wantpc19) {
220 my $new = Route->new($ncall); # throw away
221 if ($self->in_filter_route($new)) {
224 $parent = Route::Node::get($_->[0]);
225 $dxchan = $parent->dxchan if $parent;
226 if ($dxchan && $dxchan ne $self) {
227 dbg("PCPROT: PC19 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
231 my $r = $parent->add($ncall, $_->[1], $_->[2]);
232 push @nrout, $r unless @nrout;
235 $user->wantroutepc19(1) unless defined $wantpc19; # for now we work on the basis that pc16 = real route
236 $user->lastin($main::systime) unless DXChannel->get($ncall);
239 # route the pc19 - this will cause 'stuttering PC19s' for a while
240 $self->route_pc19($origin, $line, @nrout) if @nrout ;
241 $parent = Route::Node::get($ncall);
243 dbg("PCPROT: lost $ncall after sending PC19 for it?");
249 delete $pc19list{$ncall};
252 dbg("PCPROT: Node $ncall not in config") if isdbg('chanerr');
257 $dxchan = $parent->dxchan;
258 if ($dxchan && $dxchan ne $self) {
259 dbg("PCPROT: PC16 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
263 # input filter if required
264 return unless $self->in_filter_route($parent);
269 for ($i = 2; $i < $#_; $i++) {
270 my ($call, $conf, $here) = $_[$i] =~ /^(\S+) (\S) (\d)/o;
271 next unless $call && $conf && defined $here && is_callsign($call);
272 next if $call eq $main::mycall;
274 eph_del_regex("^PC17\\^$call\\^$ncall");
276 $conf = $conf eq '*';
278 # reject this if we think it is a node already
279 my $r = Route::Node::get($call);
280 my $u = DXUser->get_current($call) unless $r;
281 if ($r || ($u && $u->is_node)) {
282 dbg("PCPROT: $call is a node") if isdbg('chanerr');
286 $r = Route::User::get($call);
287 my $flags = Route::here($here)|Route::conf($conf);
290 my $au = $r->addparent($parent);
291 if ($r->flags != $flags) {
295 push @rout, $r if $au;
297 push @rout, $parent->add_user($call, $flags);
301 # add this station to the user database, if required
302 $call =~ s/-\d+$//o; # remove ssid for users
303 my $user = DXUser->get_current($call);
304 $user = DXUser->new($call) if !$user;
305 $user->homenode($parent->call) if !$user->homenode;
306 $user->node($parent->call);
307 $user->lastin($main::systime) unless DXChannel->get($call);
310 $self->route_pc16($origin, $line, $parent, @rout) if @rout;
318 my $uref = Route::User::get($ucall);
320 dbg("PCPROT: Route::User $ucall not in config") if isdbg('chanerr');
323 my $parent = Route::Node::get($ncall);
325 dbg("PCPROT: Route::Node $ncall not in config") if isdbg('chanerr');
329 $dxchan = $parent->dxchan;
330 if ($dxchan && $dxchan ne $self) {
331 dbg("PCPROT: PC17 from $self->{call} trying to alter locally connected $ncall, ignored!") if isdbg('chanerr');
335 # input filter if required
336 return unless $self->in_filter_route($parent);
338 $parent->del_user($uref);
340 if (eph_dup($line)) {
341 dbg("PCPROT: dup PC17 detected") if isdbg('chanerr');
345 $self->route_pc17($origin, $line, $parent, $uref);