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.
This commit is contained in:
Nick Mathewson 2015-11-11 13:34:05 -05:00
parent 54406f78b8
commit 0c8e042c30

View File

@ -1099,11 +1099,26 @@ check_whether_dirport_reachable(void)
can_reach_dir_port; can_reach_dir_port;
} }
/** The lower threshold of remaining bandwidth required to advertise directory /** The lower threshold of remaining bandwidth required to advertise (or
* services */ * automatically provide) directory services */
/* XXX Should this be increased? */ /* XXX Should this be increased? */
#define MIN_BW_TO_ADVERTISE_DIRSERVER 51200 #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 /** Helper: Return 1 if we have sufficient resources for serving directory
* requests, return 0 otherwise. * requests, return 0 otherwise.
* dir_port is either 0 or the configured DirPort number. * 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; new_choice = 0;
reason = "AccountingMax enabled"; reason = "AccountingMax enabled";
} }
} else if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER || } else if (! router_has_bandwidth_to_be_dirserver(options)) {
(options->RelayBandwidthRate > 0 &&
options->RelayBandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER)) {
/* if we're advertising a small amount */ /* if we're advertising a small amount */
new_choice = 0; new_choice = 0;
reason = "BandwidthRate under 50KB"; reason = "BandwidthRate under 50KB";
@ -1178,8 +1191,8 @@ dir_server_mode(const or_options_t *options)
{ {
if (!options->DirCache) if (!options->DirCache)
return 0; return 0;
return (server_mode(options) || options->DirPort_set) && return options->DirPort_set ||
router_should_be_directory_server(options, 0); (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 /** 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->addr = addr;
ri->or_port = router_get_advertised_or_port(options); ri->or_port = router_get_advertised_or_port(options);
ri->dir_port = router_get_advertised_dir_port(options, 0); 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->cache_info.published_on = time(NULL);
ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from
* main thread */ * main thread */