summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-11-11 13:34:05 -0500
committerNick Mathewson <nickm@torproject.org>2015-12-18 13:14:10 -0500
commit0c8e042c30946faa564f03251bb3663e6204df9a (patch)
tree9a19d65c5e9500cd9c3429aa5b5f5af9d433e956
parent54406f78b84103ed7fd4610a89dda9d37f0f033e (diff)
downloadtor-0c8e042c30946faa564f03251bb3663e6204df9a.tar.gz
tor-0c8e042c30946faa564f03251bb3663e6204df9a.zip
Restore semantics of advertise vs serve on directory cacheing
When we are low on accounted bandwidth, we stop advertising that we're a directory, but we will continue to answer directory requests, just as before.
-rw-r--r--src/or/router.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 5c680ce875..c1d970dbe1 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1099,11 +1099,26 @@ check_whether_dirport_reachable(void)
can_reach_dir_port;
}
-/** The lower threshold of remaining bandwidth required to advertise directory
- * services */
+/** The lower threshold of remaining bandwidth required to advertise (or
+ * automatically provide) directory services */
/* XXX Should this be increased? */
#define MIN_BW_TO_ADVERTISE_DIRSERVER 51200
+/** Return true iff we have enough configured bandwidth to cache directory
+ * information. */
+static int
+router_has_bandwidth_to_be_dirserver(const or_options_t *options)
+{
+ if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
+ return 0;
+ }
+ if (options->RelayBandwidthRate > 0 &&
+ options->RelayBandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
+ return 0;
+ }
+ return 1;
+}
+
/** Helper: Return 1 if we have sufficient resources for serving directory
* requests, return 0 otherwise.
* dir_port is either 0 or the configured DirPort number.
@@ -1144,9 +1159,7 @@ router_should_be_directory_server(const or_options_t *options, int dir_port)
new_choice = 0;
reason = "AccountingMax enabled";
}
- } else if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER ||
- (options->RelayBandwidthRate > 0 &&
- options->RelayBandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER)) {
+ } else if (! router_has_bandwidth_to_be_dirserver(options)) {
/* if we're advertising a small amount */
new_choice = 0;
reason = "BandwidthRate under 50KB";
@@ -1178,8 +1191,8 @@ dir_server_mode(const or_options_t *options)
{
if (!options->DirCache)
return 0;
- return (server_mode(options) || options->DirPort_set) &&
- router_should_be_directory_server(options, 0);
+ return options->DirPort_set ||
+ (server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
}
/** Look at a variety of factors, and return 0 if we don't want to
@@ -1899,7 +1912,8 @@ router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
ri->addr = addr;
ri->or_port = router_get_advertised_or_port(options);
ri->dir_port = router_get_advertised_dir_port(options, 0);
- ri->supports_tunnelled_dir_requests = dir_server_mode(options);
+ ri->supports_tunnelled_dir_requests = dir_server_mode(options) &&
+ router_should_be_directory_server(options, ri->dir_port);
ri->cache_info.published_on = time(NULL);
ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from
* main thread */