diff options
-rw-r--r-- | data/docs/11 | 6 | ||||
-rw-r--r-- | lib/Multi/API.pm | 18 |
2 files changed, 19 insertions, 5 deletions
diff --git a/data/docs/11 b/data/docs/11 index af0c718a..5e5962c7 100644 --- a/data/docs/11 +++ b/data/docs/11 @@ -42,8 +42,8 @@ <p>The following limits are enforced by the server, in order to limit the server resources and prevent abuse of this service.</p> <ul> - <li>5 connections per IP. All connections that are opened after reaching this limit will be immediately closed.</li> - <li>100 commands per 10 minutes per ip. Server will reply with a 'throttled' error (type="cmd") when reaching this limit.</li> + <li>10 connections per IP. All connections that are opened after reaching this limit will be immediately closed.</li> + <li>200 commands per 10 minutes per ip. Server will reply with a 'throttled' error (type="cmd") when reaching this limit.</li> <li> 1 second of SQL time per minute per ip. SQL time is the total time taken to run the database queries for each command. This depends on both the command @@ -1492,6 +1492,8 @@ however still required.<br /> </p> <b>2.25</b> <ul> + <li>Increased connection limit per IP from 5 to 10</li> + <li>Increased command limit from 100 to 200 commands per 10 minutes</li> <li>Added support for TLS</li> <li>Added "screens" flag and member to "get vn"</li> <li>Added "vns" flag and member to "get character"</li> diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm index 2b35d0d3..2b98b16e 100644 --- a/lib/Multi/API.pm +++ b/lib/Multi/API.pm @@ -8,6 +8,7 @@ package Multi::API; use strict; use warnings; use Multi::Core; +use Socket 'SO_KEEPALIVE', 'SOL_SOCKET', 'IPPROTO_TCP'; use AnyEvent::Socket; use AnyEvent::Handle; use POE::Filter::VNDBAPI 'encode_filters'; @@ -16,6 +17,10 @@ use Crypt::ScryptKDF 'scrypt_raw';; use VNDBUtil 'normalize_query', 'norm_ip'; use JSON::XS; +# Linux-specific, not exported by the Socket module. +sub TCP_KEEPIDLE () { 4 } +sub TCP_KEEPINTVL () { 5 } +sub TCP_KEEPCNT () { 6 } # what our JSON encoder considers 'true' or 'false' sub TRUE () { JSON::XS::true } @@ -25,11 +30,11 @@ my %O = ( port => 19534, tls_port => 19535, # Only used when tls_options is set logfile => "$VNDB::M{log_dir}/api.log", - conn_per_ip => 5, + conn_per_ip => 10, max_results => 25, # For get vn/release/producer/character max_results_lists => 100, # For get votelist/vnlist/wishlist default_results => 10, - throttle_cmd => [ 6, 100 ], # interval between each command, allowed burst + throttle_cmd => [ 3, 200 ], # interval between each command, allowed burst throttle_sql => [ 60, 1 ], # sql time multiplier, allowed burst (in sql time) throttle_thr => [ 2, 10 ], # interval between "throttled" replies, allowed burst tls_options => undef, # Set to AnyEvent::TLS options to enable TLS @@ -96,6 +101,13 @@ sub newconn { return; } + eval { + setsockopt($c->{fh}, SOL_SOCKET, SO_KEEPALIVE, 1); + setsockopt($c->{fh}, IPPROTO_TCP, TCP_KEEPIDLE, 120); + setsockopt($c->{fh}, IPPROTO_TCP, TCP_KEEPINTVL, 30); + setsockopt($c->{fh}, IPPROTO_TCP, TCP_KEEPCNT, 10); + }; + writelog $c, 'Connected'; $C{$connid} = $c; @@ -103,7 +115,7 @@ sub newconn { rbuf_max => 50*1024, # Commands aren't very huge, a 50k read buffer should suffice. wbuf_max => 5*1024*1024, fh => $c->{fh}, - keepalive=> 1, + keepalive=> 1, # Kinda redundant with setsockopt(), but w/e on_error => sub { writelog $c, 'IO error: %s', $_[2]; $c->{h}->destroy; |