stats: Stop reporting statistics when ExtraInfoStatistics is 0

When ExtraInfoStatistics is 0, stop including bandwidth usage statistics,
GeoIPFile hashes, ServerTransportPlugin lines, and bridge statistics
by country in extra-info documents.

Fixes bug 29018; bugfix on 0.2.4.1-alpha (and earlier versions).
This commit is contained in:
teor 2019-01-08 18:40:03 +10:00
parent 361738c964
commit a798bd40fb
3 changed files with 33 additions and 26 deletions

5
changes/bug29018 Normal file
View File

@ -0,0 +1,5 @@
o Minor bugfixes (stats):
- When ExtraInfoStatistics is 0, stop including bandwidth usage statistics,
GeoIPFile hashes, ServerTransportPlugin lines, and bridge statistics
by country in extra-info documents. Fixes bug 29018;
bugfix on 0.2.4.1-alpha.

View File

@ -2313,7 +2313,8 @@ is non-zero):
When this option is enabled and BridgeRelay is also enabled, and we have When this option is enabled and BridgeRelay is also enabled, and we have
GeoIP data, Tor keeps a per-country count of how many client GeoIP data, Tor keeps a per-country count of how many client
addresses have contacted it so that it can help the bridge authority guess addresses have contacted it so that it can help the bridge authority guess
which countries have blocked access to it. (Default: 1) which countries have blocked access to it. If ExtraInfoStatistics is
enabled, it will be published as part of extra-info document. (Default: 1)
[[ServerDNSRandomizeCase]] **ServerDNSRandomizeCase** **0**|**1**:: [[ServerDNSRandomizeCase]] **ServerDNSRandomizeCase** **0**|**1**::
When this option is set, Tor sets the case of each character randomly in When this option is set, Tor sets the case of each character randomly in
@ -2395,6 +2396,8 @@ is non-zero):
[[ExtraInfoStatistics]] **ExtraInfoStatistics** **0**|**1**:: [[ExtraInfoStatistics]] **ExtraInfoStatistics** **0**|**1**::
When this option is enabled, Tor includes previously gathered statistics in When this option is enabled, Tor includes previously gathered statistics in
its extra-info documents that it uploads to the directory authorities. its extra-info documents that it uploads to the directory authorities.
Disabling this option also disables bandwidth usage statistics, GeoIPFile
hashes, and ServerTransportPlugin lists in the extra-info file.
(Default: 1) (Default: 1)
[[ExtendAllowPrivateAddresses]] **ExtendAllowPrivateAddresses** **0**|**1**:: [[ExtendAllowPrivateAddresses]] **ExtendAllowPrivateAddresses** **0**|**1**::

View File

@ -2942,7 +2942,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
char identity[HEX_DIGEST_LEN+1]; char identity[HEX_DIGEST_LEN+1];
char published[ISO_TIME_LEN+1]; char published[ISO_TIME_LEN+1];
char digest[DIGEST_LEN]; char digest[DIGEST_LEN];
char *bandwidth_usage;
int result; int result;
static int write_stats_to_extrainfo = 1; static int write_stats_to_extrainfo = 1;
char sig[DIROBJ_MAX_SIG_LEN+1]; char sig[DIROBJ_MAX_SIG_LEN+1];
@ -2957,7 +2956,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
base16_encode(identity, sizeof(identity), base16_encode(identity, sizeof(identity),
extrainfo->cache_info.identity_digest, DIGEST_LEN); extrainfo->cache_info.identity_digest, DIGEST_LEN);
format_iso_time(published, extrainfo->cache_info.published_on); format_iso_time(published, extrainfo->cache_info.published_on);
bandwidth_usage = rep_hist_get_bandwidth_lines();
if (emit_ed_sigs) { if (emit_ed_sigs) {
if (!extrainfo->cache_info.signing_key_cert->signing_key_included || if (!extrainfo->cache_info.signing_key_cert->signing_key_included ||
!ed25519_pubkey_eq(&extrainfo->cache_info.signing_key_cert->signed_key, !ed25519_pubkey_eq(&extrainfo->cache_info.signing_key_cert->signed_key,
@ -2983,21 +2981,25 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
ed_cert_line = tor_strdup(""); ed_cert_line = tor_strdup("");
} }
tor_asprintf(&pre, "extra-info %s %s\n%spublished %s\n%s", tor_asprintf(&pre, "extra-info %s %s\n%spublished %s\n",
extrainfo->nickname, identity, extrainfo->nickname, identity,
ed_cert_line, ed_cert_line,
published, bandwidth_usage); published);
smartlist_add(chunks, pre); smartlist_add(chunks, pre);
if (options->ExtraInfoStatistics && write_stats_to_extrainfo) {
log_info(LD_GENERAL, "Adding stats to extra-info descriptor.");
/* Bandwidth usage stats don't have their own option */
{
contents = rep_hist_get_bandwidth_lines();
smartlist_add(chunks, contents);
}
if (geoip_is_loaded(AF_INET)) if (geoip_is_loaded(AF_INET))
smartlist_add_asprintf(chunks, "geoip-db-digest %s\n", smartlist_add_asprintf(chunks, "geoip-db-digest %s\n",
geoip_db_digest(AF_INET)); geoip_db_digest(AF_INET));
if (geoip_is_loaded(AF_INET6)) if (geoip_is_loaded(AF_INET6))
smartlist_add_asprintf(chunks, "geoip6-db-digest %s\n", smartlist_add_asprintf(chunks, "geoip6-db-digest %s\n",
geoip_db_digest(AF_INET6)); geoip_db_digest(AF_INET6));
if (options->ExtraInfoStatistics && write_stats_to_extrainfo) {
log_info(LD_GENERAL, "Adding stats to extra-info descriptor.");
if (options->DirReqStatistics && if (options->DirReqStatistics &&
load_stats_file("stats"PATH_SEPARATOR"dirreq-stats", load_stats_file("stats"PATH_SEPARATOR"dirreq-stats",
"dirreq-stats-end", now, &contents) > 0) { "dirreq-stats-end", now, &contents) > 0) {
@ -3033,21 +3035,19 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
if (contents) if (contents)
smartlist_add(chunks, contents); smartlist_add(chunks, contents);
} }
}
/* Add information about the pluggable transports we support. */ /* Add information about the pluggable transports we support. */
if (options->ServerTransportPlugin) { if (options->ServerTransportPlugin) {
char *pluggable_transports = pt_get_extra_info_descriptor_string(); char *pluggable_transports = pt_get_extra_info_descriptor_string();
if (pluggable_transports) if (pluggable_transports)
smartlist_add(chunks, pluggable_transports); smartlist_add(chunks, pluggable_transports);
} }
if (should_record_bridge_info(options)) {
if (should_record_bridge_info(options) && write_stats_to_extrainfo) {
const char *bridge_stats = geoip_get_bridge_stats_extrainfo(now); const char *bridge_stats = geoip_get_bridge_stats_extrainfo(now);
if (bridge_stats) { if (bridge_stats) {
smartlist_add_strdup(chunks, bridge_stats); smartlist_add_strdup(chunks, bridge_stats);
} }
} }
}
if (emit_ed_sigs) { if (emit_ed_sigs) {
char sha256_digest[DIGEST256_LEN]; char sha256_digest[DIGEST256_LEN];
@ -3139,7 +3139,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
tor_free(s_dup); tor_free(s_dup);
tor_free(ed_cert_line); tor_free(ed_cert_line);
extrainfo_free(ei_tmp); extrainfo_free(ei_tmp);
tor_free(bandwidth_usage);
return result; return result;
} }