Change dataflow on generating 'dir-cache' flag.

Convention is that router_dump_router_to_string() should look at its
input "router", which should be generated by
router_build_fresh_descirptor().
This commit is contained in:
Nick Mathewson 2015-11-03 09:29:31 -05:00
parent 6a5528356f
commit 54406f78b8
2 changed files with 4 additions and 7 deletions

View File

@ -1899,6 +1899,7 @@ 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->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 */
@ -2675,7 +2676,7 @@ router_dump_router_to_string(routerinfo_t *router,
tor_free(p6); tor_free(p6);
} }
if (dir_server_mode(options)) { if (router->supports_tunnelled_dir_requests) {
smartlist_add(chunks, tor_strdup("tunnelled-dir-server\n")); smartlist_add(chunks, tor_strdup("tunnelled-dir-server\n"));
} }

View File

@ -111,6 +111,7 @@ test_dir_formats(void *arg)
r1->cache_info.published_on = 0; r1->cache_info.published_on = 0;
r1->or_port = 9000; r1->or_port = 9000;
r1->dir_port = 9003; r1->dir_port = 9003;
r1->supports_tunnelled_dir_requests = 1;
tor_addr_parse(&r1->ipv6_addr, "1:2:3:4::"); tor_addr_parse(&r1->ipv6_addr, "1:2:3:4::");
r1->ipv6_orport = 9999; r1->ipv6_orport = 9999;
r1->onion_pkey = crypto_pk_dup_key(pk1); r1->onion_pkey = crypto_pk_dup_key(pk1);
@ -155,6 +156,7 @@ test_dir_formats(void *arg)
r2->cache_info.published_on = 5; r2->cache_info.published_on = 5;
r2->or_port = 9005; r2->or_port = 9005;
r2->dir_port = 0; r2->dir_port = 0;
r2->supports_tunnelled_dir_requests = 1;
r2->onion_pkey = crypto_pk_dup_key(pk2); r2->onion_pkey = crypto_pk_dup_key(pk2);
curve25519_keypair_t r2_onion_keypair; curve25519_keypair_t r2_onion_keypair;
curve25519_keypair_generate(&r2_onion_keypair, 0); curve25519_keypair_generate(&r2_onion_keypair, 0);
@ -176,12 +178,9 @@ test_dir_formats(void *arg)
options->ContactInfo = tor_strdup("Magri White " options->ContactInfo = tor_strdup("Magri White "
"<magri@elsewhere.example.com>"); "<magri@elsewhere.example.com>");
options->ORPort_set = options->DirPort_set = options->AssumeReachable = 1;
buf = router_dump_router_to_string(r1, pk2, NULL, NULL, NULL); buf = router_dump_router_to_string(r1, pk2, NULL, NULL, NULL);
tor_free(options->ContactInfo); tor_free(options->ContactInfo);
/* Reset for later */
options->ORPort_set = options->DirPort_set = options->AssumeReachable = 0;
tt_assert(buf); tt_assert(buf);
strlcpy(buf2, "router Magri 192.168.0.1 9000 0 9003\n" strlcpy(buf2, "router Magri 192.168.0.1 9000 0 9003\n"
@ -301,8 +300,6 @@ test_dir_formats(void *arg)
strlcat(buf2, "tunnelled-dir-server\n", sizeof(buf2)); strlcat(buf2, "tunnelled-dir-server\n", sizeof(buf2));
strlcat(buf2, "router-sig-ed25519 ", sizeof(buf2)); strlcat(buf2, "router-sig-ed25519 ", sizeof(buf2));
options->ORPort_set = 1;
buf = router_dump_router_to_string(r2, pk1, pk2, &r2_onion_keypair, &kp2); buf = router_dump_router_to_string(r2, pk1, pk2, &r2_onion_keypair, &kp2);
tt_assert(buf); tt_assert(buf);
buf[strlen(buf2)] = '\0'; /* Don't compare the sig; it's never the same buf[strlen(buf2)] = '\0'; /* Don't compare the sig; it's never the same
@ -314,7 +311,6 @@ test_dir_formats(void *arg)
buf = router_dump_router_to_string(r2, pk1, NULL, NULL, NULL); buf = router_dump_router_to_string(r2, pk1, NULL, NULL, NULL);
/* Reset for later */ /* Reset for later */
options->ORPort_set = 0;
cp = buf; cp = buf;
rp2 = router_parse_entry_from_string((const char*)cp,NULL,1,0,NULL,NULL); rp2 = router_parse_entry_from_string((const char*)cp,NULL,1,0,NULL,NULL);
tt_assert(rp2); tt_assert(rp2);