Class: Ftpd::ConnectionThrottle

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(connection_tracker) ⇒ ConnectionThrottle

Returns a new instance of ConnectionThrottle.

Parameters:



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_connectionsInteger

The maximum number of connections, or nil if there is no limit.

Returns:

  • (Integer)


13
14
15
# File 'lib/ftpd/connection_throttle.rb', line 13

def max_connections
  @max_connections
end

#max_connections_per_ipInteger

The maximum number of connections for an IP, or nil if there is no limit.

Returns:

  • (Integer)


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.

Returns:

  • (Boolean)

    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