From af0a43be2cf3e96ee9ac8e1f92c11aa5d5f6290f Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 10 Jan 2019 20:01:28 +1000 Subject: [PATCH] router: eliminate tiny router_build_fresh_descriptor() static functions Remove some tiny static functions called by router_build_fresh_descriptor(), and move their code into more relevant functions. Then, give router_update_{router,extra}info_descriptor_body identical layouts. Preparation for testing 29017 and 20918. --- src/feature/relay/router.c | 58 +++++++++++++------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c index 9aa4d56a4c..9a5e8b74ac 100644 --- a/src/feature/relay/router.c +++ b/src/feature/relay/router.c @@ -2066,6 +2066,9 @@ router_build_fresh_routerinfo(routerinfo_t **ri_out) ri->declared_family = get_my_declared_family(options); + ri->purpose = + options->BridgeRelay ? ROUTER_PURPOSE_BRIDGE : ROUTER_PURPOSE_GENERAL; + goto done; err: @@ -2122,18 +2125,20 @@ router_update_extrainfo_descriptor_body(extrainfo_t *ei) get_master_signing_keypair()) < 0) { log_warn(LD_BUG, "Couldn't generate extra-info descriptor."); return -1; - } else { - ei->cache_info.signed_descriptor_len = - strlen(ei->cache_info.signed_descriptor_body); - router_get_extrainfo_hash(ei->cache_info.signed_descriptor_body, - ei->cache_info.signed_descriptor_len, - ei->cache_info.signed_descriptor_digest); - crypto_digest256((char*) ei->digest256, - ei->cache_info.signed_descriptor_body, - ei->cache_info.signed_descriptor_len, - DIGEST_SHA256); - return 0; } + + ei->cache_info.signed_descriptor_len = + strlen(ei->cache_info.signed_descriptor_body); + + router_get_extrainfo_hash(ei->cache_info.signed_descriptor_body, + ei->cache_info.signed_descriptor_len, + ei->cache_info.signed_descriptor_digest); + crypto_digest256((char*) ei->digest256, + ei->cache_info.signed_descriptor_body, + ei->cache_info.signed_descriptor_len, + DIGEST_SHA256); + + return 0; } /** Set the fields in ri that depend on ei. @@ -2184,20 +2189,13 @@ router_update_routerinfo_descriptor_body(routerinfo_t *ri) ri->cache_info.signed_descriptor_len = strlen(ri->cache_info.signed_descriptor_body); + router_get_router_hash(ri->cache_info.signed_descriptor_body, + strlen(ri->cache_info.signed_descriptor_body), + ri->cache_info.signed_descriptor_digest); + return 0; } -/** Set the purpose field in ri. - */ -static void -router_update_routerinfo_purpose(routerinfo_t *ri) -{ - const or_options_t *options = get_options(); - - ri->purpose = - options->BridgeRelay ? ROUTER_PURPOSE_BRIDGE : ROUTER_PURPOSE_GENERAL; -} - /** Set the cache_info.send_unencrypted fields in ri and ei. */ static void @@ -2220,16 +2218,6 @@ router_update_info_send_unencrypted(routerinfo_t *ri, extrainfo_t *ei) } } -/** Set signed_descriptor_digest in ri->cache_info. - */ -static void -router_update_routerinfo_digest(routerinfo_t *ri) -{ - router_get_router_hash(ri->cache_info.signed_descriptor_body, - strlen(ri->cache_info.signed_descriptor_body), - ri->cache_info.signed_descriptor_digest); -} - /** Build a fresh routerinfo, signed server descriptor, and signed extra-info * document for this OR. * @@ -2287,16 +2275,10 @@ router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e) if (result < 0) goto err; - /* TODO: fold into router_build_fresh_routerinfo() */ - router_update_routerinfo_purpose(ri); - /* TODO: fold into router_update_extrainfo_descriptor_body() and * router_update_routerinfo_descriptor_body() ? */ router_update_info_send_unencrypted(ri, ei); - /* TODO: fold into router_update_routerinfo_descriptor_body() */ - router_update_routerinfo_digest(ri); - if (ei) { if (BUG(routerinfo_incompatible_with_extrainfo(ri->identity_pkey, ei, &ri->cache_info, NULL))) {