From eb2a2eb1aa8e7c743c23ec5e0dc5aa40a8708e79 Mon Sep 17 00:00:00 2001 From: minima Date: Tue, 22 Feb 2005 11:29:06 +0000 Subject: [PATCH] get to a reasonably stable stage in the route info exchange. --- perl/DXProtout.pm | 2 +- perl/Route.pm | 6 +-- perl/Route/Node.pm | 40 ++++++++++++++-- perl/Route/User.pm | 2 +- perl/Thingy/Bye.pm | 7 ++- perl/Thingy/Hello.pm | 37 ++++++++++----- perl/Thingy/RouteFilter.pm | 2 +- perl/Thingy/Rt.pm | 93 +++++++++++++++++++++++++++++++++++--- 8 files changed, 161 insertions(+), 28 deletions(-) diff --git a/perl/DXProtout.pm b/perl/DXProtout.pm index d2773062..d035f7ae 100644 --- a/perl/DXProtout.pm +++ b/perl/DXProtout.pm @@ -107,8 +107,8 @@ sub pc16 sub pc17 { my @out; + my $node = shift; while (@_) { - my $node = shift; my $ref = shift; my $hops = get_hops(17); my $ncall = $node->call; diff --git a/perl/Route.pm b/perl/Route.pm index 5f9de7d7..019ba1e3 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -157,8 +157,8 @@ sub here { my $self = shift; my $r = shift; - return $self ? 2 : 0 unless ref $self; - return ($self->{flags} & 2) ? 1 : 0 unless defined $r; + return $self ? 1 : 0 unless ref $self; + return ($self->{flags} & 1) ? 1 : 0 unless defined $r; $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0)); return $r ? 1 : 0; } @@ -168,7 +168,7 @@ sub conf my $self = shift; my $r = shift; return $self ? 2 : 0 unless ref $self; - return ($self->{flags} & 1) ? 1 : 0 unless defined $r; + return ($self->{flags} & 2) ? 2 : 0 unless defined $r; $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0)); return $r ? 2 : 0; } diff --git a/perl/Route/Node.pm b/perl/Route/Node.pm index 5858ddcc..2350f86f 100644 --- a/perl/Route/Node.pm +++ b/perl/Route/Node.pm @@ -27,8 +27,9 @@ use vars qw(%list %valid @ISA $max $filterdef); users => '0,Users,parray', usercount => '0,User Count', version => '0,Version', + build => '0,Build', + sw => '0,Software', np => '0,Using New Prot,yesno', - lid => '0,Last Msgid', ); $filterdef = $Route::filterdef; @@ -208,6 +209,39 @@ sub rnodes return @out; } +# return the differences in nodes between what we currently have and +# the list proffered. Returns two refs one to a list of nodes to remove and +# the other a list of nodes to add +# +# input is a list of callsigns (not refs) +sub diff_nodes +{ + my $self = shift; + my $in = ref $_[0] ? shift : \@_; + my %del = map {($_, 1)} nodes($self); + my %in = map {($_, 1)} @$in; + + # remove all the calls that are in both lists + for (@$in) { + delete $in{$_} if delete $del{$_}; + } + return ([keys %del], [keys %in]); +} + +# same as above but for users +sub diff_users +{ + my $self = shift; + my $in = ref $_[0] ? shift : \@_; + my %del = map {($_, 1)} users($self); + my %in = map {($_, 1)} @$in; + + # remove all the calls that are in both lists + for (@$in) { + delete $in{$_} if delete $del{$_}; + } + return ([keys %del], [keys %in]); +} sub new { @@ -218,8 +252,8 @@ sub new my $self = $pkg->SUPER::new($call); $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ]; - $self->{version} = shift; - $self->{flags} = shift; + $self->{version} = 0 || shift; + $self->{flags} = 0 || shift; $self->{users} = []; $self->{nodes} = []; $self->{lid} = 0; diff --git a/perl/Route/User.pm b/perl/Route/User.pm index b9862e6d..d63850d8 100644 --- a/perl/Route/User.pm +++ b/perl/Route/User.pm @@ -53,7 +53,7 @@ sub new my $self = $pkg->SUPER::new($call); $self->{parent} = [ $ncall ]; - $self->{flags} = $flags; + $self->{flags} = 0 || $flags; $list{$call} = $self; return $self; diff --git a/perl/Thingy/Bye.pm b/perl/Thingy/Bye.pm index 6d75b618..ad8059c6 100644 --- a/perl/Thingy/Bye.pm +++ b/perl/Thingy/Bye.pm @@ -1,6 +1,9 @@ # # Bye Thingy handling # +# Note that this is a generator of pc21n and pc17n/pc17u +# and a consumer of fpc21n and fpc21n +# # $Id$ # # Copyright (c) 2005 Dirk Koopman G1TLH @@ -55,8 +58,8 @@ sub handle @pc21 = $parent->del($uref); } else { $parent->del_user($uref); - $thing->{pc17n} = $thing->{origin}; - $thing->{pc17u} = $user; + $thing->{pc17n} = $parent; + $thing->{pc17u} = [$uref]; } } } else { diff --git a/perl/Thingy/Hello.pm b/perl/Thingy/Hello.pm index ed3e5b5c..4ff8ebda 100644 --- a/perl/Thingy/Hello.pm +++ b/perl/Thingy/Hello.pm @@ -33,14 +33,20 @@ $verify_on_login = 1; # make sure that a HELLO coming from sub gen_Aranea { my $thing = shift; + my $dxchan = shift; + unless ($thing->{Aranea}) { - $thing->add_auth; - - $thing->{sw} ||= 'DXSp'; - $thing->{v} ||= $main::version; - $thing->{b} ||= $main::build; + if ($thing->{user}) { + $thing->{h} ||= $dxchan->here; + } else { + $thing->add_auth; + $thing->{sw} ||= 'DXSp'; + $thing->{v} ||= $main::version; + $thing->{b} ||= $main::build; + $thing->{h} ||= $main::me->here; + } - $thing->{Aranea} = Aranea::genmsg($thing, [qw(sw v b s auth)]); + $thing->{Aranea} = Aranea::genmsg($thing, [qw(sw h v b s auth)]); } return $thing->{Aranea}; } @@ -61,7 +67,7 @@ sub handle if ($node eq $origin) { # for directly connected calls - if ($verify_on_login) { + if ($verify_on_login && !$thing->{user}) { my $pp = $dxchan->user->passphrase; unless ($pp) { dbglog('err', "Thingy::Hello::handle: verify on and $origin has no passphrase"); @@ -76,7 +82,7 @@ sub handle } } if ($dxchan->{state} ne 'normal') { - $nref = $main::routeroot->add($origin, $thing->{v}, 1); + $nref = $main::routeroot->add($origin, $thing->{v}, $thing->{h}); push @{$thing->{pc19n}}, $nref if $nref; $dxchan->start($dxchan->{conn}->{csort}, $dxchan->{conn}->{outbound} ? 'O' : 'A'); if ($dxchan->{outbound}) { @@ -89,6 +95,7 @@ sub handle } } $nref = Route::Node::get($origin); + $nref->np(1); } else { # for otherwise connected calls, that come in relayed from other nodes @@ -98,6 +105,7 @@ sub handle my $v = $thing->{user} ? undef : $thing->{v}; $nref = Route::Node->new($origin, $v, 1); push @{$thing->{pc19n}}, $nref; + $nref->np(1); } } @@ -107,14 +115,21 @@ sub handle unless ($ur) { my $uref = DXUser->get_current($user); if ($uref->is_node || $uref->is_aranea) { - my $u = $nref->add($user, $thing->{v}, 1); - push @{$thing->{pc19n}}, $u if $u; + $ur = $nref->add($user, $thing->{v}, $thing->{h}); + push @{$thing->{pc19n}}, $ur if $ur; } else { $thing->{pc16n} = $nref; - $thing->{pc16u} = [$nref->add_user($user, 1)]; + $thing->{pc16u} = [$ur = $nref->add_user($user, $thing->{h})]; } } + $ur->np(1); + } else { + $nref->version($thing->{v}) unless $nref->version; + $nref->build($thing->{b}) unless $nref->build; + $nref->sw($thing->{sw}) unless $nref->sw; + $nref->here($thing->{h}) if exists $thing->{h}; } + RouteDB::update($origin, $node, $thing->{hopsaway}); RouteDB::update($thing->{user}, $node, $thing->{hopsaway}) if $thing->{user}; diff --git a/perl/Thingy/RouteFilter.pm b/perl/Thingy/RouteFilter.pm index 0e5bf3e8..ac238ffe 100644 --- a/perl/Thingy/RouteFilter.pm +++ b/perl/Thingy/RouteFilter.pm @@ -39,7 +39,7 @@ sub gen_DXProt my $thing = shift; my @out; push @out, DXProt::pc21(@{$thing->{fpc21n}}) if $thing->{fpc21n}; - push @out, DXProt::pc17($thing->{fpc17n}, $thing->{pc17u}) if $thing->{fpc17n}; + push @out, DXProt::pc17($thing->{fpc17n}, @{$thing->{pc17u}}) if $thing->{fpc17n}; push @out, DXProt::pc19(@{$thing->{fpc19n}}) if $thing->{fpc19n}; push @out, DXProt::pc16($thing->{fpc16n}, @{$thing->{pc16u}}) if $thing->{fpc16n}; return \@out; diff --git a/perl/Thingy/Rt.pm b/perl/Thingy/Rt.pm index 798f0a82..d06d5a38 100644 --- a/perl/Thingy/Rt.pm +++ b/perl/Thingy/Rt.pm @@ -1,6 +1,9 @@ # # Route Thingy handling # +# Note that this is a generator of pc(16|17|19|21)n and pc(16|17)u +# and a consumer of the fpc versions of the above +# # $Id$ # # Copyright (c) 2005 Dirk Koopman G1TLH @@ -30,10 +33,10 @@ sub gen_Aranea unless ($thing->{Aranea}) { my $ref; if ($ref = $thing->{anodes}) { - $thing->{n} = join(':', map {$_->{call}} @$ref); + $thing->{n} = join(':', map {"$_->{flags}$_->{call}"} @$ref); } if ($ref = $thing->{ausers}) { - $thing->{u} = join(':', map {$_->{call}} @$ref); + $thing->{u} = join(':', map {"$_->{flags}$_->{call}"} @$ref); } $thing->{Aranea} = Aranea::genmsg($thing, [qw(s n u)]); } @@ -63,19 +66,97 @@ sub handle } } +# this handles the standard local configuration, it +# will reset all the config, make / break links and +# will generate pc sentences as required for nodes and users +sub handle_lcf +{ + my $thing = shift; + my $dxchan = shift; + my $origin = $thing->{origin}; + my $chan_call = $dxchan->{call}; + + my $parent = Route::Node::get($origin); + unless ($parent) { + dbg("Thingy::Rt::lcf: received from $origin on $chan_call unknown") if isdbg('chanerr'); + return; + } + + # do nodes + if ($thing->{n}) { + my %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{n}); + my ($del, $add) = $parent->diff_nodes(keys %in); + + my $call; + + my @pc21; + foreach $call (@$del) { + RouteDB::delete($call, $chan_call); + my $ref = Route::Node::get($call); + push @pc21, $ref->del($parent) if $ref; + } + $thing->{pc21n} = \@pc21 if @pc21; + + my @pc19; + foreach $call (@$add) { + RouteDB::update($call, $chan_call); + my $ref = Route::Node::get($call); + push @pc19, $parent->add($call, 0, $in{$call}) unless $ref; + } + $thing->{pc19n} = \@pc19 if @pc19; + } + + # now users + if ($thing->{u}) { + my %in = (map {my ($here, $call) = unpack "A1 A*", $_; ($call, $here)} split /:/, $thing->{u}); + my ($del, $add) = $parent->diff_users(keys %in); + + my $call; + + my @pc17; + foreach $call (@$del) { + RouteDB::delete($call, $chan_call); + my $ref = Route::User::get($call); + if ($ref) { + $parent->del_user($ref); + push @pc17, $ref; + } else { + dbg("Thingy::Rt::lcf: del user $call not known, ignored") if isdbg('chanerr'); + next; + } + } + if (@pc17) { + $thing->{pc17n} = $parent; + $thing->{pc17u} = \@pc17; + } + + my @pc16; + foreach $call (@$add) { + RouteDB::update($call, $chan_call); + push @pc16, _add_user($parent, $call, $in{$call}); + } + if (@pc16) { + $thing->{pc16n} = $parent; + $thing->{pc16u} = \@pc16; + } + } + + return $thing; +} -sub add_user +sub _add_user { my $node = shift; my $user = shift; my $flag = shift; - $node->add_user($user, $flag); - my $ur = upd_user_rec($user, $node); + my @out = $node->add_user($user, $flag); + my $ur = _upd_user_rec($user, $node); $ur->put; + return @out; } -sub upd_user_rec +sub _upd_user_rec { my $call = shift; my $parentcall = shift; -- 2.43.0