From b9d43e2685e809f0a31c7f35e9b2a003a8dd9e41 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 24 Aug 2007 14:41:10 +0000 Subject: [PATCH] r14203@Kushana: nickm | 2007-08-24 10:15:58 -0400 Add a hacked-up GETINFO desc/all-recent-extrainfo-hack so that torstat can keep working with a minimum of fuss, until it learns about extrainfo documents. svn:r11269 --- ChangeLog | 4 +++ src/or/control.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/ChangeLog b/ChangeLog index e97b06ec74..fb5241f3d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,10 @@ Changes in version 0.2.0.6-alpha - 2007-??-?? address family. Addresses but does not wholly fix bug 483. (Bugfix on 0.2.0.x) + o Minor features (controller): + - There is now an ugly, temporary "desc/all-recent-extrainfo-hack" + GETINFO for Torstat to use into it can switch to use extrainfos. + o Minor bugfixes (misc): - Let directory authorities startup even when they can't generate a descriptor immediately, e.g. because they don't know their diff --git a/src/or/control.c b/src/or/control.c index 8a77a6e716..d7674c80c5 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1230,6 +1230,48 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, return 0; } +/** DOCDOC */ +static char * +munge_extrainfo_into_routerinfo(const char *ri_body, signed_descriptor_t *ri, + signed_descriptor_t *ei) +{ + char *out = NULL, *outp; + int i; + const char *router_sig; + const char *ei_body = signed_descriptor_get_body(ei); + size_t ri_len = ri->signed_descriptor_len; + size_t ei_len = ei->signed_descriptor_len; + if (!ei_body) + goto bail; + + outp = out = tor_malloc(ri_len+ei_len+1); + if (!(router_sig = tor_memstr(ri_body, ri_len, "\nrouter-signature"))) + goto bail; + ++router_sig; + memcpy(out, ri_body, router_sig-ri_body); + outp += router_sig-ri_body; + + for (i=0; i < 2; ++i) { + const char *kwd = i?"\nwrite-history ":"\nread-history "; + const char *cp, *eol; + if (!(cp = tor_memstr(ei_body, ei_len, kwd))) + continue; + ++cp; + eol = memchr(cp, '\n', ei_len - (cp-ei_body)); + memcpy(outp, cp, eol-cp+1); + outp += eol-cp+1; + } + memcpy(outp, router_sig, ri_len - (router_sig-ri_body)); + *outp++ = '\0'; + tor_assert(outp-out < (int)(ri_len+ei_len+1)); + + return out; + bail: + tor_free(out); + return tor_strndup(ri_body, ri->signed_descriptor_len); +} + + /** Implementation helper for GETINFO: knows the answers for questions about * directory information. */ static int @@ -1265,6 +1307,28 @@ getinfo_helper_dir(control_connection_t *control_conn, *answer = smartlist_join_strings(sl, "", 0, NULL); SMARTLIST_FOREACH(sl, char *, c, tor_free(c)); smartlist_free(sl); + } else if (!strcmp(question, "desc/all-recent-extrainfo-hack")) { + /* XXXX Remove this once Torstat asks for extrainfos. */ + routerlist_t *routerlist = router_get_routerlist(); + smartlist_t *sl = smartlist_create(); + if (routerlist && routerlist->routers) { + SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, ri, + { + const char *body = signed_descriptor_get_body(&ri->cache_info); + signed_descriptor_t *ei = extrainfo_get_by_descriptor_digest( + ri->cache_info.signed_descriptor_digest); + if (ei && body) { + smartlist_add(sl, munge_extrainfo_into_routerinfo(body, + &ri->cache_info, ei)); + } else if (body) { + smartlist_add(sl, + tor_strndup(body, ri->cache_info.signed_descriptor_len)); + } + }); + } + *answer = smartlist_join_strings(sl, "", 0, NULL); + SMARTLIST_FOREACH(sl, char *, c, tor_free(c)); + smartlist_free(sl); } else if (!strcmpstart(question, "dir/server/")) { size_t answer_len = 0, url_len = strlen(question)+2; char *url = tor_malloc(url_len); @@ -1584,6 +1648,7 @@ static const getinfo_item_t getinfo_items[] = { PREFIX("desc/name/", dir, "Router descriptors by nickname."), ITEM("desc/all-recent", dir, "All non-expired, non-superseded router descriptors."), + ITEM("desc/all-recent-extrainfo-hack", dir, NULL), /* Hack. */ ITEM("ns/all", networkstatus, "Brief summary of router status (v2 directory format)"), PREFIX("ns/id/", networkstatus,