"-----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.
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"
);
}
-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);
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");
/********************************* config.c ***************************/
+int config_assign_default_dirservers(void);
int getconfig(int argc, char **argv, or_options_t *options);
/********************************* connection.c ***************************/
/****************************************************************************/
/* 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,
/****************************************************************************/
-/* 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;