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

[or-cvs] When it can"t resolve any dirservers, it was useless from t...



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

Modified Files:
	config.c or.h routerlist.c 
Log Message:
When it can't resolve any dirservers, it was useless from then on.
Now it reloads the RouterFile (or default dirservers) if it has no
dirservers.


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- config.c	26 Feb 2004 21:25:50 -0000	1.83
+++ config.c	26 Feb 2004 22:56:36 -0000	1.84
@@ -298,6 +298,14 @@
 "-----END SIGNATURE-----\n"
 ;
 
+int config_assign_default_dirservers(void) {
+  if(router_set_routerlist_from_string(default_dirservers_string) < 0) {
+    log_fn(LOG_WARN,"Bug: the default dirservers internal string is corrupt.");
+    return -1;
+  }
+  return 0;
+}
+
 /* Call this function when they're using the default torrc but
  * we can't find it. For now, just hard-code what comes in the
  * default torrc.
@@ -308,16 +316,13 @@
   options->SocksPort = 9050;
 
   /* plus give them a dirservers file */
-  if(router_set_routerlist_from_string(default_dirservers_string) < 0) {
-    log_fn(LOG_WARN,"Bug: the default dirservers internal string is corrupt.");
+  if(config_assign_default_dirservers() < 0)
     return -1;
-  }
-
   return 0;
 }
 
 /* prints the usage of tor. */
-void print_usage(void) {
+static void print_usage(void) {
   printf("tor -f <torrc> [args]\n"
          "See man page for more options.\n\n"
          "-b <bandwidth>\t\tbytes/second rate limiting\n"
@@ -336,7 +341,7 @@
          );
 }
 
-void free_options(or_options_t *options) {
+static void free_options(or_options_t *options) {
   tor_free(options->LogLevel);
   tor_free(options->LogFile);
   tor_free(options->DebugLogFile);
@@ -357,7 +362,7 @@
   tor_free(options->Group);
 }
 
-void init_options(or_options_t *options) {
+static void init_options(or_options_t *options) {
 /* give reasonable values for each option. Defaults to zero. */
   memset(options,0,sizeof(or_options_t));
   options->LogLevel = tor_strdup("warn");

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -d -r1.229 -r1.230
--- or.h	26 Feb 2004 22:02:22 -0000	1.229
+++ or.h	26 Feb 2004 22:56:36 -0000	1.230
@@ -622,6 +622,7 @@
 
 /********************************* config.c ***************************/
 
+int config_assign_default_dirservers(void);
 int getconfig(int argc, char **argv, or_options_t *options);
 
 /********************************* connection.c ***************************/

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- routerlist.c	26 Feb 2004 21:25:51 -0000	1.27
+++ routerlist.c	26 Feb 2004 22:56:36 -0000	1.28
@@ -65,6 +65,8 @@
 /****************************************************************************/
 
 /* static function prototypes */
+static routerinfo_t *
+router_pick_directory_server_impl(void);
 static int
 router_get_list_from_string_impl(const char **s, routerlist_t **dest,
                                  int n_good_nicknames,
@@ -93,8 +95,29 @@
 
 /****************************************************************************/
 
-/* pick a random running router with a positive dir_port */
+/* try to find a running dirserver. if there are no dirservers
+ * in our routerlist, reload the routerlist and try again. */
 routerinfo_t *router_pick_directory_server(void) {
+  routerinfo_t *choice;
+
+  choice = router_pick_directory_server_impl();
+  if(!choice) {
+    log_fn(LOG_WARN,"No dirservers known. Reloading and trying again.");
+    if(options.RouterFile) {
+      if(router_set_routerlist_from_file(options.RouterFile) < 0)
+        return NULL;
+    } else {
+      if(config_assign_default_dirservers() < 0)
+        return NULL;
+    }
+    /* give it another try */
+    choice = router_pick_directory_server_impl();
+  }
+  return choice;
+}
+
+/* pick a random running router with a positive dir_port */
+static routerinfo_t *router_pick_directory_server_impl(void) {
   int i;
   routerinfo_t *router, *dirserver=NULL;
   smartlist_t *sl;