diff options
author | David Goulet <dgoulet@torproject.org> | 2018-04-25 11:04:47 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2018-05-01 10:07:08 -0400 |
commit | fdc01cb40e1c982c273f7e9685c586ee1ef89e30 (patch) | |
tree | 00e4e278c93dcdc74dbceeffdf7b46590e964eea /src/or/dirauth | |
parent | 6ee6533fd89018036f11c5ee62897f8a2b6c39c0 (diff) | |
download | tor-fdc01cb40e1c982c273f7e9685c586ee1ef89e30.tar.gz tor-fdc01cb40e1c982c273f7e9685c586ee1ef89e30.zip |
dirvote: Move the handling of GET /tor/status-vote to dirauth module
In order to further isolate the dirauth code into its module, this moves the
handling of the directory request GET /tor/status-vote/* into the module.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/dirauth')
-rw-r--r-- | src/or/dirauth/dirvote.c | 54 | ||||
-rw-r--r-- | src/or/dirauth/dirvote.h | 11 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/or/dirauth/dirvote.c b/src/or/dirauth/dirvote.c index 53a896eb4d..dd00806238 100644 --- a/src/or/dirauth/dirvote.c +++ b/src/or/dirauth/dirvote.c @@ -3912,3 +3912,57 @@ dirvote_clear_commits(networkstatus_t *ns) } } +/* The given url is the /tor/status-gove GET directory request. Populates the + * items list with strings that we can compress on the fly and dir_items with + * cached_dir_t objects that have a precompressed deflated version. */ +void +dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items, + smartlist_t *dir_items) +{ + int current; + + url += strlen("/tor/status-vote/"); + current = !strcmpstart(url, "current/"); + url = strchr(url, '/'); + tor_assert(url); + ++url; + if (!strcmp(url, "consensus")) { + const char *item; + tor_assert(!current); /* we handle current consensus specially above, + * since it wants to be spooled. */ + if ((item = dirvote_get_pending_consensus(FLAV_NS))) + smartlist_add(items, (char*)item); + } else if (!current && !strcmp(url, "consensus-signatures")) { + /* XXXX the spec says that we should implement + * current/consensus-signatures too. It doesn't seem to be needed, + * though. */ + const char *item; + if ((item=dirvote_get_pending_detached_signatures())) + smartlist_add(items, (char*)item); + } else if (!strcmp(url, "authority")) { + const cached_dir_t *d; + int flags = DGV_BY_ID | + (current ? DGV_INCLUDE_PREVIOUS : DGV_INCLUDE_PENDING); + if ((d=dirvote_get_vote(NULL, flags))) + smartlist_add(dir_items, (cached_dir_t*)d); + } else { + const cached_dir_t *d; + smartlist_t *fps = smartlist_new(); + int flags; + if (!strcmpstart(url, "d/")) { + url += 2; + flags = DGV_INCLUDE_PENDING | DGV_INCLUDE_PREVIOUS; + } else { + flags = DGV_BY_ID | + (current ? DGV_INCLUDE_PREVIOUS : DGV_INCLUDE_PENDING); + } + dir_split_resource_into_fingerprints(url, fps, NULL, + DSR_HEX|DSR_SORT_UNIQ); + SMARTLIST_FOREACH(fps, char *, fp, { + if ((d = dirvote_get_vote(fp, flags))) + smartlist_add(dir_items, (cached_dir_t*)d); + tor_free(fp); + }); + smartlist_free(fps); + } +} diff --git a/src/or/dirauth/dirvote.h b/src/or/dirauth/dirvote.h index 9682c60364..69d628766f 100644 --- a/src/or/dirauth/dirvote.h +++ b/src/or/dirauth/dirvote.h @@ -101,6 +101,8 @@ void dirvote_free_all(void); void dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens); void dirvote_clear_commits(networkstatus_t *ns); +void dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items, + smartlist_t *dir_items); #else /* HAVE_MODULE_DIRAUTH */ @@ -129,6 +131,15 @@ dirvote_clear_commits(networkstatus_t *ns) (void) ns; } +static inline void +dirvote_dirreq_get_status_vote(const char *url, smartlist_t *items, + smartlist_t *dir_items) +{ + (void) url; + (void) items; + (void) dir_items; +} + #endif /* HAVE_MODULE_DIRAUTH */ void dirvote_recalculate_timing(const or_options_t *options, time_t now); |