Client should check if dir server has open dir port or handles tunnelled requests

Final piece of prop 237. Closes 12538.
This commit is contained in:
Matthew Finkel 2014-10-29 00:29:48 +00:00 committed by Nick Mathewson
parent 1ceb7142a1
commit 0a7d22a664
4 changed files with 58 additions and 6 deletions

6
changes/feature12538 Normal file
View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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
};