summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-02-26 22:56:36 +0000
committerRoger Dingledine <arma@torproject.org>2004-02-26 22:56:36 +0000
commitd3e9afda272b672ebbc15d7f26ea517c7e8a4e35 (patch)
treecc31553d1752d6f51901b2777100a76505b7417d
parent4c48359eceb38670269ab78dbb9fa79f714c2f7e (diff)
downloadtor-d3e9afda272b672ebbc15d7f26ea517c7e8a4e35.tar.gz
tor-d3e9afda272b672ebbc15d7f26ea517c7e8a4e35.zip
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. svn:r1130
-rw-r--r--src/or/config.c19
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerlist.c25
3 files changed, 37 insertions, 8 deletions
diff --git a/src/or/config.c b/src/or/config.c
index e3ee6a5e28..6017847cdf 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -298,6 +298,14 @@ const char default_dirservers_string[] =
"-----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 @@ static int config_assign_default(or_options_t *options) {
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 print_usage(void) {
);
}
-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 @@ void free_options(or_options_t *options) {
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");
diff --git a/src/or/or.h b/src/or/or.h
index f34d57a133..3aff946379 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -622,6 +622,7 @@ extern unsigned long stats_n_destroy_cells_processed;
/********************************* config.c ***************************/
+int config_assign_default_dirservers(void);
int getconfig(int argc, char **argv, or_options_t *options);
/********************************* connection.c ***************************/
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 75674849c5..42d4f4480d 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -65,6 +65,8 @@ typedef struct directory_token_t {
/****************************************************************************/
/* 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 @@ router_release_token(directory_token_t *tok);
/****************************************************************************/
-/* 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;