get to a reasonably stable stage in the route info exchange.
authorminima <minima>
Tue, 22 Feb 2005 11:29:06 +0000 (11:29 +0000)
committerminima <minima>
Tue, 22 Feb 2005 11:29:06 +0000 (11:29 +0000)
perl/DXProtout.pm
perl/Route.pm
perl/Route/Node.pm
perl/Route/User.pm
perl/Thingy/Bye.pm
perl/Thingy/Hello.pm
perl/Thingy/RouteFilter.pm
perl/Thingy/Rt.pm

index d27730621559a9915709c1d3fdc5086bc6f1b4ed..d035f7ae605a0faeb77af87b5534ee3f1eada2b5 100644 (file)
@@ -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;
index 5f9de7d72a823db72b50d20791362638e6454e02..019ba1e3c68f1355f6f7f1c223e0754733f49075 100644 (file)
@@ -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;
 }
index 5858ddcc0053184f77b2eb7481441a3906c3c660..2350f86f062dacbd0218e8f4a2c53f67a00df042 100644 (file)
@@ -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;
index b9862e6de5f0b847a627a4af0279e2043cc85660..d63850d89e8de89e8c20e1e75c661d6ca10c3a7f 100644 (file)
@@ -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;
index 6d75b618e2832befe2cf4c58088964953266a890..ad8059c69cacfe1d0b481528821f3987dcf3373e 100644 (file)
@@ -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 {
index ed3e5b5cc68f7c5e607ab77b83c771657e0bd16c..4ff8ebda6f9b63fb254362ea7ce5b8fd01d9500b 100644 (file)
@@ -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 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};
        
index 0e5bf3e8ce3a0dec514a78f80bdd3edee398b2e3..ac238ffef048782b8e13d3865666b839ba96b0d6 100644 (file)
@@ -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;
index 798f0a82f98748a836ae5ccd782fde79b810b30c..d06d5a380e0185e0f5f20b2b28a376aee80ec5ff 100644 (file)
@@ -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;