proxy.common.leakage module#

proxy.py#

⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.

copyright
  1. 2013-present by Abhinav Singh and contributors.

license

BSD, see LICENSE for more details.

class proxy.common.leakage.Leakage(rate: int)[source]#

Bases: object

Leaky Bucket algorithm.

_refill() None[source]#

Refill tokens based on the elapsed time since the last check.

consume(amount: int) int[source]#

Attempt to consume the amount from the bucket.

Returns the amount allowed to be sent, up to the available tokens (rate).

release(tokens: int) None[source]#

When you are unable to consume amount units of token, release them into the bucket.

E.g. say you wanted to read 1024 units, but only 24 units were read, then put back unconsumed 1000 tokens back in the bucket.