Refactor generating the m lines in a vote into its own function

This commit is contained in:
Nick Mathewson 2013-02-08 11:52:51 -05:00
parent fd1c2a13e7
commit 194bd56c8a
3 changed files with 48 additions and 32 deletions

View File

@ -66,19 +66,6 @@ static cached_dir_t *the_directory = NULL;
/** For authoritative directories: the current (v1) network status. */ /** For authoritative directories: the current (v1) network status. */
static cached_dir_t the_runningrouters; static cached_dir_t the_runningrouters;
/** Array of start and end of consensus methods used for supported
microdescriptor formats. */
static const struct consensus_method_range_t {
int low;
int high;
} microdesc_consensus_methods[] = {
{MIN_METHOD_FOR_MICRODESC, MIN_METHOD_FOR_A_LINES - 1},
{MIN_METHOD_FOR_A_LINES, MIN_METHOD_FOR_P6_LINES - 1},
{MIN_METHOD_FOR_P6_LINES, MIN_METHOD_FOR_NTOR_KEY - 1},
{MIN_METHOD_FOR_NTOR_KEY, MAX_SUPPORTED_CONSENSUS_METHOD},
{-1, -1}
};
static void directory_remove_invalid(void); static void directory_remove_invalid(void);
static cached_dir_t *dirserv_regenerate_directory(void); static cached_dir_t *dirserv_regenerate_directory(void);
static char *format_versions_list(config_line_t *ln); static char *format_versions_list(config_line_t *ln);
@ -2811,11 +2798,9 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
microdescriptors = smartlist_new(); microdescriptors = smartlist_new();
SMARTLIST_FOREACH_BEGIN(routers, routerinfo_t *, ri) { SMARTLIST_FOREACH_BEGIN(routers, routerinfo_t *, ri) {
const struct consensus_method_range_t *cmr = NULL;
if (ri->cache_info.published_on >= cutoff) { if (ri->cache_info.published_on >= cutoff) {
routerstatus_t *rs; routerstatus_t *rs;
vote_routerstatus_t *vrs; vote_routerstatus_t *vrs;
microdesc_t *md;
node_t *node = node_get_mutable_by_id(ri->cache_info.identity_digest); node_t *node = node_get_mutable_by_id(ri->cache_info.identity_digest);
if (!node) if (!node)
continue; continue;
@ -2833,23 +2818,8 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
rs->is_flagged_running = 0; rs->is_flagged_running = 0;
vrs->version = version_from_platform(ri->platform); vrs->version = version_from_platform(ri->platform);
for (cmr = microdesc_consensus_methods; vrs->microdesc = dirvote_format_all_microdesc_vote_lines(ri, now,
cmr->low != -1 && cmr->high != -1; microdescriptors);
cmr++) {
md = dirvote_create_microdescriptor(ri, cmr->low);
if (md) {
char buf[128];
vote_microdesc_hash_t *h;
dirvote_format_microdesc_vote_line(buf, sizeof(buf), md,
cmr->low, cmr->high);
h = tor_malloc_zero(sizeof(vote_microdesc_hash_t));
h->microdesc_hash_line = tor_strdup(buf);
h->next = vrs->microdesc;
vrs->microdesc = h;
md->last_listed = now;
smartlist_add(microdescriptors, md);
}
}
smartlist_add(routerstatuses, vrs); smartlist_add(routerstatuses, vrs);
} }

View File

@ -3651,6 +3651,47 @@ dirvote_format_microdesc_vote_line(char *out_buf, size_t out_buf_len,
return ret; return ret;
} }
/** Array of start and end of consensus methods used for supported
microdescriptor formats. */
static const struct consensus_method_range_t {
int low;
int high;
} microdesc_consensus_methods[] = {
{MIN_METHOD_FOR_MICRODESC, MIN_METHOD_FOR_A_LINES - 1},
{MIN_METHOD_FOR_A_LINES, MIN_METHOD_FOR_P6_LINES - 1},
{MIN_METHOD_FOR_P6_LINES, MIN_METHOD_FOR_NTOR_KEY - 1},
{MIN_METHOD_FOR_NTOR_KEY, MAX_SUPPORTED_CONSENSUS_METHOD},
{-1, -1}
};
vote_microdesc_hash_t *
dirvote_format_all_microdesc_vote_lines(const routerinfo_t *ri, time_t now,
smartlist_t *microdescriptors_out)
{
const struct consensus_method_range_t *cmr;
vote_microdesc_hash_t *result = NULL;
for (cmr = microdesc_consensus_methods;
cmr->low != -1 && cmr->high != -1;
cmr++) {
microdesc_t *md = dirvote_create_microdescriptor(ri, cmr->low);
if (md) {
char buf[128];
vote_microdesc_hash_t *h;
dirvote_format_microdesc_vote_line(buf, sizeof(buf), md,
cmr->low, cmr->high);
h = tor_malloc_zero(sizeof(vote_microdesc_hash_t));
h->microdesc_hash_line = tor_strdup(buf);
h->next = result;
result = h;
md->last_listed = now;
smartlist_add(microdescriptors_out, md);
}
}
return result;
}
/** If <b>vrs</b> has a hash made for the consensus method <b>method</b> with /** If <b>vrs</b> has a hash made for the consensus method <b>method</b> with
* the digest algorithm <b>alg</b>, decode it and copy it into * the digest algorithm <b>alg</b>, decode it and copy it into
* <b>digest256_out</b> and return 0. Otherwise return -1. */ * <b>digest256_out</b> and return 0. Otherwise return -1. */

View File

@ -109,6 +109,11 @@ ssize_t dirvote_format_microdesc_vote_line(char *out, size_t out_len,
const microdesc_t *md, const microdesc_t *md,
int consensus_method_low, int consensus_method_low,
int consensus_method_high); int consensus_method_high);
vote_microdesc_hash_t *dirvote_format_all_microdesc_vote_lines(
const routerinfo_t *ri,
time_t now,
smartlist_t *microdescriptors_out);
int vote_routerstatus_find_microdesc_hash(char *digest256_out, int vote_routerstatus_find_microdesc_hash(char *digest256_out,
const vote_routerstatus_t *vrs, const vote_routerstatus_t *vrs,
int method, int method,