[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Remove controller getinfo support for "desc/all-ids".



Update of /home2/or/cvsroot/tor/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/or

Modified Files:
	control.c dirserv.c or.h 
Log Message:
Remove controller getinfo support for "desc/all-ids".
Replace it with getinfo "network-status" just like in directories.
This way the controller can learn which servers are running, which
are verified, etc.


Index: control.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- control.c	22 Mar 2005 00:42:38 -0000	1.59
+++ control.c	22 Mar 2005 03:27:51 -0000	1.60
@@ -538,37 +538,25 @@
   return 0;
 }
 
-static char *
-handle_getinfo_helper(const char *question)
+/** Lookup the 'getinfo' entry <b>question</b>, and return
+ * the answer in <b>*answer</b> (or NULL if key not recognized).
+ * Return 0 if success, or -1 if internal error. */
+static int
+handle_getinfo_helper(const char *question, char **answer)
 {
+  *answer = NULL; /* unrecognized key by default */
   if (!strcmp(question, "version")) {
-    return tor_strdup(VERSION);
+    *answer = tor_strdup(VERSION);
   } else if (!strcmpstart(question, "desc/id/")) {
     routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
-    if (!ri)
-      return NULL;
-    if (!ri->signed_descriptor)
-      return NULL;
-    return tor_strdup(ri->signed_descriptor);
-  } else if (!strcmp(question, "desc/all-ids")) {
-    routerlist_t *rl;
-    char *answer, *cp;
-    router_get_routerlist(&rl);
-    if (!rl)
-      return tor_strdup("");
-    answer = tor_malloc(smartlist_len(rl->routers)*(HEX_DIGEST_LEN+1)+1);
-    cp = answer;
-    SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
-    {
-      base16_encode(cp, HEX_DIGEST_LEN+1, r->identity_digest, DIGEST_LEN);
-      cp += HEX_DIGEST_LEN;
-      *cp++ = ',';
-    });
-    return answer;
+    if (ri && ri->signed_descriptor)
+      *answer = tor_strdup(ri->signed_descriptor);
+  } else if (!strcmp(question, "network-status")) {
+    if (list_server_status(NULL, answer) < 0)
+      return -1;
   } else if (!strcmpstart(question, "addr-mappings/")) {
     time_t min_e, max_e;
     smartlist_t *mappings;
-    char *answer;
     if (!strcmp(question, "addr-mappings/all")) {
       min_e = 0; max_e = TIME_MAX;
     } else if (!strcmp(question, "addr-mappings/cache")) {
@@ -578,18 +566,15 @@
     } else if (!strcmp(question, "addr-mappings/control")) {
       min_e = 1; max_e = 1;
     } else {
-      return NULL;
+      return 0;
     }
     mappings = smartlist_create();
     addressmap_get_mappings(mappings, min_e, max_e);
-    answer = smartlist_join_strings(mappings, "\n", 1, NULL);
+    *answer = smartlist_join_strings(mappings, "\n", 1, NULL);
     SMARTLIST_FOREACH(mappings, char *, cp, tor_free(cp));
     smartlist_free(mappings);
-    return answer;
-  } else {
-    /* unrecognized key */
-    return NULL;
   }
+  return 0;
 }
 
 static int
@@ -607,15 +592,16 @@
   msg_len = 0;
   SMARTLIST_FOREACH(questions, const char *, q,
   {
-    ans = handle_getinfo_helper(q);
-    if (!ans) {
+    if (handle_getinfo_helper(q, &ans) < 0) {
+      send_control_error(conn, ERR_INTERNAL, body);
+      goto done;
+    } if (!ans) {
       send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
       goto done;
-    } else {
-      smartlist_add(answers, tor_strdup(q));
-      smartlist_add(answers, ans);
-      msg_len += 2 + strlen(ans) + strlen(q);
     }
+    smartlist_add(answers, tor_strdup(q));
+    smartlist_add(answers, ans);
+    msg_len += 2 + strlen(ans) + strlen(q);
   });
 
   msg = smartlist_join_strings2(answers, "\0", 1, 1, &msg_len);

Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- dirserv.c	25 Feb 2005 20:46:13 -0000	1.143
+++ dirserv.c	22 Mar 2005 03:27:51 -0000	1.144
@@ -20,8 +20,6 @@
 static int the_directory_is_dirty = 1;
 static int runningrouters_is_dirty = 1;
 
-static int list_server_status(char **running_routers_out,
-                              char **router_status_out);
 static void directory_remove_unrecognized(void);
 static int dirserv_regenerate_directory(void);
 /* Should be static; exposed for testing */
@@ -515,7 +513,7 @@
  * and store them in *<b>running_routers_out</b> and *<b>router_status_out</b>
  * respectively.  Return 0 on success, -1 on failure.
  */
-static int
+int
 list_server_status(char **running_routers_out, char **router_status_out)
 {
   /* List of entries in running-routers style: An optional !, then either

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.564
retrieving revision 1.565
diff -u -d -r1.564 -r1.565
--- or.h	22 Mar 2005 01:01:15 -0000	1.564
+++ or.h	22 Mar 2005 03:27:51 -0000	1.565
@@ -1454,6 +1454,7 @@
 int dirserv_add_descriptor(const char **desc, const char **msg);
 int dirserv_load_from_directory_string(const char *dir);
 void dirserv_free_descriptors(void);
+int list_server_status(char **running_routers_out, char **router_status_out);
 void dirserv_remove_old_servers(int age);
 int dirserv_dump_directory_to_string(char **dir_out,
                                      crypto_pk_env_t *private_key);