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.
25 26 27 28 29 |
# File 'lib/ftpd/connection_throttle.rb', line 25 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.
15 16 17 |
# File 'lib/ftpd/connection_throttle.rb', line 15 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.
21 22 23 |
# File 'lib/ftpd/connection_throttle.rb', line 21 def max_connections_per_ip @max_connections_per_ip end |
Instance Method Details
#allow?(socket) ⇒ Boolean
Returns true if the connection should be allowed.
33 34 35 36 |
# File 'lib/ftpd/connection_throttle.rb', line 33 def allow?(socket) allow_by_total_count && allow_by_ip_count(socket) end |
#deny(socket) ⇒ Object
Reject a connection
40 41 42 |
# File 'lib/ftpd/connection_throttle.rb', line 40 def deny(socket) socket.write "421 Too many connections\r\n" end |