R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype::ChatRate Class Reference

The chat rate of one session (RFC section 3.8): a token bucket. More...

#include </__w/project-rtype/project-rtype/server/include/rtype/rate_limit.hpp>

Public Types

using Clock = std::chrono::steady_clock
 Clock of the refills.
 

Public Member Functions

bool allow (Clock::time_point now) noexcept
 Counts a message and tells whether it may be relayed.
 

Static Public Attributes

static constexpr std::uint32_t burst = 5
 Messages a session may send at once.
 
static constexpr std::chrono::seconds refill {1}
 Time for one message to come back.
 

Detailed Description

The chat rate of one session (RFC section 3.8): a token bucket.

A session sends burst messages at once, then gets one more back every refill, up to burst kept. A message refused does not count. Not thread-safe.

Member Typedef Documentation

◆ Clock

using rtype::ChatRate::Clock = std::chrono::steady_clock

Clock of the refills.

Member Function Documentation

◆ allow()

bool rtype::ChatRate::allow ( Clock::time_point  now)
noexcept

Counts a message and tells whether it may be relayed.

Parameters
nowCurrent time, never earlier than the previous call's.
Returns
false if the session is over the rate: the message is a flood.

Member Data Documentation

◆ burst

constexpr std::uint32_t rtype::ChatRate::burst = 5
staticconstexpr

Messages a session may send at once.

◆ refill

constexpr std::chrono::seconds rtype::ChatRate::refill {1}
staticconstexpr

Time for one message to come back.


The documentation for this class was generated from the following file: