irc-core-2.13: IRC core library for glirc

Copyright | (c) Eric Mertens 2016
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | Safe-Inferred
Language | Haskell2010

Irc.RateLimit

Description

This module implements a simple rate limiter based on the IRC RFC to be used to keep an IRC client from getting disconnected for flooding. It allows one event per duration with a given threshold.

This algorithm keeps track of the time at which the client may start sending messages. Each message sent advances that time into the future by the `penalty`. The client is allowed to transmit up to `threshold` seconds ahead of this time.

Synopsis

- data RateLimit
- newRateLimit :: Rational -> Rational -> IO RateLimit
- tickRateLimit :: RateLimit -> IO ()

# Documentation

data RateLimit Source #

The `RateLimit` keeps track of rate limit settings as well as the current state of the limit.

newRateLimit Source #

Arguments

:: Rational | penalty seconds
-> Rational | threshold seconds
-> IO RateLimit |

Construct a new rate limit with the given penalty and threshold.

tickRateLimit :: RateLimit -> IO () Source #

Account for an event in the context of a `RateLimit`. This command will block and delay as required to satisfy the current rate. Once it returns it is safe to proceed with the rate limited action.