mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
token: Fix uint32_t to uint64_t conversion
Unfortunately, the units passed to monotime_coarse_stamp_units_to_approx_msec() was always 0 due to a type conversion. Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
@@ -108,7 +108,7 @@ token_bucket_raw_dec(token_bucket_raw_t *bucket,
|
||||
}
|
||||
|
||||
/** Convert a rate in bytes per second to a rate in bytes per step */
|
||||
static uint32_t
|
||||
STATIC uint32_t
|
||||
rate_per_sec_to_rate_per_step(uint32_t rate)
|
||||
{
|
||||
/*
|
||||
@@ -117,8 +117,9 @@ rate_per_sec_to_rate_per_step(uint32_t rate)
|
||||
(rate / 1000) * to_approximate_msec(TICKS_PER_STEP). But to minimize
|
||||
rounding error, we do it this way instead, and divide last.
|
||||
*/
|
||||
uint64_t units = (uint64_t) rate * TICKS_PER_STEP;
|
||||
uint32_t val = (uint32_t)
|
||||
monotime_coarse_stamp_units_to_approx_msec(rate*TICKS_PER_STEP)/1000;
|
||||
monotime_coarse_stamp_units_to_approx_msec(units) / 1000;
|
||||
return val ? val : 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define TOR_TOKEN_BUCKET_H
|
||||
|
||||
#include "torint.h"
|
||||
#include "testsupport.h"
|
||||
|
||||
/** Largest allowable burst value for a token buffer. */
|
||||
#define TOKEN_BUCKET_MAX_BURST INT32_MAX
|
||||
@@ -109,6 +110,8 @@ token_bucket_rw_get_write(const token_bucket_rw_t *bucket)
|
||||
* a power of two if you can. */
|
||||
#define TICKS_PER_STEP 16
|
||||
|
||||
STATIC uint32_t rate_per_sec_to_rate_per_step(uint32_t rate);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* TOR_TOKEN_BUCKET_H */
|
||||
|
||||
Reference in New Issue
Block a user