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:



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_connectionsInteger

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

Returns:

  • (Integer)


15
16
17
# File 'lib/ftpd/connection_throttle.rb', line 15

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)


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.

Returns:

  • (Boolean)

    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