+ my $self = shift;
+ my $pref = shift;
+
+ # delete parent from this call's parent list
+ $pref->_delnode($self);
+ $self->_delparent($pref);
+ my @nodes;
+ my $ncall = $self->{call};
+
+ # is this the last connection, I have no parents anymore?
+ unless (@{$self->{parent}}) {
+ 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
+{
+ my $self = shift;
+ for (@{$self->{users}}) {
+ my $ref = Route::User::get($_);
+ $ref->del($self) if $ref;
+ }
+ $self->{users} = [];
+}
+
+# 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;
+
+ my $uref = Route::User::get($ucall);
+ my @out;
+ if ($uref) {
+ @out = $uref->addparent($self);
+ } else {
+ $uref = Route::User->new($ucall, $self->{call}, @_);
+ @out = $uref;
+ }
+ $self->_adduser($uref);
+ $self->{usercount} = scalar @{$self->{users}};
+
+ return @out;
+}
+
+# delete a user from this node
+sub del_user
+{
+ my $self = shift;
+ my $ref = shift;
+ my @out;
+
+ if ($ref) {
+ @out = $self->_deluser($ref);
+ $ref->del($self);
+ } else {
+ confess "tried to delete non-existant $ref->{call} from $self->{call}";
+ }
+ $self->{usercount} = scalar @{$self->{users}};
+ return @out;
+}
+
+sub usercount
+{
+ my $self = shift;
+ if (@_ && @{$self->{users}} == 0) {
+ $self->{usercount} = shift;
+ }
+ return $self->{usercount};
+}
+
+sub users
+{
+ my $self = shift;
+ return @{$self->{users}};
+}
+
+sub nodes
+{
+ my $self = shift;
+ return @{$self->{nodes}};
+}
+
+sub parents
+{
+ my $self = shift;
+ return @{$self->{parent}};
+}
+
+sub rnodes
+{
+ my $self = shift;
+ my @out;
+ foreach my $call (@{$self->{nodes}}) {
+ next if grep $call eq $_, @_;
+ push @out, $call;
+ my $r = get($call);
+ push @out, $r->rnodes($call, @_) if $r;
+ }
+ return @out;
+}
+
+# this takes in a list of node and user calls (not references) from
+# a config type update for a node and returns
+# the differences as lists of things that have gone away
+# and things that have been added.
+sub calc_config_changes
+{
+ my $self = shift;
+ my %nodes = map {$_ => 1} @{$self->{nodes}};
+ my %users = map {$_ => 1} @{$self->{users}};
+ my $cnodes = shift;
+ my $cusers = shift;
+ my (@dnodes, @dusers, @nnodes, @nusers);
+ push @nnodes, map {my @r = $nodes{$_} ? () : $_; delete $nodes{$_}; @r} @$cnodes;
+ push @dnodes, keys %nodes;
+ push @nusers, map {my @r = $users{$_} ? () : $_; delete $users{$_}; @r} @$cusers;
+ push @dusers, keys %users;
+ return (\@dnodes, \@dusers, \@nnodes, \@nusers);