-
Notifications
You must be signed in to change notification settings - Fork 924
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
Ticket31684 #1328
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
o Minor features (onion services): | ||
- Implement a new GETINFO command to fetch microdescriptor consensus. Closes ticket 31684. | ||
|
||
o Code simplification and refactoring (onion services): | ||
- Create a helper function that can fetch network status or microdesc consensuses. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,6 +325,41 @@ getinfo_helper_current_time(control_connection_t *control_conn, | |
return 0; | ||
} | ||
|
||
/** GETINFO helper for dumping different consensus flavors | ||
* returns: 0 on success -1 on error. */ | ||
STATIC int | ||
getinfo_helper_current_consensus(consensus_flavor_t flavor, | ||
char** answer, | ||
const char** errmsg) | ||
{ | ||
asn-d6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const char *flavor_name = networkstatus_get_flavor_name(flavor); | ||
if (!strcmp(flavor_name, "??")) { | ||
*errmsg = "Could not open cached consensus. " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong error message |
||
"Make sure FetchUselessDescriptors is set to 1."; | ||
return -1; | ||
} | ||
if (we_want_to_fetch_flavor(get_options(), flavor)) { | ||
/** Check from the cache */ | ||
const cached_dir_t *consensus = dirserv_get_consensus(flavor_name); | ||
if (consensus) { | ||
*answer = tor_strdup(consensus->dir); | ||
} | ||
} | ||
if (!*answer) { /* try loading it from disk */ | ||
tor_mmap_t *mapped = networkstatus_map_cached_consensus(flavor_name); | ||
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 | ||
|
@@ -362,6 +397,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/* " | ||
|
@@ -576,24 +612,19 @@ 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); | ||
} else if (!strcmp(question, "dir/status-vote/current/consensus")) { | ||
int consensus_result = getinfo_helper_current_consensus(FLAV_NS, | ||
answer, errmsg); | ||
if (consensus_result == -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
return -1; | ||
} | ||
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."; | ||
} else if (!strcmp(question, | ||
"dir/status-vote/current/consensus-microdesc")) { | ||
int consensus_result = getinfo_helper_current_consensus(FLAV_MICRODESC, | ||
answer, errmsg); | ||
if (consensus_result == -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
return -1; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird spacing? |
||
} else if (!strcmp(question, "network-status")) { /* v1 */ | ||
static int network_status_warned = 0; | ||
if (!network_status_warned) { | ||
|
@@ -1513,6 +1544,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."), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,8 +259,9 @@ dirserv_set_cached_consensus_networkstatus(const char *networkstatus, | |
|
||
/** Return the latest downloaded consensus networkstatus in encoded, signed, | ||
* optionally compressed format, suitable for sending to clients. */ | ||
cached_dir_t * | ||
dirserv_get_consensus(const char *flavor_name) | ||
MOCK_IMPL(cached_dir_t *, | ||
dirserv_get_consensus, | ||
(const char *flavor_name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
{ | ||
if (!cached_consensuses) | ||
return NULL; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,10 +216,12 @@ networkstatus_reset_download_failures(void) | |
} | ||
|
||
/** Return the filename used to cache the consensus of a given flavor */ | ||
static char * | ||
networkstatus_get_cache_fname(int flav, | ||
const char *flavorname, | ||
int unverified_consensus) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
MOCK_IMPL(char *, | ||
networkstatus_get_cache_fname, | ||
(int flav, | ||
const char *flavorname, | ||
int unverified_consensus)) | ||
{ | ||
char buf[128]; | ||
const char *prefix; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,12 @@ | |
|
||
void networkstatus_reset_warnings(void); | ||
void networkstatus_reset_download_failures(void); | ||
tor_mmap_t *networkstatus_map_cached_consensus(const char *flavorname); | ||
MOCK_DECL(char *, | ||
networkstatus_get_cache_fname, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
(int flav, | ||
const char *flavorname, | ||
int unverified_consensus)); | ||
tor_mmap_t * networkstatus_map_cached_consensus(const char *flavorname); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra space |
||
int router_reload_consensus_networkstatus(void); | ||
void routerstatus_free_(routerstatus_t *rs); | ||
#define routerstatus_free(rs) \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,7 @@ | |
* failure, return NULL. Sets errno properly, using ERANGE to mean | ||
* "empty file". Must only be called on trusted Tor-owned files, as changing | ||
* the underlying file's size causes unspecified behavior. */ | ||
tor_mmap_t * | ||
tor_mmap_file(const char *filename) | ||
MOCK_IMPL(tor_mmap_t *, tor_mmap_file, (const char *filename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
{ | ||
int fd; /* router file */ | ||
char *string; | ||
|
@@ -111,8 +110,7 @@ tor_mmap_file(const char *filename) | |
} | ||
/** Release storage held for a memory mapping; returns 0 on success, | ||
* or -1 on failure (and logs a warning). */ | ||
int | ||
tor_munmap_file(tor_mmap_t *handle) | ||
MOCK_IMPL(int, tor_munmap_file, (tor_mmap_t *handle)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
{ | ||
int res; | ||
|
||
|
@@ -132,8 +130,8 @@ tor_munmap_file(tor_mmap_t *handle) | |
return res; | ||
} | ||
#elif defined(_WIN32) | ||
tor_mmap_t * | ||
tor_mmap_file(const char *filename) | ||
|
||
MOCK_IMPL(tor_mmap_t *, tor_mmap_file, (const char *filename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
{ | ||
TCHAR tfilename[MAX_PATH]= {0}; | ||
tor_mmap_t *res = tor_malloc_zero(sizeof(tor_mmap_t)); | ||
|
@@ -213,8 +211,7 @@ tor_mmap_file(const char *filename) | |
} | ||
|
||
/* Unmap the file, and return 0 for success or -1 for failure */ | ||
int | ||
tor_munmap_file(tor_mmap_t *handle) | ||
MOCK_IMPL(int, tor_munmap_file, (tor_mmap_t *handle)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing |
||
{ | ||
if (handle == NULL) | ||
return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typos