From: teor Date: Wed, 10 Apr 2019 05:57:54 +0000 (+1000) Subject: bwauth: update measured bandwidth file comments X-Git-Tag: tor-0.4.1.1-alpha~54^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ce9b1015741b663e4f1dbd2923886aedd00c7094;p=thirdparty%2Ftor.git bwauth: update measured bandwidth file comments We forgot to update function header comments and code comments when we made changes in 0.3.5.1-alpha and later. Closes 30112. --- diff --git a/src/feature/dirauth/bwauth.c b/src/feature/dirauth/bwauth.c index 1cfd8119df..e60c8b86bd 100644 --- a/src/feature/dirauth/bwauth.c +++ b/src/feature/dirauth/bwauth.c @@ -199,9 +199,32 @@ dirserv_get_credible_bandwidth_kb(const routerinfo_t *ri) } /** - * Read the measured bandwidth list file, apply it to the list of - * vote_routerstatus_t and store all the headers in bw_file_headers. + * Read the measured bandwidth list from_file: + * - store all the headers in bw_file_headers, + * - apply bandwidth lines to the list of vote_routerstatus_t in + * routerstatuses, + * - cache bandwidth lines for dirserv_get_bandwidth_for_router(), + * - expire old entries in the measured bandwidth cache, and + * - store the DIGEST_SHA256 of the contents of the file in digest_out. + * * Returns -1 on error, 0 otherwise. + * + * If the file can't be read, or is empty: + * - bw_file_headers is empty, + * - routerstatuses is not modified, + * - the measured bandwidth cache is not modified, and + * - digest_out is the zero-byte digest. + * + * Otherwise, if there is an error later in the file: + * - bw_file_headers contains all the headers up to the error, + * - routerstatuses is updated with all the relay lines up to the error, + * - the measured bandwidth cache is updated with all the relay lines up to + * the error, + * - if the timestamp is valid and recent, old entries in the measured + * bandwidth cache are expired, and + * - digest_out is the digest up to the first read error (if any). + * The digest is taken over all the readable file contents, even if the + * file is outdated or unparseable. */ int dirserv_read_measured_bandwidths(const char *from_file, @@ -223,15 +246,12 @@ dirserv_read_measured_bandwidths(const char *from_file, size_t n = 0; crypto_digest_t *digest = crypto_digest256_new(DIGEST_SHA256); - /* Initialise line, so that we can't possibly run off the end. */ - if (fp == NULL) { log_warn(LD_CONFIG, "Can't open bandwidth file at configured location: %s", from_file); goto err; } - /* If fgets fails, line is either unmodified, or indeterminate. */ if (tor_getline(&line,&n,fp) <= 0) { log_warn(LD_DIRSERV, "Empty bandwidth file"); goto err; @@ -345,6 +365,9 @@ dirserv_read_measured_bandwidths(const char *from_file, * the header block yet. If we encounter an incomplete bw line, return -1 but * don't warn since there could be additional header lines coming. If we * encounter a proper bw line, return 0 (and we got past the headers). + * + * If the line contains "vote=0", stop parsing it, and return -1, so that the + * line is ignored during voting. */ STATIC int measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line,