commit 0a7d22a664505c5235031fc2d3d792b83254b5ad Author: Matthew Finkel Matthew.Finkel@gmail.com Date: Wed Oct 29 00:29:48 2014 +0000
Client should check if dir server has open dir port or handles tunnelled requests
Final piece of prop 237. Closes 12538. --- changes/feature12538 | 6 ++++++ src/or/nodelist.c | 17 ++++++++++++----- src/or/routerlist.c | 2 +- src/test/test_nodelist.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/changes/feature12538 b/changes/feature12538 new file mode 100644 index 0000000..4e7ea9f --- /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 fc27207..056d5e8 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 c45854c..df6d797 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 a8693ec..262f105 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 };
tor-commits@lists.torproject.org