{
int base = RELAY_PAYLOAD_SIZE;
int priority = conn->type != CONN_TYPE_DIR;
- int conn_bucket = -1;
- int global_bucket_val = (int) token_bucket_get_read(&global_bucket);
+ ssize_t conn_bucket = -1;
+ size_t global_bucket_val = token_bucket_get_read(&global_bucket);
if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
}
if (connection_counts_as_relayed_traffic(conn, now)) {
- int relayed = token_bucket_get_read(&global_relayed_bucket);
+ size_t relayed = token_bucket_get_read(&global_relayed_bucket);
global_bucket_val = MIN(global_bucket_val, relayed);
}
{
int base = RELAY_PAYLOAD_SIZE;
int priority = conn->type != CONN_TYPE_DIR;
- int conn_bucket = (int)conn->outbuf_flushlen;
- int global_bucket_val = (int) token_bucket_get_write(&global_bucket);
+ size_t conn_bucket = conn->outbuf_flushlen;
+ size_t global_bucket_val = token_bucket_get_write(&global_bucket);
if (!connection_is_rate_limited(conn)) {
/* be willing to write to local conns even if our buckets are empty */
}
if (connection_counts_as_relayed_traffic(conn, now)) {
- int relayed = token_bucket_get_write(&global_relayed_bucket);
+ size_t relayed = token_bucket_get_write(&global_relayed_bucket);
global_bucket_val = MIN(global_bucket_val, relayed);
}
int
global_write_bucket_low(connection_t *conn, size_t attempt, int priority)
{
- int smaller_bucket = MIN(token_bucket_get_write(&global_bucket),
- token_bucket_get_write(&global_relayed_bucket));
+ size_t smaller_bucket = MIN(token_bucket_get_write(&global_bucket),
+ token_bucket_get_write(&global_relayed_bucket));
if (authdir_mode(get_options()) && priority>1)
return 0; /* there's always room to answer v2 if we're an auth dir */
if (!connection_is_rate_limited(conn))
return 0; /* local conns don't get limited */
- if (smaller_bucket < (int)attempt)
+ if (smaller_bucket < attempt)
return 1; /* not enough space no matter the priority */
if (write_buckets_empty_last_second)
if (priority == 1) { /* old-style v1 query */
/* Could we handle *two* of these requests within the next two seconds? */
const or_options_t *options = get_options();
- int64_t can_write = (int64_t)smaller_bucket
+ size_t can_write = smaller_bucket
+ 2*(options->RelayBandwidthRate ? options->RelayBandwidthRate :
options->BandwidthRate);
- if (can_write < 2*(int64_t)attempt)
+ if (can_write < 2*attempt)
return 1;
} else { /* v2 query */
/* no further constraints yet */
/** What was the read/write bucket before the last second_elapsed_callback()
* call? (used to determine how many bytes we've read). */
-static int stats_prev_global_read_bucket;
+static size_t stats_prev_global_read_bucket;
/** What was the write bucket before the last second_elapsed_callback() call?
* (used to determine how many bytes we've written). */
-static int stats_prev_global_write_bucket;
+static size_t stats_prev_global_write_bucket;
/* DOCDOC stats_prev_n_read */
static uint64_t stats_prev_n_read = 0;