Class: Ftpd::ConnectionThrottle
- Inherits:
-
Object
- Object
- Ftpd::ConnectionThrottle
- Defined in:
- lib/ftpd/connection_throttle.rb
Overview
This class limits the number of connections
Constant Summary collapse
- DEFAULT_MAX_CONNECTIONS =
nil
- DEFAULT_MAX_CONNECTIONS_PER_IP =
nil
Instance Attribute Summary collapse
-
#max_connections ⇒ Integer
The maximum number of connections, or nil if there is no limit.
-
#max_connections_per_ip ⇒ Integer
The maximum number of connections for an IP, or nil if there is no limit.
Instance Method Summary collapse
-
#allow?(socket) ⇒ Boolean
True if the connection should be allowed.
-
#deny(socket) ⇒ Object
Reject a connection.
-
#initialize(connection_tracker) ⇒ ConnectionThrottle
constructor
A new instance of ConnectionThrottle.
Constructor Details
#initialize(connection_tracker) ⇒ ConnectionThrottle
Returns a new instance of ConnectionThrottle.
23 24 25 26 27 |
# File 'lib/ftpd/connection_throttle.rb', line 23 def initialize(connection_tracker) @max_connections = DEFAULT_MAX_CONNECTIONS @max_connections_per_ip = DEFAULT_MAX_CONNECTIONS_PER_IP @connection_tracker = connection_tracker end |
Instance Attribute Details
#max_connections ⇒ Integer
The maximum number of connections, or nil if there is no limit.
13 14 15 |
# File 'lib/ftpd/connection_throttle.rb', line 13 def max_connections @max_connections end |
#max_connections_per_ip ⇒ Integer
The maximum number of connections for an IP, or nil if there is no limit.
19 20 21 |
# File 'lib/ftpd/connection_throttle.rb', line 19 def max_connections_per_ip @max_connections_per_ip end |
Instance Method Details
#allow?(socket) ⇒ Boolean
Returns true if the connection should be allowed.
31 32 33 34 |
# File 'lib/ftpd/connection_throttle.rb', line 31 def allow?(socket) allow_by_total_count && allow_by_ip_count(socket) end |
#deny(socket) ⇒ Object
Reject a connection
38 39 40 |
# File 'lib/ftpd/connection_throttle.rb', line 38 def deny(socket) socket.write "421 Too many connections\r\n" end |