aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/connection.c70
-rw-r--r--src/or/connection_or.c4
-rw-r--r--src/or/main.c16
-rw-r--r--src/or/main.h4
-rw-r--r--src/or/or.h2
5 files changed, 49 insertions, 47 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 1aad68678e..20c758f57d 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -2880,12 +2880,12 @@ connection_bucket_read_limit(connection_t *conn, time_t now)
int base = RELAY_PAYLOAD_SIZE;
int priority = conn->type != CONN_TYPE_DIR;
ssize_t conn_bucket = -1;
- size_t global_bucket_val = token_bucket_get_read(&global_bucket);
+ size_t global_bucket_val = token_bucket_rw_get_read(&global_bucket);
if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
if (conn->state == OR_CONN_STATE_OPEN)
- conn_bucket = token_bucket_get_read(&or_conn->bucket);
+ conn_bucket = token_bucket_rw_get_read(&or_conn->bucket);
base = get_cell_network_size(or_conn->wide_circ_ids);
}
@@ -2895,7 +2895,7 @@ connection_bucket_read_limit(connection_t *conn, time_t now)
}
if (connection_counts_as_relayed_traffic(conn, now)) {
- size_t relayed = token_bucket_get_read(&global_relayed_bucket);
+ size_t relayed = token_bucket_rw_get_read(&global_relayed_bucket);
global_bucket_val = MIN(global_bucket_val, relayed);
}
@@ -2910,7 +2910,7 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
int base = RELAY_PAYLOAD_SIZE;
int priority = conn->type != CONN_TYPE_DIR;
size_t conn_bucket = conn->outbuf_flushlen;
- size_t global_bucket_val = token_bucket_get_write(&global_bucket);
+ size_t global_bucket_val = token_bucket_rw_get_write(&global_bucket);
if (!connection_is_rate_limited(conn)) {
/* be willing to write to local conns even if our buckets are empty */
@@ -2921,12 +2921,13 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
/* use the per-conn write limit if it's lower */
or_connection_t *or_conn = TO_OR_CONN(conn);
if (conn->state == OR_CONN_STATE_OPEN)
- conn_bucket = MIN(conn_bucket, token_bucket_get_write(&or_conn->bucket));
+ conn_bucket = MIN(conn_bucket,
+ token_bucket_rw_get_write(&or_conn->bucket));
base = get_cell_network_size(or_conn->wide_circ_ids);
}
if (connection_counts_as_relayed_traffic(conn, now)) {
- size_t relayed = token_bucket_get_write(&global_relayed_bucket);
+ size_t relayed = token_bucket_rw_get_write(&global_relayed_bucket);
global_bucket_val = MIN(global_bucket_val, relayed);
}
@@ -2956,8 +2957,9 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
int
global_write_bucket_low(connection_t *conn, size_t attempt, int priority)
{
- size_t smaller_bucket = MIN(token_bucket_get_write(&global_bucket),
- token_bucket_get_write(&global_relayed_bucket));
+ size_t smaller_bucket =
+ MIN(token_bucket_rw_get_write(&global_bucket),
+ token_bucket_rw_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 */
@@ -3041,12 +3043,12 @@ connection_buckets_decrement(connection_t *conn, time_t now,
return; /* local IPs are free */
if (connection_counts_as_relayed_traffic(conn, now)) {
- token_bucket_dec(&global_relayed_bucket, num_read, num_written);
+ token_bucket_rw_dec(&global_relayed_bucket, num_read, num_written);
}
- token_bucket_dec(&global_bucket, num_read, num_written);
+ token_bucket_rw_dec(&global_bucket, num_read, num_written);
if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
or_connection_t *or_conn = TO_OR_CONN(conn);
- token_bucket_dec(&or_conn->bucket, num_read, num_written);
+ token_bucket_rw_dec(&or_conn->bucket, num_read, num_written);
}
}
@@ -3060,14 +3062,14 @@ connection_consider_empty_read_buckets(connection_t *conn)
if (!connection_is_rate_limited(conn))
return; /* Always okay. */
- if (token_bucket_get_read(&global_bucket) <= 0) {
+ if (token_bucket_rw_get_read(&global_bucket) <= 0) {
reason = "global read bucket exhausted. Pausing.";
} else if (connection_counts_as_relayed_traffic(conn, approx_time()) &&
- token_bucket_get_read(&global_relayed_bucket) <= 0) {
+ token_bucket_rw_get_read(&global_relayed_bucket) <= 0) {
reason = "global relayed read bucket exhausted. Pausing.";
} else if (connection_speaks_cells(conn) &&
conn->state == OR_CONN_STATE_OPEN &&
- token_bucket_get_read(&TO_OR_CONN(conn)->bucket) <= 0) {
+ token_bucket_rw_get_read(&TO_OR_CONN(conn)->bucket) <= 0) {
reason = "connection read bucket exhausted. Pausing.";
} else
return; /* all good, no need to stop it */
@@ -3087,14 +3089,14 @@ connection_consider_empty_write_buckets(connection_t *conn)
if (!connection_is_rate_limited(conn))
return; /* Always okay. */
- if (token_bucket_get_write(&global_bucket) <= 0) {
+ if (token_bucket_rw_get_write(&global_bucket) <= 0) {
reason = "global write bucket exhausted. Pausing.";
} else if (connection_counts_as_relayed_traffic(conn, approx_time()) &&
- token_bucket_get_write(&global_relayed_bucket) <= 0) {
+ token_bucket_rw_get_write(&global_relayed_bucket) <= 0) {
reason = "global relayed write bucket exhausted. Pausing.";
} else if (connection_speaks_cells(conn) &&
conn->state == OR_CONN_STATE_OPEN &&
- token_bucket_get_write(&TO_OR_CONN(conn)->bucket) <= 0) {
+ token_bucket_rw_get_write(&TO_OR_CONN(conn)->bucket) <= 0) {
reason = "connection write bucket exhausted. Pausing.";
} else
return; /* all good, no need to stop it */
@@ -3111,17 +3113,17 @@ connection_bucket_init(void)
{
const or_options_t *options = get_options();
const uint32_t now_ts = monotime_coarse_get_stamp();
- token_bucket_init(&global_bucket,
+ token_bucket_rw_init(&global_bucket,
(int32_t)options->BandwidthRate,
(int32_t)options->BandwidthBurst,
now_ts);
if (options->RelayBandwidthRate) {
- token_bucket_init(&global_relayed_bucket,
+ token_bucket_rw_init(&global_relayed_bucket,
(int32_t)options->RelayBandwidthRate,
(int32_t)options->RelayBandwidthBurst,
now_ts);
} else {
- token_bucket_init(&global_relayed_bucket,
+ token_bucket_rw_init(&global_relayed_bucket,
(int32_t)options->BandwidthRate,
(int32_t)options->BandwidthBurst,
now_ts);
@@ -3132,15 +3134,15 @@ connection_bucket_init(void)
void
connection_bucket_adjust(const or_options_t *options)
{
- token_bucket_adjust(&global_bucket,
+ token_bucket_rw_adjust(&global_bucket,
(int32_t)options->BandwidthRate,
(int32_t)options->BandwidthBurst);
if (options->RelayBandwidthRate) {
- token_bucket_adjust(&global_relayed_bucket,
+ token_bucket_rw_adjust(&global_relayed_bucket,
(int32_t)options->RelayBandwidthRate,
(int32_t)options->RelayBandwidthBurst);
} else {
- token_bucket_adjust(&global_relayed_bucket,
+ token_bucket_rw_adjust(&global_relayed_bucket,
(int32_t)options->BandwidthRate,
(int32_t)options->BandwidthBurst);
}
@@ -3153,12 +3155,12 @@ connection_bucket_refill(time_t now, uint32_t now_ts)
smartlist_t *conns = get_connection_array();
write_buckets_empty_last_second =
- token_bucket_get_write(&global_bucket) <= 0 ||
- token_bucket_get_write(&global_relayed_bucket) <= 0;
+ token_bucket_rw_get_write(&global_bucket) <= 0 ||
+ token_bucket_rw_get_write(&global_relayed_bucket) <= 0;
/* refill the global buckets */
- token_bucket_refill(&global_bucket, now_ts);
- token_bucket_refill(&global_relayed_bucket, now_ts);
+ token_bucket_rw_refill(&global_bucket, now_ts);
+ token_bucket_rw_refill(&global_relayed_bucket, now_ts);
/* refill the per-connection buckets */
SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
@@ -3166,17 +3168,17 @@ connection_bucket_refill(time_t now, uint32_t now_ts)
or_connection_t *or_conn = TO_OR_CONN(conn);
if (conn->state == OR_CONN_STATE_OPEN) {
- token_bucket_refill(&or_conn->bucket, now_ts);
+ token_bucket_rw_refill(&or_conn->bucket, now_ts);
}
}
if (conn->read_blocked_on_bw == 1 /* marked to turn reading back on now */
- && token_bucket_get_read(&global_bucket) > 0 /* and we can read */
+ && token_bucket_rw_get_read(&global_bucket) > 0 /* and we can read */
&& (!connection_counts_as_relayed_traffic(conn, now) ||
- token_bucket_get_read(&global_relayed_bucket) > 0)
+ token_bucket_rw_get_read(&global_relayed_bucket) > 0)
&& (!connection_speaks_cells(conn) ||
conn->state != OR_CONN_STATE_OPEN ||
- token_bucket_get_read(&TO_OR_CONN(conn)->bucket) > 0)) {
+ token_bucket_rw_get_read(&TO_OR_CONN(conn)->bucket) > 0)) {
/* and either a non-cell conn or a cell conn with non-empty bucket */
LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET,
"waking up conn (fd %d) for read", (int)conn->s));
@@ -3185,12 +3187,12 @@ connection_bucket_refill(time_t now, uint32_t now_ts)
}
if (conn->write_blocked_on_bw == 1
- && token_bucket_get_write(&global_bucket) > 0 /* and we can write */
+ && token_bucket_rw_get_write(&global_bucket) > 0 /* and we can write */
&& (!connection_counts_as_relayed_traffic(conn, now) ||
- token_bucket_get_write(&global_relayed_bucket) > 0)
+ token_bucket_rw_get_write(&global_relayed_bucket) > 0)
&& (!connection_speaks_cells(conn) ||
conn->state != OR_CONN_STATE_OPEN ||
- token_bucket_get_write(&TO_OR_CONN(conn)->bucket) > 0)) {
+ token_bucket_rw_get_write(&TO_OR_CONN(conn)->bucket) > 0)) {
LOG_FN_CONN(conn, (LOG_DEBUG,LD_NET,
"waking up conn (fd %d) for write", (int)conn->s));
conn->write_blocked_on_bw = 0;
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 3afdfa6b5a..7723d9d2bd 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -793,9 +793,9 @@ connection_or_update_token_buckets_helper(or_connection_t *conn, int reset,
(int)options->BandwidthBurst, 1, INT32_MAX);
}
- token_bucket_adjust(&conn->bucket, rate, burst);
+ token_bucket_rw_adjust(&conn->bucket, rate, burst);
if (reset) {
- token_bucket_reset(&conn->bucket, monotime_coarse_get_stamp());
+ token_bucket_rw_reset(&conn->bucket, monotime_coarse_get_stamp());
}
}
diff --git a/src/or/main.c b/src/or/main.c
index 0e67ea6f68..2ad915c5f8 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -154,10 +154,10 @@ static void shutdown_did_not_work_callback(evutil_socket_t fd, short event,
/********* START VARIABLES **********/
/* Token bucket for all traffic. */
-token_bucket_t global_bucket;
+token_bucket_rw_t global_bucket;
/* Token bucket for relayed traffic. */
-token_bucket_t global_relayed_bucket;
+token_bucket_rw_t global_relayed_bucket;
/** What was the read/write bucket before the last second_elapsed_callback()
* call? (used to determine how many bytes we've read). */
@@ -2390,9 +2390,9 @@ refill_callback(periodic_timer_t *timer, void *arg)
}
bytes_written = stats_prev_global_write_bucket -
- token_bucket_get_write(&global_bucket);
+ token_bucket_rw_get_write(&global_bucket);
bytes_read = stats_prev_global_read_bucket -
- token_bucket_get_read(&global_bucket);
+ token_bucket_rw_get_read(&global_bucket);
stats_n_bytes_read += bytes_read;
stats_n_bytes_written += bytes_written;
@@ -2404,8 +2404,8 @@ refill_callback(periodic_timer_t *timer, void *arg)
monotime_coarse_get_stamp());
}
- stats_prev_global_read_bucket = token_bucket_get_read(&global_bucket);
- stats_prev_global_write_bucket = token_bucket_get_write(&global_bucket);
+ stats_prev_global_read_bucket = token_bucket_rw_get_read(&global_bucket);
+ stats_prev_global_write_bucket = token_bucket_rw_get_write(&global_bucket);
/* remember what time it is, for next time */
refill_timer_current_millisecond = now;
@@ -2609,8 +2609,8 @@ do_main_loop(void)
/* Set up our buckets */
connection_bucket_init();
- stats_prev_global_read_bucket = token_bucket_get_read(&global_bucket);
- stats_prev_global_write_bucket = token_bucket_get_write(&global_bucket);
+ stats_prev_global_read_bucket = token_bucket_rw_get_read(&global_bucket);
+ stats_prev_global_write_bucket = token_bucket_rw_get_write(&global_bucket);
/* initialize the bootstrap status events to know we're starting up */
control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0);
diff --git a/src/or/main.h b/src/or/main.h
index 9ef5b9472f..6b9ac1b583 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -89,8 +89,8 @@ uint64_t get_main_loop_idle_count(void);
extern time_t time_of_process_start;
extern int quiet_level;
-extern token_bucket_t global_bucket;
-extern token_bucket_t global_relayed_bucket;
+extern token_bucket_rw_t global_bucket;
+extern token_bucket_rw_t global_relayed_bucket;
#ifdef MAIN_PRIVATE
STATIC void init_connection_lists(void);
diff --git a/src/or/or.h b/src/or/or.h
index 829b6755d2..c0e1ffff48 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1661,7 +1661,7 @@ typedef struct or_connection_t {
time_t timestamp_lastempty; /**< When was the outbuf last completely empty?*/
- token_bucket_t bucket; /**< Used for rate limiting when the connection is
+ token_bucket_rw_t bucket; /**< Used for rate limiting when the connection is
* in state CONN_OPEN. */
/*