[or-cvs] r11269: Add a hacked-up GETINFO desc/all-recent-extrainfo-hack so th (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Fri Aug 24 14:41:10 UTC 2007


Author: nickm
Date: 2007-08-24 10:41:10 -0400 (Fri, 24 Aug 2007)
New Revision: 11269

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/control.c
Log:
 r14203 at 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.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14203] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-08-24 14:41:06 UTC (rev 11268)
+++ tor/trunk/ChangeLog	2007-08-24 14:41:10 UTC (rev 11269)
@@ -32,6 +32,10 @@
       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

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-08-24 14:41:06 UTC (rev 11268)
+++ tor/trunk/src/or/control.c	2007-08-24 14:41:10 UTC (rev 11269)
@@ -1230,6 +1230,48 @@
   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 @@
     *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 @@
   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,



More information about the tor-commits mailing list