aboutsummaryrefslogtreecommitdiff
path: root/src/or/router.c
diff options
context:
space:
mode:
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-04-20 17:30:55 +1000
committerteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-04-28 12:26:38 +1000
commit692828bea558295b2480eab473f9131e85d1eb9e (patch)
treeba737cfb0ae7f7743b2cef0aa90f56c2b1e1c6c2 /src/or/router.c
parent7babf33239eb1e349826753a9d0405cb59150cce (diff)
downloadtor-692828bea558295b2480eab473f9131e85d1eb9e.tar.gz
tor-692828bea558295b2480eab473f9131e85d1eb9e.zip
Decide to advertise begindir support like we decide to advertise DirPort
Decide to advertise begindir support in a similar way to how we decide to advertise DirPort. Fix up the associated descriptor-building unit tests. Resolves #18616, bugfix on 0c8e042c30946faa in #12538 in 0.2.8.1-alpha.
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 68bcf1326e..545753c82e 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1148,10 +1148,11 @@ router_should_be_directory_server(const or_options_t *options, int dir_port)
"seconds long. Raising to 1.");
interval_length = 1;
}
- log_info(LD_GENERAL, "Calculating whether to disable dirport: effective "
+ log_info(LD_GENERAL, "Calculating whether to advertise %s: effective "
"bwrate: %u, AccountingMax: "U64_FORMAT", "
- "accounting interval length %d", effective_bw,
- U64_PRINTF_ARG(options->AccountingMax),
+ "accounting interval length %d",
+ dir_port ? "dirport" : "begindir",
+ effective_bw, U64_PRINTF_ARG(options->AccountingMax),
interval_length);
acc_bytes = options->AccountingMax;
@@ -1218,6 +1219,7 @@ decide_to_advertise_dirport(const or_options_t *options, uint16_t dir_port)
return dir_port;
if (net_is_disabled())
return 0;
+ /* redundant - if DirPort is unreachable, we don't publish a descriptor */
if (!check_whether_dirport_reachable())
return 0;
if (!router_get_advertised_dir_port(options, dir_port))
@@ -1229,6 +1231,39 @@ decide_to_advertise_dirport(const or_options_t *options, uint16_t dir_port)
return router_should_be_directory_server(options, dir_port) ? dir_port : 0;
}
+/** Look at a variety of factors, and return 0 if we don't want to
+ * advertise the fact that we support begindir requests, else return 1.
+ *
+ * Log a helpful message if we change our mind about whether to advertise
+ * support for begindir.
+ */
+static int
+decide_to_advertise_begindir(const or_options_t *options,
+ int supports_tunnelled_dir_requests)
+{
+ /* Part one: reasons to publish or not publish that aren't
+ * worth mentioning to the user, either because they're obvious
+ * or because they're normal behavior. */
+
+ /* short circuit the rest of the function */
+ if (!supports_tunnelled_dir_requests)
+ return 0;
+ if (authdir_mode(options)) /* always publish */
+ return 1;
+ if (net_is_disabled())
+ return 0;
+ /* redundant - if ORPort is unreachable, we don't publish a descriptor */
+ if (!check_whether_orport_reachable())
+ return 0;
+ if (!router_get_advertised_or_port(options))
+ return 0;
+
+ /* Part two: reasons to publish or not publish that the user
+ * might find surprising. router_should_be_directory_server()
+ * considers config options that make us choose not to publish. */
+ return router_should_be_directory_server(options, 0);
+}
+
/** Allocate and return a new extend_info_t that can be used to build
* a circuit to or through the router <b>r</b>. Use the primary
* address of the router unless <b>for_direct_connect</b> is true, in
@@ -1924,8 +1959,8 @@ router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
ri->addr = addr;
ri->or_port = router_get_advertised_or_port(options);
ri->dir_port = router_get_advertised_dir_port(options, 0);
- ri->supports_tunnelled_dir_requests = dir_server_mode(options) &&
- router_should_be_directory_server(options, ri->dir_port);
+ ri->supports_tunnelled_dir_requests =
+ directory_permits_begindir_requests(options);
ri->cache_info.published_on = time(NULL);
ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from
* main thread */
@@ -2706,7 +2741,8 @@ router_dump_router_to_string(routerinfo_t *router,
tor_free(p6);
}
- if (router->supports_tunnelled_dir_requests) {
+ if (decide_to_advertise_begindir(options,
+ router->supports_tunnelled_dir_requests)) {
smartlist_add(chunks, tor_strdup("tunnelled-dir-server\n"));
}