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

[or-cvs] Make GETINFO for "network-status" work on non-authdirs



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv4716/src/or

Modified Files:
	control.c dirserv.c or.h 
Log Message:
Make GETINFO for "network-status" work on non-authdirs

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- control.c	23 Mar 2005 08:40:10 -0000	1.64
+++ control.c	23 Mar 2005 19:15:10 -0000	1.65
@@ -561,8 +561,12 @@
     if (ri && ri->signed_descriptor)
       *answer = tor_strdup(ri->signed_descriptor);
   } else if (!strcmp(question, "network-status")) {
-    if (list_server_status(NULL, answer) < 0)
+    routerlist_t *routerlist;
+    router_get_routerlist(&routerlist);
+    if (!routerlist || !routerlist->routers ||
+        list_server_status(routerlist->routers, NULL, answer) < 0) {
       return -1;
+    }
   } else if (!strcmpstart(question, "addr-mappings/")) {
     time_t min_e, max_e;
     smartlist_t *mappings;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- dirserv.c	23 Mar 2005 08:40:10 -0000	1.147
+++ dirserv.c	23 Mar 2005 19:15:10 -0000	1.148
@@ -509,12 +509,14 @@
   return tor_strdup(buf);
 }
 
-/** Allocate the contents of a running-routers line and a router-status line,
- * and store them in *<b>running_routers_out</b> and *<b>router_status_out</b>
- * respectively.  Return 0 on success, -1 on failure.
+/** Based on the routerinfo_ts in <b>routers</b>, allocate the
+ * contents of a running-routers line and a router-status line, and
+ * store them in *<b>running_routers_out</b> and
+ * *<b>router_status_out</b> respectively.  If either is NULL, skip
+ * it.  Return 0 on success, -1 on failure.
  */
 int
-list_server_status(char **running_routers_out, char **router_status_out)
+list_server_status(smartlist_t *routers, char **running_routers_out, char **router_status_out)
 {
   /* List of entries in running-routers style: An optional !, then either
    * a nickname or a dollar-prefixed hexdigest. */
@@ -522,26 +524,32 @@
   /* List of entries in a router-status style: An optional !, then an optional
    * equals-suffixed nickname, then a dollar-prefixed hexdigest. */
   smartlist_t *rs_entries;
-
+  /* XXXX Really, we should merge descriptor_list into routerlist.  But
+   * this is potentially tricky, since the semantics of the two lists
+   * are not quite the same.  In any case, it's not for the 0.1.0.x
+   * series.
+   */
+  int authdir_mode = get_options()->AuthoritativeDir;
   tor_assert(running_routers_out || router_status_out);
 
   rr_entries = smartlist_create();
   rs_entries = smartlist_create();
 
-  if (!descriptor_list)
-    descriptor_list = smartlist_create();
-
-  SMARTLIST_FOREACH(descriptor_list, routerinfo_t *, ri,
+  SMARTLIST_FOREACH(routers, routerinfo_t *, ri,
   {
     int is_live;
     connection_t *conn;
     conn = connection_get_by_identity_digest(
                     ri->identity_digest, CONN_TYPE_OR);
-    /* Treat a router as alive if
-     *    - It's me, and I'm not hibernating.
-     * or - we're connected to it. */
-    is_live = (router_is_me(ri) && !we_are_hibernating()) ||
-      (conn && conn->state == OR_CONN_STATE_OPEN);
+    if (authdir_mode) {
+      /* Treat a router as alive if
+       *    - It's me, and I'm not hibernating.
+       * or - we're connected to it. */
+      is_live = (router_is_me(ri) && !we_are_hibernating()) ||
+        (conn && conn->state == OR_CONN_STATE_OPEN);
+    } else {
+      is_live = ri->is_running;
+    }
     smartlist_add(rr_entries, list_single_server_status(ri, is_live, 1));
     smartlist_add(rs_entries, list_single_server_status(ri, is_live, 0));
   });
@@ -610,7 +618,7 @@
   if (!descriptor_list)
     descriptor_list = smartlist_create();
 
-  if (list_server_status(&running_routers, &router_status))
+  if (list_server_status(descriptor_list, &running_routers, &router_status))
     return -1;
 
   /* ASN.1-encode the public key.  This is a temporary measure; once
@@ -869,7 +877,10 @@
   time_t published_on;
   char *identity_pkey; /* Identity key, DER64-encoded. */
 
-  if (list_server_status(NULL, &router_status)) {
+  if (!descriptor_list)
+    descriptor_list = smartlist_create();
+
+  if (list_server_status(descriptor_list, NULL, &router_status)) {
     goto err;
   }
   /* ASN.1-encode the public key.  This is a temporary measure; once

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.571
retrieving revision 1.572
diff -u -d -r1.571 -r1.572
--- or.h	23 Mar 2005 08:40:11 -0000	1.571
+++ or.h	23 Mar 2005 19:15:10 -0000	1.572
@@ -1460,7 +1460,8 @@
 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);
+int list_server_status(smartlist_t *routers,
+                       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);