diff --git a/src/or/config.c b/src/or/config.c index b6c3541aae..8c578813a2 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -1310,6 +1310,14 @@ options_validate(or_options_t *options) 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) { @@ -2325,7 +2333,7 @@ config_parse_interval(const char *s, int *ok) { *ok = 0; return -1; } - return r; + return (int)r; } /* diff --git a/src/or/connection.c b/src/or/connection.c index daf51a0c5f..7035b8dc0a 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -723,8 +723,8 @@ static void connection_consider_empty_buckets(connection_t *conn) { * 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. */ @@ -736,11 +736,11 @@ void connection_bucket_refill(struct timeval *now) { /* 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); } diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 73b635d593..c9d3bc8b46 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -136,7 +136,7 @@ connection_or_init_conn_from_address(connection_t *conn, 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. */ diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 8f2183f1c7..394bf4ff0d 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -336,8 +336,8 @@ configure_accounting(time_t now) 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 @@ -346,15 +346,17 @@ update_expected_bandwidth(void) * 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 @@ -440,7 +442,7 @@ accounting_set_wakeup_time(void) 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; diff --git a/src/or/router.c b/src/or/router.c index 286ba46779..9690860954 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -561,8 +561,8 @@ int router_rebuild_descriptor(int force) { } 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 */