aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Finkel <Matthew.Finkel@gmail.com>2014-10-29 00:29:48 +0000
committerNick Mathewson <nickm@torproject.org>2015-12-18 13:14:09 -0500
commit0a7d22a664505c5235031fc2d3d792b83254b5ad (patch)
tree3236545e95744e96e0ac7ac4180a3c2ca3e63214
parent1ceb7142a131bd8706663d2b3c27d66a2dcb2a46 (diff)
downloadtor-0a7d22a664505c5235031fc2d3d792b83254b5ad.tar.gz
tor-0a7d22a664505c5235031fc2d3d792b83254b5ad.zip
Client should check if dir server has open dir port or handles tunnelled requests
Final piece of prop 237. Closes 12538.
-rw-r--r--changes/feature125386
-rw-r--r--src/or/nodelist.c17
-rw-r--r--src/or/routerlist.c2
-rw-r--r--src/test/test_nodelist.c39
4 files changed, 58 insertions, 6 deletions
diff --git a/changes/feature12538 b/changes/feature12538
new file mode 100644
index 0000000000..4e7ea9f41d
--- /dev/null
+++ b/changes/feature12538
@@ -0,0 +1,6 @@
+ o Minor features (directory system):
+ Previously only relays who explicitly opened a directory port (DirPort)
+ accepted directory requests from clients. Now all relays, with and without
+ a DirPort, who do not disable the DirCache option accept and serve
+ directory requests sent (tunnelled) through their ORPort.
+ Closes ticket 12538.
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index fc27207851..056d5e8cb9 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -644,12 +644,19 @@ node_is_named(const node_t *node)
int
node_is_dir(const node_t *node)
{
- if (node->rs)
- return node->rs->dir_port != 0;
- else if (node->ri)
- return node->ri->dir_port != 0;
- else
+ if (node->rs) {
+ routerstatus_t * rs = node->rs;
+ /* This is true if supports_tunnelled_dir_requests is true which
+ * indicates that we support directory request tunnelled or through the
+ * DirPort. */
+ return rs->is_v2_dir;
+ } else if (node->ri) {
+ routerinfo_t * ri = node->ri;
+ /* Both tunnelled request is supported or DirPort is set. */
+ return ri->supports_tunnelled_dir_requests;
+ } else {
return 0;
+ }
}
/** Return true iff <b>node</b> has either kind of usable descriptor -- that
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c45854c52f..df6d797e0d 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1512,7 +1512,7 @@ router_pick_directory_server_impl(dirinfo_type_t type, int flags,
if (!status)
continue;
- if (!node->is_running || !status->dir_port || !node->is_valid)
+ if (!node->is_running || !node_is_dir(node) || !node->is_valid)
continue;
if (requireother && router_digest_is_me(node->identity))
continue;
diff --git a/src/test/test_nodelist.c b/src/test/test_nodelist.c
index a8693ec9b5..262f105921 100644
--- a/src/test/test_nodelist.c
+++ b/src/test/test_nodelist.c
@@ -60,12 +60,51 @@ test_nodelist_node_get_verbose_nickname_not_named(void *arg)
return;
}
+/** A node should be considered a directory server if it has an open dirport
+ * of it accepts tunnelled directory requests.
+ */
+static void
+test_nodelist_node_is_dir(void *arg)
+{
+ routerstatus_t rs;
+ routerinfo_t ri;
+ node_t node;
+ memset(&node, 0, sizeof(node_t));
+ memset(&rs, 0, sizeof(routerstatus_t));
+ memset(&ri, 0, sizeof(routerinfo_t));
+
+ tt_assert(!node_is_dir(&node));
+
+ node.rs = &rs;
+ tt_assert(!node_is_dir(&node));
+
+ rs.is_v2_dir = 1;
+ tt_assert(node_is_dir(&node));
+
+ rs.is_v2_dir = 0;
+ rs.dir_port = 1;
+ tt_assert(node_is_dir(&node));
+
+ node.rs = NULL;
+ tt_assert(!node_is_dir(&node));
+ node.ri = &ri;
+ ri.supports_tunnelled_dir_requests = 1;
+ tt_assert(node_is_dir(&node));
+ ri.supports_tunnelled_dir_requests = 0;
+ ri.dir_port = 1;
+ tt_assert(node_is_dir(&node));
+
+ done:
+ return;
+}
+
#define NODE(name, flags) \
{ #name, test_nodelist_##name, (flags), NULL, NULL }
struct testcase_t nodelist_tests[] = {
NODE(node_get_verbose_nickname_by_id_null_node, TT_FORK),
NODE(node_get_verbose_nickname_not_named, TT_FORK),
+ NODE(node_is_dir, TT_FORK),
END_OF_TESTCASES
};