Remove ticket_cost member as it is no longer needed
This commit is contained in:
+9
-11
@@ -5,21 +5,19 @@ void uc_ratelimit_init(struct RateLimit *r, long tickets, long period, long curr
|
||||
{
|
||||
r->tickets = tickets;
|
||||
|
||||
r->ticket_cost = period;
|
||||
|
||||
r->period = period;
|
||||
r->funds = r->ticket_cost * tickets;
|
||||
r->funds = r->period * tickets;
|
||||
r->last_ts = current_ts;
|
||||
|
||||
assert(tickets > 0);
|
||||
assert(period > 0);
|
||||
assert(r->ticket_cost > 0);
|
||||
assert(r->period > 0);
|
||||
assert(r->funds > 0);
|
||||
}
|
||||
|
||||
void uc_ratelimit_reset(struct RateLimit *r, long current_ts)
|
||||
{
|
||||
r->funds = r->ticket_cost * r->tickets;
|
||||
r->funds = r->period * r->tickets;
|
||||
|
||||
if (current_ts) {
|
||||
r->last_ts = current_ts;
|
||||
@@ -46,20 +44,20 @@ int uc_ratelimit_allow(struct RateLimit *r, long current_ts)
|
||||
//the last time.
|
||||
r->funds += diff_period * r->tickets;
|
||||
|
||||
//the below is the real algorithm, with ticket_cost =
|
||||
//the below is the real algorithm, with period =
|
||||
//tickets * period.
|
||||
//we have optimized this to the expression used above
|
||||
//r->funds += diff_period *
|
||||
// ((r->tickets * r->ticket_cost) / r->period);
|
||||
// ((r->tickets * r->period) / r->period);
|
||||
|
||||
//throttle handing out tickets
|
||||
if (r->funds > r->ticket_cost * r->tickets) {
|
||||
r->funds = r->ticket_cost * r->tickets;
|
||||
if (r->funds > r->period * r->tickets) {
|
||||
r->funds = r->period * r->tickets;
|
||||
}
|
||||
|
||||
//If we have enough to buy atleast one ticket, we can allow
|
||||
if (r->funds >= r->ticket_cost) {
|
||||
r->funds -= r->ticket_cost;
|
||||
if (r->funds >= r->period) {
|
||||
r->funds -= r->period;
|
||||
allowed = 1;
|
||||
} else {
|
||||
//not enough to buy a ticket
|
||||
|
||||
Reference in New Issue
Block a user