summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-04-13 10:51:59 -0400
committerNick Mathewson <nickm@torproject.org>2018-04-13 10:54:26 -0400
commit03b96882deb60cd21c3c77746f4f9cd4aac0a724 (patch)
treedc9f65dc453aa4d0eb468e74880fded889f4bd8e /src/or/connection.c
parentb152d62cee7480ee7b9b68dd9b619db65b6cd112 (diff)
downloadtor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.tar.gz
tor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.zip
Rename token_bucket_t to token_bucket_rw_t.
This is a simple search-and-replace to rename the token bucket type to indicate that it contains both a read and a write bucket, bundled with their configuration. It's preliminary to refactoring the bucket type.
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c70
1 files changed, 36 insertions, 34 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;