add the ability to limit no of connections
authorDirk Koopman <djk@tobit.co.uk>
Wed, 1 Oct 2008 22:04:48 +0000 (23:04 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Wed, 1 Oct 2008 22:04:48 +0000 (23:04 +0100)
Add the ability to limit the no of connections an incoming user/node
has. If a node/user is already connected elsewhere more than the maximum
no of times then this incoming connection is refused.

Changes
cmd/stat/nodeconfig.pl
cmd/stat/userconfig.pl
perl/DXCommandmode.pm
perl/DXProtHandle.pm
perl/Messages
perl/Route.pm
perl/Route/Node.pm
perl/Route/User.pm
perl/Version.pm
perl/cluster.pl

diff --git a/Changes b/Changes
index a5431faa01efe25e104bfff623c532b8d334a00f..e84146cb7423f8e4455ee5f4a26d7b4dc2bd743c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
 01Oct08=======================================================================
 1. added CTY-1809 prefix data
+2. added new config variables to allow an incoming users to have (as default)
+up to 2 other connections to other nodes and incoming nodes up to 8 other
+parents. Note that you can switch off this behaviour by setting
+$main::maxconnect_user or $main::maxconnect_node = 0 (or set them to whatever
+you need).
 28Jun08=======================================================================
 1. Made buddies work again on PC92.
 26Jun08=======================================================================
index 00f1c94cabb4a65dc061c99d158ff0524758160a..88e353d26f1bee3055d596e78ca243cfe8d45d55 100644 (file)
@@ -15,7 +15,7 @@ foreach my $nref (@nodes) {
        my $ncall = $nref->call;
        next if @list && !grep $ncall =~ m|$_|, @list;
        my $call = $nref->user_call;
-       my $l = join ',', (map {my $ref = Route::Node::get($_); $ref ? ($ref->user_call) : ("$_?")} sort @{$nref->parent});
+       my $l = join ',', (map {my $ref = Route::Node::get($_); $ref ? ($ref->user_call) : ("$_?")} sort $nref->parents);
        push @out, "$call->$l";
 }
 
index fd86f74817b0c4c7e8495b2065b1cc06e93ba362..6d3b389f66252674b592a963e809fab3dd77284d 100644 (file)
@@ -15,7 +15,7 @@ foreach my $uref (@users) {
        my $ucall = $uref->call;
        next if @list && !grep $ucall =~ m|$_|, @list;
        my $call = $uref->user_call;
-       my $l = join ',', (map {my $ref = Route::Node::get($_); $ref ? ($ref->user_call) : ("$_?")} sort @{$uref->parent});
+       my $l = join ',', (map {my $ref = Route::Node::get($_); $ref ? ($ref->user_call) : ("$_?")} sort $uref->parents);
        push @out, "$call->$l";
 }
 
index 854a635496e058a651896d04bc8f412a381f84ea..c75f32f165a47fb80bbd0f59920dfff6be5d6937 100644 (file)
@@ -218,7 +218,7 @@ sub start
        foreach my $call (@{$user->buddies}) {
                my $ref = Route::User::get($call);
                if ($ref) {
-                       foreach my $node (@{$ref->parent}) {
+                       foreach my $node ($ref->parents) {
                                $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
                        } 
                }
index c5f6cc81b2a7edcf0043b94e37ac2665d5dbceae..8d766732777e31a90dc5c74f735ea3ca5136ae75 100644 (file)
@@ -1860,7 +1860,7 @@ sub find_pc9x_routes
        if ($ref->isa('Route::User')) {
                my $dxchan = DXChannel::get($to);
                push @parent, $to if $dxchan;
-               push @parent, @{$ref->parent};
+               push @parent, $ref->parents;
        } else {
                @parent = $to;
        }
index 11c70d52d5d7847dfc12ae5b98b60eec9e58a225..38e030f0f02423ae3b8ae9449aef478c53047758 100644 (file)
@@ -36,6 +36,7 @@ package DXM;
                                chattoomany => 'Not allowed, already in $_[1], use /chat $_[0]',
                                conother => 'Sorry $_[0] you are connected to me on another port',
                                concluster => 'Sorry $_[0] you are already connected elsewhere on the cluster (on $_[1])',
+                               contomany => 'Sorry $_[0] but you are already connected to $_[1] other nodes (on $_[2])',
                                conscript => 'no connect script called \"$_[0]\" found in $main::root/connect',
                                confail => 'connection to $_[0] failed ($_[1])',
                                constart => 'connection to $_[0] started',
index eb83af11f8e16d6c1cb55e7e6429ddf6905911af..443b3ee9e037a4e2a19c0de5299ef5b11de5441c 100644 (file)
@@ -375,7 +375,6 @@ sub delete_interface
 
 }
 
-
 #
 # track destruction
 #
index 9c2b734e1b3bb867243c59a5a28b1ba37d3c577c..123f21f9f2e952d4c74a06a69ddf8c8544afa212 100644 (file)
@@ -221,12 +221,6 @@ sub nodes
        return @{$self->{nodes}};
 }
 
-sub parents
-{
-       my $self = shift;
-       return @{$self->{parent}};
-}
-
 sub rnodes
 {
        my $self = shift;
index fc2de00a7a8b6c9ea90341cf4ebdd1fec9e3b6ed..e25c199cfdd40e6e7a8dc5ce53b23e916ab070b6 100644 (file)
@@ -92,6 +92,8 @@ sub delparent
     return $self->_dellist('parent', @_);
 }
 
+
+
 #
 # generic AUTOLOAD for accessors
 #
index 644cba93a04b34734cddafe0843e3ae5217a668a..be2a961b28df1917e754386aa2eb814b5a4965b2 100644 (file)
@@ -11,6 +11,6 @@ use vars qw($version $subversion $build);
 
 $version = '1.55';
 $subversion = '0';
-$build = '27';
+$build = '28';
 
 1;
index 25b84a9cec3ade5663a27a4fe7ca02eb62a8556f..46f4818325af00ef5945e48ac2027e58dbef3877 100755 (executable)
@@ -118,7 +118,7 @@ use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects
                        $zombies $root @listeners $lang $myalias @debug $userfn $clusteraddr
                        $clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting
                        $allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart
-                       $can_encode
+                       $can_encode $maxconnect_user $maxconnect_node
                   );
 
 @inqueue = ();                                 # the main input queue, an array of hashes
