diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-08-15 19:55:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-08-15 19:55:52 +0000 |
commit | 4135c68853a92cf756886d3baf303a7c58ee8aaf (patch) | |
tree | 33db95470c297a6ce490af9e5d8353cab11ea9be /src/or | |
parent | 717f3b8a1239fe1e72afd76002470969730cd2bc (diff) | |
download | tor-4135c68853a92cf756886d3baf303a7c58ee8aaf.tar tor-4135c68853a92cf756886d3baf303a7c58ee8aaf.tar.gz |
r14049@Kushana: nickm | 2007-08-15 14:43:56 -0400
Implement code to serve pending votes, consensuses, and signatures.
svn:r11125
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/directory.c | 79 | ||||
-rw-r--r-- | src/or/dirvote.c | 38 | ||||
-rw-r--r-- | src/or/or.h | 5 |
3 files changed, 121 insertions, 1 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 76e6c99ac..0847f23fd 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1935,6 +1935,85 @@ directory_handle_command_get(dir_connection_t *conn, const char *headers, return 0; } + if (!strcmpstart(url,"/tor/status-vote/current/") || + !strcmpstart(url,"/tor/status-vote/next/")) { + char *url_mem = url; + size_t url_len = strlen(url); + int deflated = !strcmp(url+url_len-2, ".z"); + int current = 1; + ssize_t body_len = 0; + smartlist_t *items = smartlist_create(); + smartlist_t *dir_items = smartlist_create(); + int lifetime = 60; /* XXXX020 should actually use vote intervals. */ + if (deflated) + url[url_len-2] = '\0'; + 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())) + smartlist_add(items, (char*)item); + } else if (current && !strcmp(url, "consensus-signatures")) { + /* XXXX020 the spec says that we should implement + * currrent/consensus-signatures too. Why? */ + const char *item; + if ((item=dirvote_get_pending_detached_signatures())) + smartlist_add(items, (char*)item); + } else if (current && !strcmp(url, "authority")) { + const cached_dir_t *d; + if ((d=dirvote_get_vote(NULL))) + smartlist_add(dir_items, (cached_dir_t*)d); + } else if (current) { + const cached_dir_t *d; + smartlist_t *fps = smartlist_create(); + dir_split_resource_into_fingerprints(url, fps, NULL, 1, 1); + SMARTLIST_FOREACH(fps, char *, fp, { + if ((d = dirvote_get_vote(fp))) + smartlist_add(dir_items, (cached_dir_t*)d); + tor_free(fp); + }); + smartlist_free(fps); + } + if (!smartlist_len(dir_items) && !smartlist_len(items)) { + write_http_status_line(conn, 404, "Not found"); + tor_free(url_mem); + return 0; + } + SMARTLIST_FOREACH(items, const char *, item, + if (!deflated) + body_len += strlen(item)); + SMARTLIST_FOREACH(dir_items, cached_dir_t *, d, + body_len += deflated ? d->dir_z_len : d->dir_len); + write_http_response_header(conn, body_len ? body_len : -1, + deflated?"application/octet_stream":"text/plain", + deflated?"deflate":NULL, + lifetime); + + if (smartlist_len(items)) { + if (deflated) { + conn->zlib_state = tor_zlib_new(1, ZLIB_METHOD); + SMARTLIST_FOREACH(items, const char *, c, + connection_write_to_buf_zlib(c, strlen(c), conn, 0)); + connection_write_to_buf_zlib("", 0, conn, 1); + } else { + SMARTLIST_FOREACH(items, const char *, c, + connection_write_to_buf(c, strlen(c), TO_CONN(conn))); + } + } else { + SMARTLIST_FOREACH(dir_items, cached_dir_t *, d, + connection_write_to_buf(deflated ? d->dir_z : d->dir, + deflated ? d->dir_z_len : d->dir_len, + TO_CONN(conn))); + } + tor_free(url_mem); + return 0; + } + if (!strcmpstart(url,"/tor/server/") || !strcmpstart(url,"/tor/extra/")) { char *url_mem = url; diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 5d0471375..2c88b07c9 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -1096,7 +1096,6 @@ dirvote_recalculate_timing(time_t now) memset(&voting_schedule, 0, sizeof(voting_schedule)); if (consensus) { - /* XXXX020 sanity-check these somewhere! */ interval = consensus->fresh_until - consensus->valid_after; vote_delay = consensus->vote_seconds; dist_delay = consensus->dist_seconds; @@ -1605,3 +1604,40 @@ dirvote_free_all(void) } } +/* ==== + * Access to pending items. + * ==== */ + +/** DOCDOC */ +const char * +dirvote_get_pending_consensus(void) +{ + return pending_consensus_body; +} + +/** DOCDOC */ +const char * +dirvote_get_pending_detached_signatures(void) +{ + return pending_consensus_signatures; +} + +/** DOCDOC */ +const cached_dir_t * +dirvote_get_vote(const char *id) +{ + if (!pending_vote_list) + return NULL; + if (id == NULL) { + authority_cert_t *c = get_my_v3_authority_cert(); + if (c) + id = c->cache_info.identity_digest; + else + return NULL; + } + SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, pv, + if (!memcmp(get_voter(pv->vote)->identity_digest, id, DIGEST_LEN)) + return pv->vote_body); + return NULL; +} + diff --git a/src/or/or.h b/src/or/or.h index 4d04a7f02..a0d9b087e 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2881,6 +2881,11 @@ int dirvote_compute_consensus(void); int dirvote_add_signatures(const char *detached_signatures_body); int dirvote_publish_consensus(void); +/* Item access */ +const char *dirvote_get_pending_consensus(void); +const char *dirvote_get_pending_detached_signatures(void); +const cached_dir_t *dirvote_get_vote(const char *id); + #ifdef DIRVOTE_PRIVATE time_t median_time(smartlist_t *times); int median_int(smartlist_t *times); |