Echo server with throttling implemented using token bucket algorithm. Simplified adaptation of the boost asio example.
The algorithm is the following:
-
define a bucket of current capacity
b
and of max capacityB
-
every
1/t
seconds 1 token added to the bucket -
when packet of size
n
bytes arrives:3.1 if
b >= n
=>b := b - n
and process packet3.2 else packet is non-conformant
There are 2 different strategies to handle non-conformant packets: drop them or delay (so-called traffic shaping).