ソースを参照

Add "GETINFO/desc-annotations/id/<OR digest>" so controllers can
ask about source, timestamp of arrival, purpose, etc. We need
something like this to help Vidalia not do GeoIP lookups on bridge
addresses.


svn:r12687

Roger Dingledine 17 年 前
コミット
8de470cf69

+ 4 - 0
ChangeLog

@@ -49,6 +49,10 @@ Changes in version 0.2.0.13-alpha - 2007-12-??
       be a bridge relay. Right now the only difference is that it makes
       be a bridge relay. Right now the only difference is that it makes
       you answer begin_dir requests, and it makes you cache dir info,
       you answer begin_dir requests, and it makes you cache dir info,
       even if your DirPort isn't on.
       even if your DirPort isn't on.
+    - Add "GETINFO/desc-annotations/id/<OR digest>" so controllers can
+      ask about source, timestamp of arrival, purpose, etc. We need
+      something like this to help Vidalia not do GeoIP lookups on bridge
+      addresses.
 
 
 
 
 Changes in version 0.2.0.12-alpha - 2007-11-16
 Changes in version 0.2.0.12-alpha - 2007-11-16

+ 4 - 0
doc/spec/control-spec.txt

@@ -371,6 +371,10 @@ $Id$
     "desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest
     "desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest
       server descriptor for a given OR, NUL-terminated.
       server descriptor for a given OR, NUL-terminated.
 
 
+    "desc-annotations/id/<OR identity>" -- outputs the annotations string
+      (source, timestamp of arrival, purpose, etc) for the corresponding
+      descriptor. [First implemented in 0.2.0.13-alpha.]
+
     "extra-info/digest/<digest>"  -- the extrainfo document whose digest (in
     "extra-info/digest/<digest>"  -- the extrainfo document whose digest (in
       hex) is <digest>.  Only available if we're downloading extra-info
       hex) is <digest>.  Only available if we're downloading extra-info
       documents.
       documents.

+ 1 - 2
doc/spec/proposals/126-geoip-reporting.txt

@@ -148,8 +148,7 @@ Status: Open
   that might want to map its relay locations. The best answer is that it
   that might want to map its relay locations. The best answer is that it
   should learn the router annotations, with a new controller 'getinfo'
   should learn the router annotations, with a new controller 'getinfo'
   command:
   command:
-    "GETINFO router-annotations/id/<OR identity>" or
+    "GETINFO desc-annotations/id/<OR identity>"
-    "GETINFO router-annotations/name/<OR nickname>"
   which would respond with something like
   which would respond with something like
     @downloaded-at 2007-11-29 08:06:38
     @downloaded-at 2007-11-29 08:06:38
     @source "128.31.0.34"
     @source "128.31.0.34"

+ 10 - 0
src/or/control.c

@@ -1356,6 +1356,16 @@ getinfo_helper_dir(control_connection_t *control_conn,
     *answer = smartlist_join_strings(sl, "", 0, NULL);
     *answer = smartlist_join_strings(sl, "", 0, NULL);
     SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
     SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
     smartlist_free(sl);
     smartlist_free(sl);
+  } else if (!strcmpstart(question, "desc-annotations/id/")) {
+    routerinfo_t *ri = router_get_by_hexdigest(question+
+                                               strlen("desc-annotations/id/"));
+    if (ri) {
+      const char *annotations =
+        signed_descriptor_get_annotations(&ri->cache_info);
+      if (annotations)
+        *answer = tor_strndup(annotations,
+                              ri->cache_info.signed_annotations_len);
+    }
   } else if (!strcmpstart(question, "dir/server/")) {
   } else if (!strcmpstart(question, "dir/server/")) {
     size_t answer_len = 0, url_len = strlen(question)+2;
     size_t answer_len = 0, url_len = strlen(question)+2;
     char *url = tor_malloc(url_len);
     char *url = tor_malloc(url_len);

+ 1 - 0
src/or/or.h

@@ -3810,6 +3810,7 @@ signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
 signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
 signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
 signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
 signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
 const char *signed_descriptor_get_body(signed_descriptor_t *desc);
 const char *signed_descriptor_get_body(signed_descriptor_t *desc);
+const char *signed_descriptor_get_annotations(signed_descriptor_t *desc);
 routerlist_t *router_get_routerlist(void);
 routerlist_t *router_get_routerlist(void);
 void routerinfo_free(routerinfo_t *router);
 void routerinfo_free(routerinfo_t *router);
 void extrainfo_free(extrainfo_t *extrainfo);
 void extrainfo_free(extrainfo_t *extrainfo);

+ 10 - 1
src/or/routerlist.c

@@ -1966,7 +1966,8 @@ extrainfo_get_by_descriptor_digest(const char *digest)
  * The returned string is not guaranteed to be NUL-terminated: the string's
  * The returned string is not guaranteed to be NUL-terminated: the string's
  * length will be in desc-\>signed_descriptor_len.
  * length will be in desc-\>signed_descriptor_len.
  *
  *
- * If with_annotations is set, the returned string will include the annotations
+ * If <b>with_annotations</b> is set, the returned string will include
+ * the annotations
  * (if any) preceding the descriptor.  This will increase the length of the
  * (if any) preceding the descriptor.  This will increase the length of the
  * string by desc-\>annotations_len.
  * string by desc-\>annotations_len.
  *
  *
@@ -2020,6 +2021,14 @@ signed_descriptor_get_body(signed_descriptor_t *desc)
   return signed_descriptor_get_body_impl(desc, 0);
   return signed_descriptor_get_body_impl(desc, 0);
 }
 }
 
 
+/** As signed_descriptor_get_body(), but points to the beginning of the
+ * annotations section rather than the beginning of the descriptor. */
+const char *
+signed_descriptor_get_annotations(signed_descriptor_t *desc)
+{
+  return signed_descriptor_get_body_impl(desc, 1);
+}
+
 /** Return the current list of all known routers. */
 /** Return the current list of all known routers. */
 routerlist_t *
 routerlist_t *
 router_get_routerlist(void)
 router_get_routerlist(void)