log(LOG_WARN,"BandwidthBurst must be more than twice BandwidthRate.");
result = -1;
}
+ if (options->BandwidthRate > INT_MAX) {
+ log(LOG_WARN,"BandwidthRate must be less than %d",INT_MAX);
+ result = -1;
+ }
+ if (options->BandwidthBurst > INT_MAX) {
+ log(LOG_WARN,"BandwidthBurst must be less than %d",INT_MAX);
+ result = -1;
+ }
if (options->_MonthlyAccountingStart) {
if (options->AccountingStart) {
*ok = 0;
return -1;
}
- return r;
+ return (int)r;
}
/*
* and current_time to the current time. */
void connection_bucket_init(void) {
or_options_t *options = get_options();
- global_read_bucket = options->BandwidthBurst; /* start it at max traffic */
- global_write_bucket = options->BandwidthBurst; /* start it at max traffic */
+ global_read_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
+ global_write_bucket = (int)options->BandwidthBurst; /* start it at max traffic */
}
/** A second has rolled over; increment buckets appropriately. */
/* refill the global buckets */
if(global_read_bucket < options->BandwidthBurst) {
- global_read_bucket += options->BandwidthRate;
+ global_read_bucket += (int)options->BandwidthRate;
log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
}
if(global_write_bucket < options->BandwidthBurst) {
- global_write_bucket += options->BandwidthRate;
+ global_write_bucket += (int)options->BandwidthRate;
log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket);
}
conn->addr = addr;
conn->port = port;
/* This next part isn't really right, but it's good enough for now. */
- conn->receiver_bucket = conn->bandwidth = options->BandwidthBurst;
+ conn->receiver_bucket = conn->bandwidth = (int)options->BandwidthBurst;
memcpy(conn->identity_digest, id_digest, DIGEST_LEN);
/* If we're an authoritative directory server, we may know a
* nickname for this router. */
static void
update_expected_bandwidth(void)
{
- uint64_t used;
- uint32_t max_configured = (get_options()->BandwidthRate * 60);
+ uint64_t used, expected;
+ uint64_t max_configured = (get_options()->BandwidthRate * 60);
if (n_seconds_active_in_interval < 1800) {
/* If we haven't gotten enough data last interval, guess that
* up until we send Max bytes. Next interval, we'll choose
* our starting time based on how much we sent this interval.
*/
- expected_bandwidth_usage = max_configured;
+ expected = max_configured;
} else {
used = n_bytes_written_in_interval < n_bytes_read_in_interval ?
n_bytes_read_in_interval : n_bytes_written_in_interval;
- expected_bandwidth_usage = (uint32_t)
- (used / (n_seconds_active_in_interval / 60));
- if (expected_bandwidth_usage > max_configured)
- expected_bandwidth_usage = max_configured;
+ expected = (used / (n_seconds_active_in_interval / 60));
+ if (expected > max_configured)
+ expected = max_configured;
}
+ if (expected > UINT32_MAX)
+ expected = UINT32_MAX;
+ expected_bandwidth_usage = (uint32_t) expected;
}
/** Called at the start of a new accounting interval: reset our
crypto_free_digest_env(d_env);
if (expected_bandwidth_usage)
- time_to_exhaust_bw =
+ time_to_exhaust_bw = (int)
(get_options()->AccountingMax/expected_bandwidth_usage)*60;
else
time_to_exhaust_bw = 24*60*60;
}
get_platform_str(platform, sizeof(platform));
ri->platform = tor_strdup(platform);
- ri->bandwidthrate = options->BandwidthRate;
- ri->bandwidthburst = options->BandwidthBurst;
+ ri->bandwidthrate = (int)options->BandwidthRate;
+ ri->bandwidthburst = (int)options->BandwidthBurst;
ri->bandwidthcapacity = router_get_bandwidth_capacity();
router_add_exit_policy_from_config(ri);
if(desc_routerinfo) /* inherit values */