@@ -129,7 +129,10 @@ $starttime = 0;                 # the starting time of the cluster
 $reqreg = 0;                                   # 1 = registration required, 2 = deregister people
 $bumpexisting = 1;                             # 1 = allow new connection to disconnect old, 0 - don't allow it
 $allowdxby = 0;                                        # 1 = allow "dx by <othercall>", 0 - don't allow it
-
+$maxconnect_user = 3;                  # the maximum no of concurrent connections a user can have at a time
+$maxconnect_node = 8;                  # Ditto but for nodes. In either case if a new incoming connection
+                                                               # takes the no of references in the routing table above these numbers
+                                                               # then the connection is refused. This only affects INCOMING connections.
 
 # send a message to call on conn and disconnect
 sub already_conn
@@ -182,6 +185,19 @@ sub new_channel
                }
        }
 
+       # (fairly) politely disconnect people that are connected to too many other places at once
+       my $r = Route::get($call);
+       if ($r) {
+               my @n = $r->parents;
+               my $v = $r->isa('Route::Node') ? $maxconnect_node : $maxconnect_user;
+               if ($v && @n >= $v) {
+                       my $nodes = join ',', @n;
+                       LogDbg('DXCommand', "$call has too many connections ($v) at $nodes, disconnected");
+                       already_conn($conn, $call, DXM::msg($lang, 'contomany', $call, $v, $nodes));
+                       return;
+               }
+       }
+
        # is he locked out ?
        my $basecall = $call;
        $basecall =~ s/-\d+$//;