Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket31684 #1328

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/ticket31684
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
o Minor features (onion services):
- GETINFO dir/status-vote/current/consensus-microdesc dumps microdesc consensus. Closes ticket 31684.
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
76 changes: 58 additions & 18 deletions src/feature/control/control_getinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,51 @@ getinfo_helper_current_time(control_connection_t *control_conn,
return 0;
}

/**
* Switch between microdesc vs networkstatus descriptor dumps
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
* Assumes that question would be either:
* - dir/status-vote/current/consensus-microdesc
* or
* - dir/status-vote/current/consensus
*/
STATIC int
getinfo_helper_current_consensus(const char* question,
char** answer,
const char** errmsg)
{
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
// Ensures question contains a request for
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
// ns or microdesc consensus
if (
ltbringer marked this conversation as resolved.
Show resolved Hide resolved
strcmp(question, "dir/status-vote/current/consensus") &&
strcmp(question, "dir/status-vote/current/consensus-microdesc")) {
return 0;
}

const char* consensus_type = !strcmp(
question, "dir/status-vote/current/consensus-microdesc"
) ? "microdesc" : "ns";

if (we_want_to_fetch_flavor(get_options(), FLAV_NS)) {
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
const cached_dir_t *consensus = dirserv_get_consensus(consensus_type);
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
if (consensus) {
*answer = tor_strdup(consensus->dir);
}
}
if (!*answer) { /* try loading it from disk */
tor_mmap_t *mapped = networkstatus_map_cached_consensus(consensus_type);
if (mapped) {
*answer = tor_memdup_nulterm(mapped->data, mapped->size);
tor_munmap_file(mapped);
}
if (!*answer) { /* generate an error */
*errmsg = "Could not open cached consensus. "
"Make sure FetchUselessDescriptors is set to 1.";
return -1;
}
}
return 0;
}

/** Implementation helper for GETINFO: knows the answers for questions about
* directory information. */
STATIC int
Expand Down Expand Up @@ -362,6 +407,7 @@ getinfo_helper_dir(control_connection_t *control_conn,
if (body)
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
} else if (! we_fetch_router_descriptors(get_options())) {

asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing

/* Descriptors won't be available, provide proper error */
*errmsg = "We fetch microdescriptors, not router "
"descriptors. You'll need to use md/name/* "
Expand Down Expand Up @@ -576,24 +622,16 @@ getinfo_helper_dir(control_connection_t *control_conn,
smartlist_free(descs);
} else if (!strcmpstart(question, "dir/status/")) {
*answer = tor_strdup("");
} else if (!strcmp(question, "dir/status-vote/current/consensus")) { /* v3 */
if (we_want_to_fetch_flavor(get_options(), FLAV_NS)) {
const cached_dir_t *consensus = dirserv_get_consensus("ns");
if (consensus)
*answer = tor_strdup(consensus->dir);
}
if (!*answer) { /* try loading it from disk */
tor_mmap_t *mapped = networkstatus_map_cached_consensus("ns");
if (mapped) {
*answer = tor_memdup_nulterm(mapped->data, mapped->size);
tor_munmap_file(mapped);
}
if (!*answer) { /* generate an error */
*errmsg = "Could not open cached consensus. "
"Make sure FetchUselessDescriptors is set to 1.";
return -1;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird spacing?

} else if (-1 == getinfo_helper_current_consensus(
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
question,
asn-d6 marked this conversation as resolved.
Show resolved Hide resolved
answer,
errmsg))
{
/**
* answer is set by getinfo_helper_current_consensus
* if the question matches
*/
return -1;
} else if (!strcmp(question, "network-status")) { /* v1 */
static int network_status_warned = 0;
if (!network_status_warned) {
Expand Down Expand Up @@ -1513,6 +1551,8 @@ static const getinfo_item_t getinfo_items[] = {
"v2 networkstatus docs as retrieved from a DirPort."),
ITEM("dir/status-vote/current/consensus", dir,
"v3 Networkstatus consensus as retrieved from a DirPort."),
ITEM("dir/status-vote/current/consensus-microdesc", dir,
ltbringer marked this conversation as resolved.
Show resolved Hide resolved
"v3 Microdescriptors consensus as retrieved from a DirPort."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

ITEM("exit-policy/default", policies,
"The default value appended to the configured exit policy."),
ITEM("exit-policy/reject-private/default", policies,
Expand Down
3 changes: 3 additions & 0 deletions src/feature/control/control_getinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ STATIC int getinfo_helper_downloads(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_current_consensus(
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_dir(
control_connection_t *control_conn,
const char *question, char **answer,
Expand Down