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

[or-cvs] Implement user-declared node families.



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

Modified Files:
	config.c or.h routerlist.c 
Log Message:
Implement user-declared node families.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- config.c	15 Oct 2004 19:18:08 -0000	1.172
+++ config.c	15 Oct 2004 20:52:09 -0000	1.173
@@ -245,6 +245,7 @@
       config_compare(list, "FascistFirewall",CONFIG_TYPE_BOOL, &options->FascistFirewall) ||
       config_compare(list, "FirewallPorts",CONFIG_TYPE_CSV, &options->FirewallPorts) ||
       config_compare(list, "MyFamily",      CONFIG_TYPE_STRING, &options->MyFamily) ||
+      config_compare(list, "NodeFamily",    CONFIG_TYPE_LINELIST, &options->NodeFamilies) ||
 
       config_compare(list, "Group",          CONFIG_TYPE_STRING, &options->Group) ||
 
@@ -477,6 +478,7 @@
   config_free_lines(options->SocksPolicy);
   config_free_lines(options->DirServers);
   config_free_lines(options->RecommendedVersions);
+  config_free_lines(options->NodeFamilies);
   if (options->FirewallPorts) {
     SMARTLIST_FOREACH(options->FirewallPorts, char *, cp, tor_free(cp));
     smartlist_free(options->FirewallPorts);
@@ -519,6 +521,7 @@
   options->FirewallPorts = NULL;
   options->DirServers = NULL;
   options->MyFamily = NULL;
+  options->NodeFamilies = NULL;
 }
 
 static char *
@@ -560,7 +563,7 @@
  * nicknames, or NULL. Return 0 on success. Warn and return -1 on failure.
  */
 static int check_nickname_list(const char *lst, const char *name)
-{ 
+{
   int r = 0;
   smartlist_t *sl;
 
@@ -576,7 +579,7 @@
       }
     });
   SMARTLIST_FOREACH(sl, char *, s, tor_free(s));
-  smartlist_free(sl); 
+  smartlist_free(sl);
   return r;
 }
 
@@ -876,7 +879,11 @@
     return -1;
   if (check_nickname_list(options->MyFamily, "MyFamily"))
     return -1;
-  
+  for (cl = options->NodeFamilies; cl; cl = cl->next) {
+    if (check_nickname_list(cl->value, "NodeFamily"))
+      return -1;
+  }
+
   clear_trusted_dir_servers();
   if (!options->DirServers) {
     add_default_trusted_dirservers();
@@ -890,7 +897,6 @@
   if (rend_config_services(options) < 0) {
     result = -1;
   }
-
   return result;
 }
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.435
retrieving revision 1.436
diff -u -d -r1.435 -r1.436
--- or.h	15 Oct 2004 19:04:37 -0000	1.435
+++ or.h	15 Oct 2004 20:52:09 -0000	1.436
@@ -859,7 +859,7 @@
   /** Local address to bind outbound sockets */
   char *OutboundBindAddress;
   struct config_line_t *RecommendedVersions;
-  /**< Directory server only: which versions of 
+  /**< Directory server only: which versions of
      * Tor should we tell users to run? */
   char *User; /**< Name of user to run Tor as. */
   char *Group; /**< Name of group to run Tor as. */
@@ -904,6 +904,8 @@
   struct config_line_t *DirServers; /**< List of configuration lines
                                      * for directory servers. */
   char *MyFamily; /**< Declared family for this OR. */
+  struct config_line_t *NodeFamilies; /**< List of config lines for
+                                       * node families */
 } or_options_t;
 
 /* XXX are these good enough defaults? */
@@ -1420,6 +1422,7 @@
 struct smartlist_t;
 void routerlist_add_family(struct smartlist_t *sl, routerinfo_t *router);
 void add_nickname_list_to_smartlist(struct smartlist_t *sl, const char *list, int warn_if_down);
+int router_nickname_is_in_list(routerinfo_t *router, const char *list);
 routerinfo_t *routerlist_find_my_routerinfo(void);
 int router_nickname_matches(routerinfo_t *router, const char *nickname);
 int router_is_unreliable_router(routerinfo_t *router, int need_uptime, int need_bw);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -d -r1.161 -r1.162
--- routerlist.c	15 Oct 2004 19:04:38 -0000	1.161
+++ routerlist.c	15 Oct 2004 20:52:09 -0000	1.162
@@ -248,10 +248,11 @@
  */
 void routerlist_add_family(smartlist_t *sl, routerinfo_t *router) {
   routerinfo_t *r;
+  struct config_line_t *cl;
 
   if (!router->declared_family)
     return;
-  
+
   /* Add every r such that router declares familyness with r, and r
    * declares familyhood with router. */
   SMARTLIST_FOREACH(router->declared_family, const char *, n,
@@ -266,6 +267,13 @@
             smartlist_add(sl, r);
         });
     });
+
+
+  for (cl = options.NodeFamilies; cl; cl = cl->next) {
+    if (router_nickname_is_in_list(router, cl->value)) {
+      add_nickname_list_to_smartlist(sl, cl->value, 0);
+    }
+  }
 }
 
 /** Given a comma-and-whitespace separated list of nicknames, see which
@@ -306,6 +314,26 @@
   smartlist_free(nickname_list);
 }
 
+/** Return 1 iff any member of the comma-separated list <b>list</b> is an
+ * acceptable nickname or hexdigest for <b>router</b>.  Else return 0.
+ */
+int
+router_nickname_is_in_list(routerinfo_t *router, const char *list)
+{
+  smartlist_t *nickname_list;
+  int v = 0;
+
+  tor_assert(router);
+  tor_assert(list);
+
+  nickname_list = smartlist_create();
+  smartlist_split_string(nickname_list, list, ",",
+                         SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+  SMARTLIST_FOREACH(nickname_list, char *, cp,
+                    if (router_nickname_matches(router, cp)) {v=1;break;});
+  return v;
+}
+
 /** Add every router from our routerlist that is currently running to
  * <b>sl</b>.
  */
@@ -405,7 +433,7 @@
 //    log_fn(LOG_INFO,"Recording bw %d for node %s.", this_bw, router->nickname);
   }
   if(!total_bw)
-    return NULL; 
+    return NULL;
   rand_bw = crypto_pseudo_rand_int(total_bw);
 //  log_fn(LOG_INFO,"Total bw %d. Randomly chose %d.", total_bw, rand_bw);
   tmp = 0;