Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
Haio::Cdn::Detail::ClientQuota Class Reference

#include <cache.hpp>

Public Member Functions

 ClientQuota (size_t perWindow, std::chrono::seconds window)
bool mayStore (const std::string &client)

Detailed Description

how many entries one address may create per window.

the limit is on creating, never on reading: what it answers is one caller filling the cache with keys nobody else wants and evicting everyone else on the way.

Definition at line 44 of file cache.hpp.

Constructor & Destructor Documentation

◆ ClientQuota()

Haio::Cdn::Detail::ClientQuota::ClientQuota ( size_t perWindow,
std::chrono::seconds window )

Definition at line 7 of file quota.cpp.

Member Function Documentation

◆ mayStore()

bool Haio::Cdn::Detail::ClientQuota::mayStore ( const std::string & client)

the quota counts entries created, not requests served, and it refills every window. going over does not fail anything: the answer is produced and returned, it is only not stored, so an address that asks for ten thousand different sizes pays for them itself instead of evicting everybody else.

the table is keyed by address, so a caller with many addresses grows it. expired rows are dropped on the way past, and if it still runs away the whole table is cleared: everyone gets a fresh quota, which is far better than an allocation nobody bounds.

Todo
a fixed size counting sketch would hold the limit without the table, and without handing an attacker a reset by flooding it.

Definition at line 16 of file quota.cpp.


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