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

[patch] network-status/[fast|valid|stable]



This allows you to specify the status of servers you want listed with getinfo. 
the ugly if statement is the only way I know how to implement it, but I'm 
sure there is a better way (which I'd like to learn), so any advice 
appreciated.

thanks,
robert
*** src/or/dirserv.c.old	2006-04-07 20:11:54.000000000 +0100
--- src/or/dirserv.c	2006-04-07 20:13:03.000000000 +0100
***************
*** 721,726 ****
--- 721,764 ----
    return 0;
  }
  
+ 
+ int
+ list_server_status_by_type(smartlist_t *routers, char **router_status_out, char *type)
+ {
+ 
+   if ((strcmp(type,"stable")) && (strcmp(type,"valid")) && (strcmp(type,"fast")))
+   	return -1;
+ 
+   /* 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;
+   time_t now = time(NULL);
+   time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
+   int authdir_mode = get_options()->AuthoritativeDir;
+   tor_assert(router_status_out);
+ 
+   rs_entries = smartlist_create();
+ 
+   SMARTLIST_FOREACH(routers, routerinfo_t *, ri,
+   {
+     if (authdir_mode) {
+       /* Update router status in routerinfo_t. */
+       ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
+     }
+     if (((ri->is_stable) && (!strcmp(type,"stable"))) ||
+      ((ri->is_valid) && (!strcmp(type,"valid"))) ||
+      ((ri->is_fast) && (!strcmp(type,"fast"))))
+       smartlist_add(rs_entries, list_single_server_status(ri, ri->is_running));
+   });
+ 
+   *router_status_out = smartlist_join_strings(rs_entries, " ", 0, NULL);
+ 
+   SMARTLIST_FOREACH(rs_entries, char *, cp, tor_free(cp));
+   smartlist_free(rs_entries);
+ 
+   return 0;
+ }
+ 
  /* Given a (possibly empty) list of config_line_t, each line of which contains
   * a list of comma-separated version numbers surrounded by optional space,
   * allocate and return a new string containing the version numbers, in order,
*** src/or/control.c.old	2006-04-07 20:13:17.000000000 +0100
--- src/or/control.c	2006-04-07 20:13:42.000000000 +0100
***************
*** 1355,1360 ****
--- 1355,1366 ----
          list_server_status(routerlist->routers, answer) < 0) {
        return -1;
      }
+   } else if (!strcmpstart(question, "network-status/")) {
+     routerlist_t *routerlist = router_get_routerlist();
+     if (!routerlist || !routerlist->routers ||
+         list_server_status_by_type(routerlist->routers, answer, question+strlen("network-status/")) < 0) {
+       return -1;
+     }
    } else if (!strcmp(question, "circuit-status")) {
      circuit_t *circ;
      smartlist_t *status = smartlist_create();
*** src/or/or.h.old	2006-04-07 20:13:59.000000000 +0100
--- src/or/or.h	2006-04-07 20:14:34.000000000 +0100
***************
*** 1914,1919 ****
--- 1914,1920 ----
  int dirserv_thinks_router_is_blatantly_unreachable(routerinfo_t *router,
                                                     time_t now);
  int list_server_status(smartlist_t *routers, char **router_status_out);
+ int list_server_status_by_type(smartlist_t *routers, char **router_status_out, char *type);
  int dirserv_dump_directory_to_string(char **dir_out,
                                       crypto_pk_env_t *private_key);
  void directory_set_dirty(void);