class Circed::Services::RateLimiter

Overview

Rate limiter for IRC commands to prevent flooding

Defined in:

circed/services/rate_limiter.cr

Constant Summary

COMMAND_LIMITS = {"PRIVMSG" => {max_commands: 5, time_window: 10}, "NOTICE" => {max_commands: 5, time_window: 10}, "JOIN" => {max_commands: 3, time_window: 10}, "PART" => {max_commands: 3, time_window: 10}, "NICK" => {max_commands: 2, time_window: 30}, "WHOIS" => {max_commands: 3, time_window: 10}, "WHO" => {max_commands: 2, time_window: 10}, "NAMES" => {max_commands: 2, time_window: 10}, "LIST" => {max_commands: 1, time_window: 30}, "TOPIC" => {max_commands: 2, time_window: 10}, "MODE" => {max_commands: 3, time_window: 10}, "KICK" => {max_commands: 2, time_window: 10}, "INVITE" => {max_commands: 2, time_window: 10}}

Different rate limits for different command types

DEFAULT_BURST_SIZE = 5
DEFAULT_MAX_COMMANDS = 10

Per-client rate limiting configuration

DEFAULT_TIME_WINDOW = 60

Class Method Summary

Class Method Detail

def self.check_rate_limit(client_id : String, command : String) : Bool #

[View source]
def self.cleanup_old_entries : Void #

[View source]
def self.clear_client_history(client_id : String) : Void #

[View source]
def self.get_client_stats(client_id : String) : Hash(String, Int32) #

[View source]
def self.get_remaining_quota(client_id : String, command : String) : Int32 #

[View source]
def self.get_reset_time(client_id : String, command : String) : Time | Nil #

[View source]
def self.global_stats : Hash(String, Int32) #

[View source]
def self.rate_limited?(client_id : String, command : String) : Bool #

[View source]
def self.registration_command?(command : String) : Bool #

Special handling for burst commands during registration


[View source]
def self.should_rate_limit?(command : String) : Bool #

[View source]