mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
mainloop: Remove unused parameter from connection_dir_is_global_write_low()
Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
@@ -3189,9 +3189,6 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
|
||||
/** Return true iff the global write buckets are low enough that we
|
||||
* shouldn't send <b>attempt</b> bytes of low-priority directory stuff
|
||||
* out to <b>conn</b>.
|
||||
|
||||
* Priority was 1 for v1 requests (directories and running-routers),
|
||||
* and 2 for v2 requests and later (statuses and descriptors).
|
||||
*
|
||||
* There are a lot of parameters we could use here:
|
||||
* - global_relayed_write_bucket. Low is bad.
|
||||
@@ -3206,38 +3203,25 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
|
||||
* that's harder to quantify and harder to keep track of.
|
||||
*/
|
||||
int
|
||||
connection_dir_is_global_write_low(connection_t *conn, size_t attempt,
|
||||
int priority)
|
||||
connection_dir_is_global_write_low(connection_t *conn, size_t attempt)
|
||||
{
|
||||
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)
|
||||
if (authdir_mode(get_options()))
|
||||
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 < attempt)
|
||||
return 1; /* not enough space no matter the priority */
|
||||
return 1; /* not enough space. */
|
||||
|
||||
{
|
||||
const time_t diff = approx_time() - write_buckets_last_empty_at;
|
||||
if (diff <= 1)
|
||||
return 1; /* we're already hitting our limits, no more please */
|
||||
}
|
||||
|
||||
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();
|
||||
size_t can_write = (size_t) (smaller_bucket
|
||||
+ 2*(options->RelayBandwidthRate ? options->RelayBandwidthRate :
|
||||
options->BandwidthRate));
|
||||
if (can_write < 2*attempt)
|
||||
return 1;
|
||||
} else { /* v2 query */
|
||||
/* no further constraints yet */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ void connection_mark_all_noncontrol_connections(void);
|
||||
|
||||
ssize_t connection_bucket_write_limit(struct connection_t *conn, time_t now);
|
||||
int connection_dir_is_global_write_low(struct connection_t *conn,
|
||||
size_t attempt, int priority);
|
||||
size_t attempt);
|
||||
void connection_bucket_init(void);
|
||||
void connection_bucket_adjust(const or_options_t *options);
|
||||
void connection_bucket_refill_all(time_t now,
|
||||
|
||||
@@ -951,7 +951,7 @@ handle_get_current_consensus(dir_connection_t *conn,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess)) {
|
||||
log_debug(LD_DIRSERV,
|
||||
"Client asked for network status lists, but we've been "
|
||||
"writing too many bytes lately. Sending 503 Dir busy.");
|
||||
@@ -1060,7 +1060,7 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
|
||||
}
|
||||
});
|
||||
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), estimated_len, 2)) {
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), estimated_len)) {
|
||||
write_short_http_response(conn, 503, "Directory busy, try again later");
|
||||
goto vote_done;
|
||||
}
|
||||
@@ -1119,7 +1119,7 @@ handle_get_microdesc(dir_connection_t *conn, const get_handler_args_t *args)
|
||||
write_short_http_response(conn, 404, "Not found");
|
||||
goto done;
|
||||
}
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess)) {
|
||||
log_info(LD_DIRSERV,
|
||||
"Client asked for server descriptors, but we've been "
|
||||
"writing too many bytes lately. Sending 503 Dir busy.");
|
||||
@@ -1217,7 +1217,7 @@ handle_get_descriptor(dir_connection_t *conn, const get_handler_args_t *args)
|
||||
msg = "Not found";
|
||||
write_short_http_response(conn, 404, msg);
|
||||
} else {
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess)) {
|
||||
log_info(LD_DIRSERV,
|
||||
"Client asked for server descriptors, but we've been "
|
||||
"writing too many bytes lately. Sending 503 Dir busy.");
|
||||
@@ -1314,8 +1314,7 @@ handle_get_keys(dir_connection_t *conn, const get_handler_args_t *args)
|
||||
len += c->cache_info.signed_descriptor_len);
|
||||
|
||||
if (connection_dir_is_global_write_low(TO_CONN(conn),
|
||||
compress_method != NO_METHOD ? len/2 : len,
|
||||
2)) {
|
||||
compress_method != NO_METHOD ? len/2 : len)) {
|
||||
write_short_http_response(conn, 503, "Directory busy, try again later");
|
||||
goto keys_done;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user