X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute%2FNode.pm;h=4bb4c9ca4812624e43b6ed9170f7504c1d17c16a;hb=24656c96ca7d059dd24ac5a53a3ed55b164e756f;hp=c70682040e31bec42d67986cae10c6084850b3b3;hpb=febdc9bd8f6cd065d217ba089fab4361e9980f35;p=spider.git diff --git a/perl/Route/Node.pm b/perl/Route/Node.pm index c7068204..4bb4c9ca 100644 --- a/perl/Route/Node.pm +++ b/perl/Route/Node.pm @@ -56,14 +56,24 @@ sub max sub add { my $parent = shift; - my $call = uc shift; - confess "Route::add trying to add $call to myself" if $call eq $parent->{call}; - my $self = get($call); + my $call = shift; + my $self; + + if (ref $call) { + $self = $call; + $call = $self->{call}; + } else { + $self = get($call); + } + + confess "Trying to add NULL Node call to routing tables" unless $call; + if ($self) { $self->_addparent($parent->{call}); $parent->_addnode($call); return undef; } + confess "Route::Node::add trying to add $call to myself" if $call eq $parent->{call}; $parent->_addnode($call); $self = $parent->new($call, @_); return $self; @@ -83,19 +93,35 @@ sub del # delete parent from this call's parent list my $pcall = $pref->{call}; + my $ncall = $self->{call}; + $pref->_delnode($ncall);; my $ref = $self->_delparent($pcall); my @nodes; - # is this the last connection? - $self->_del_users; + # is this the last connection, I have no parents anymore? unless (@$ref) { - push @nodes, $self->del_nodes; + foreach my $rcall (@{$self->{nodes}}) { + next if grep $rcall eq $_, @_; + my $r = Route::Node::get($rcall); + push @nodes, $r->del($self, $ncall, @_) if $r; + } + $self->_del_users; delete $list{$self->{call}}; push @nodes, $self; } return @nodes; } +sub del_nodes +{ + my $parent = shift; + my @out; + foreach my $rcall (@{$parent->{nodes}}) { + my $r = get($rcall); + push @out, $r->del($parent, $parent->{call}, @_) if $r; + } + return @out; +} sub _del_users { @@ -107,41 +133,14 @@ sub _del_users $self->{users} = []; } -# remove all sub nodes from this parent -sub del_nodes -{ - my $self = shift; - my @nodes; - - for (@{$self->{nodes}}) { - next if $self->{call} eq $_; - push @nodes, $self->del_node($_); - } - return @nodes; -} - -# delete a node from this node (ie I am a parent) -sub del_node -{ - my $self = shift; - my $ncall = shift; - my @out; - $self->_delnode($ncall); - if (my $ref = get($ncall)) { - foreach my $rcall (@{$ref->{nodes}}) { - next if $rcall eq $ncall || $rcall eq $self->{call}; - push @out, $ref->del_node($rcall); - } - push @out, $ref->del($self); - } - return @out; -} - # add a user to this node sub add_user { my $self = shift; my $ucall = shift; + + confess "Trying to add NULL User call to routing tables" unless $ucall; + $self->_adduser($ucall); $self->{usercount} = scalar @{$self->{users}}; @@ -190,7 +189,7 @@ sub rnodes next if grep $call eq $_, @_; push @out, $call; my $r = get($call); - push @out, $r->rnodes(@_, @out) if $r; + push @out, $r->rnodes($call, @_) if $r; } return @out; } @@ -219,7 +218,9 @@ sub get { my $call = shift; $call = shift if ref $call; - return $list{uc $call}; + my $ref = $list{uc $call}; + dbg("Failed to get Node $call" ) if !$ref && isdbg('routerr'); + return $ref; } sub get_all @@ -271,7 +272,7 @@ sub DESTROY my $pkg = ref $self; my $call = $self->{call} || "Unknown"; - dbg('route', "destroying $pkg with $call"); + dbg("destroying $pkg with $call") if isdbg('routelow'); } #