diff options
author | Roger Dingledine <arma@torproject.org> | 2003-12-05 09:51:49 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-12-05 09:51:49 +0000 |
commit | e0952d07735c60cbe420cec74b7e95c8d3eb61f0 (patch) | |
tree | c670f9c9f7c7c81cbdc30978669861fc765b85ea /src | |
parent | 727a260a81f7313d391fc95bebf21bcf745d5294 (diff) | |
download | tor-e0952d07735c60cbe420cec74b7e95c8d3eb61f0.tar.gz tor-e0952d07735c60cbe420cec74b7e95c8d3eb61f0.zip |
terminology shift:
directory is the string that dirserv.c and directory.c deal with
routerlist is routerinfo's that are bundled together in routers.c
rename some of the get_routerlist functions to set_routerlist
preparing to break into router.c for stuff the router does,
and routerlist.c for handling routerlist.
svn:r886
Diffstat (limited to 'src')
-rw-r--r-- | src/or/directory.c | 4 | ||||
-rw-r--r-- | src/or/dirserv.c | 4 | ||||
-rw-r--r-- | src/or/main.c | 51 | ||||
-rw-r--r-- | src/or/onion.c | 6 | ||||
-rw-r--r-- | src/or/or.h | 9 | ||||
-rw-r--r-- | src/or/routers.c | 194 | ||||
-rw-r--r-- | src/or/test.c | 2 |
7 files changed, 136 insertions, 134 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 039ebb7ced..e4ab0ebe55 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -13,6 +13,8 @@ extern or_options_t options; /* command-line and config-file options */ static char fetchstring[] = "GET / HTTP/1.0\r\n\r\n"; static char answerstring[] = "HTTP/1.0 200 OK\r\n\r\n"; +/* XXX the_directory is the same name as a different variable in· + * dirserv.c, are you crazy?? */ static char the_directory[MAX_DIR_SIZE+1]; static int directorylen=0; @@ -120,7 +122,7 @@ int connection_dir_process_inbuf(connection_t *conn) { log_fn(LOG_INFO,"Empty directory. Ignoring."); return -1; } - if(router_get_dir_from_string(the_directory, conn->identity_pkey) < 0){ + if(router_set_routerlist_from_directory(the_directory, conn->identity_pkey) < 0){ log_fn(LOG_INFO,"...but parsing failed. Ignoring."); } else { log_fn(LOG_INFO,"updated routers."); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 42f1d57fa4..ab46d16d73 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -10,6 +10,8 @@ extern or_options_t options; /* command-line and config-file options */ static int the_directory_is_dirty = 1; +/* XXX the_directory is the same name as a different variable in + * directory.c, are you crazy?? */ static char *the_directory = NULL; static int the_directory_len = -1; @@ -448,7 +450,7 @@ size_t dirserv_get_directory(const char **directory) * necessary, but safe is better than sorry. */ new_directory = tor_strdup(the_directory); /* use a new copy of the dir, since get_dir_from_string scribbles on it */ - if (router_get_dir_from_string(new_directory, get_identity_key())) { + if (router_set_routerlist_from_directory(new_directory, get_identity_key())) { log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying."); exit(0); } diff --git a/src/or/main.c b/src/or/main.c index 1e82ed1493..581f83d90c 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -84,7 +84,7 @@ int connection_add(connection_t *conn) { log(LOG_WARN,"connection_add(): failing because nfds is too high."); return -1; } - + conn->poll_index = nfds; connection_set_poll_socket(conn); connection_array[nfds] = conn; @@ -125,17 +125,17 @@ int connection_remove(connection_t *conn) { if(current_index == nfds-1) { /* this is the end */ nfds--; return 0; - } + } /* we replace this one with the one at the end, then free it */ nfds--; - poll_array[current_index].fd = poll_array[nfds].fd; + poll_array[current_index].fd = poll_array[nfds].fd; poll_array[current_index].events = poll_array[nfds].events; poll_array[current_index].revents = poll_array[nfds].revents; connection_array[current_index] = connection_array[nfds]; connection_array[current_index]->poll_index = current_index; - return 0; + return 0; } void get_connection_array(connection_t ***array, int *n) { @@ -196,7 +196,7 @@ static void conn_read(int i) { return; /* this conn should not read */ log_fn(LOG_DEBUG,"socket %d wants to read.",conn->s); - + assert_connection_ok(conn, time(NULL)); if( @@ -207,10 +207,12 @@ static void conn_read(int i) { connection_handle_read(conn) < 0) { /* this connection is broken. remove it */ - log_fn(LOG_INFO,"%s connection broken, removing.", conn_type_to_string[conn->type]); + log_fn(LOG_INFO,"%s connection broken, removing.", + conn_type_to_string[conn->type]); connection_remove(conn); connection_free(conn); - if(i<nfds) { /* we just replaced the one at i with a new one. process it too. */ + if(i<nfds) { + /* we just replaced the one at i with a new one. process it too. */ conn_read(i); } } else assert_connection_ok(conn, time(NULL)); @@ -270,6 +272,7 @@ static void conn_close_if_marked(int i) { static void run_connection_housekeeping(int i, time_t now) { cell_t cell; connection_t *conn = connection_array[i]; + if(connection_receiver_bucket_should_increase(conn)) { conn->receiver_bucket += conn->bandwidth; // log_fn(LOG_DEBUG,"Receiver bucket %d now %d.", i, conn->receiver_bucket); @@ -286,7 +289,7 @@ static void run_connection_housekeeping(int i, time_t now) { connection_start_writing(conn); } } - + /* check connections to see whether we should send a keepalive, expire, or wait */ if(!connection_speaks_cells(conn)) return; @@ -336,7 +339,7 @@ static void run_scheduled_events(time_t now) { } /* 2. Every second, we examine pending circuits and prune the - * ones which have been pending for more than 2 seconds. + * ones which have been pending for more than 3 seconds. * We do this before step 3, so it can try building more if * it's not comfortable with the number of available circuits. */ @@ -372,7 +375,7 @@ static void run_scheduled_events(time_t now) { } } - /* 4. Every second, we check how much bandwidth we've consumed and + /* 4. Every second, we check how much bandwidth we've consumed and * increment global_read_bucket. */ stats_n_bytes_read += stats_prev_global_read_bucket-global_read_bucket; @@ -462,7 +465,7 @@ static crypto_pk_env_t *init_key_from_file(const char *fname) goto error; } return prkey; - default: + default: assert(0); } @@ -479,7 +482,7 @@ static crypto_pk_env_t *init_key_from_file(const char *fname) static int init_keys(void) { char keydir[512]; - char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3]; + char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3]; char *cp; const char *tmp, *mydesc; crypto_pk_env_t *prkey; @@ -506,7 +509,7 @@ static int init_keys(void) return -1; } cp = keydir + strlen(keydir); /* End of string. */ - + /* 1. Read identity key. Make it if none is found. */ strcpy(cp, "/identity.key"); log_fn(LOG_INFO,"Reading/making identity key %s...",keydir); @@ -519,7 +522,7 @@ static int init_keys(void) prkey = init_key_from_file(keydir); if (!prkey) return -1; set_onion_key(prkey); - + /* 3. Initialize link key and TLS context. */ strcpy(cp, "/link.key"); log_fn(LOG_INFO,"Reading/making link key %s...",keydir); @@ -638,9 +641,9 @@ static int do_main_loop(void) { int i; int timeout; int poll_result; - + /* load the routers file */ - if(router_get_list_from_file(options.RouterFile) < 0) { + if(router_set_routerlist_from_file(options.RouterFile) < 0) { log_fn(LOG_ERR,"Error loading router list."); return -1; } @@ -681,21 +684,21 @@ static int do_main_loop(void) { exit(1); } - /* fetch a new directory */ if(options.DirPort) { - /* reload the fingerprint file */ - char keydir[512]; + char keydir[512]; sprintf(keydir,"%s/approved-routers", options.DataDirectory); log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir); if(dirserv_parse_fingerprint_file(keydir) < 0) { log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list."); } - if(router_get_list_from_file(options.RouterFile) < 0) { + /* XXX do we really want to be resetting the routerlist here? */ + if(router_set_routerlist_from_file(options.RouterFile) < 0) { log(LOG_WARN,"Error reloading router list. Continuing with old list."); } } else { + /* fetch a new directory */ directory_initiate_command(router_pick_directory_server(), DIR_CONN_STATE_CONNECTING_FETCH); } @@ -732,7 +735,7 @@ static int do_main_loop(void) { /* any of the conns need to be closed now? */ for(i=0;i<nfds;i++) - conn_close_if_marked(i); + conn_close_if_marked(i); /* refilling buckets and sending cells happens at the beginning of the * next iteration of the loop, inside prepare_for_poll() @@ -807,13 +810,13 @@ static void dumpstats(int severity) { stats_n_destroy_cells_processed); if (stats_n_data_cells_packaged) log(severity,"Average outgoing cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_packaged) / + 100*(((double)stats_n_data_bytes_packaged) / (stats_n_data_cells_packaged*(CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE))) ); if (stats_n_data_cells_received) log(severity,"Average incoming cell fullness: %2.3f%%", - 100*(((double)stats_n_data_bytes_received) / + 100*(((double)stats_n_data_bytes_received) / (stats_n_data_cells_received*(CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE))) ); - + if (stats_n_seconds_reading) log(severity,"Average bandwidth used: %d bytes/sec", (int) (stats_n_bytes_read/stats_n_seconds_reading)); diff --git a/src/or/onion.c b/src/or/onion.c index 0f67d37ebd..168a41387b 100644 --- a/src/or/onion.c +++ b/src/or/onion.c @@ -221,7 +221,7 @@ static int new_route_len(double cw, routerinfo_t **rarray, int rarray_len) { return routelen; } -static routerinfo_t *choose_good_exit_server(directory_t *dir) +static routerinfo_t *choose_good_exit_server(routerlist_t *dir) { int *n_supported; int *n_maybe_supported; @@ -383,12 +383,12 @@ static routerinfo_t *choose_good_exit_server(directory_t *dir) } cpath_build_state_t *onion_new_cpath_build_state(void) { - directory_t *dir; + routerlist_t *dir; int r; cpath_build_state_t *info; routerinfo_t *exit; - router_get_directory(&dir); + router_get_routerlist(&dir); r = new_route_len(options.PathlenCoinWeight, dir->routers, dir->n_routers); if (r < 0) return NULL; diff --git a/src/or/or.h b/src/or/or.h index 6d75007206..96d9b5abfc 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -363,7 +363,7 @@ typedef struct { int n_routers; char *software_versions; time_t published_on; -} directory_t; +} routerlist_t; struct crypt_path_t { @@ -737,7 +737,7 @@ void router_upload_desc_to_dirservers(void); routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port); routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk); routerinfo_t *router_get_by_nickname(char *nickname); -void router_get_directory(directory_t **pdirectory); +void router_get_directory(routerlist_t **pdirectory); void router_mark_as_down(char *nickname); int router_get_list_from_file(char *routerfile); int router_get_router_hash(char *s, char *digest); @@ -746,11 +746,11 @@ int router_get_dir_hash(char *s, char *digest); /* Reads a list of known routers, unsigned. */ int router_get_list_from_string(char *s); /* Exported for debugging */ -int router_get_list_from_string_impl(char **s, directory_t **dest, int n_good_nicknames, const char *good_nickname_lst[]); +int router_get_list_from_string_impl(char **s, routerlist_t **dest, int n_good_nicknames, const char *good_nickname_lst[]); /* Reads a signed directory. */ int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey); /* Exported or debugging */ -int router_get_dir_from_string_impl(char *s, directory_t **dest, +int router_get_dir_from_string_impl(char *s, routerlist_t **dest, crypto_pk_env_t *pkey); routerinfo_t *router_get_entry_from_string(char **s); int router_supports_exit_address(uint32_t addr, uint16_t port, @@ -761,7 +761,6 @@ int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port, void routerinfo_free(routerinfo_t *router); int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router, crypto_pk_env_t *ident_key); -const routerinfo_t *router_get_desc_routerinfo(void); int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port); int router_exit_policy_rejects_all(routerinfo_t *router); const char *router_get_my_descriptor(void); diff --git a/src/or/routers.c b/src/or/routers.c index 1c83120c1a..ccaa7f72ec 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -16,7 +16,7 @@ /****************************************************************************/ -static directory_t *directory = NULL; /* router array */ +static routerlist_t *routerlist = NULL; /* router array */ static routerinfo_t *desc_routerinfo = NULL; /* my descriptor */ static char descriptor[8192]; /* string representation of my descriptor */ @@ -28,11 +28,10 @@ struct directory_token; typedef struct directory_token directory_token_t; /* static function prototypes */ -void routerlist_free(routerinfo_t *list); static int router_add_exit_policy_from_string(routerinfo_t *router, char *s); static int router_add_exit_policy(routerinfo_t *router, directory_token_t *tok); -static int router_resolve_directory(directory_t *dir); +static int router_resolve_routerlist(routerlist_t *dir); /****************************************************************************/ @@ -40,9 +39,10 @@ void router_retry_connections(void) { int i; routerinfo_t *router; - for (i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; - if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { /* not in the list */ + for (i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; + if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { + /* not in the list */ log_fn(LOG_DEBUG,"connecting to OR %s:%u.",router->address,router->or_port); connection_or_connect(router); } @@ -55,11 +55,11 @@ routerinfo_t *router_pick_directory_server(void) { routerinfo_t *router, *dirserver=NULL; int num_dirservers=0; - if(!directory) + if(!routerlist) return NULL; - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if(router->dir_port > 0 && router->is_running) num_dirservers++; } @@ -68,8 +68,8 @@ routerinfo_t *router_pick_directory_server(void) { log_fn(LOG_INFO,"No dirservers are reachable. Trying them all again."); /* no running dir servers found? go through and mark them all as up, * and we'll cycle through the list again. */ - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if(router->dir_port > 0) { router->is_running = 1; dirserver = router; @@ -79,8 +79,8 @@ routerinfo_t *router_pick_directory_server(void) { } j = crypto_pseudo_rand_int(num_dirservers); - for (i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for (i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if (router->dir_port > 0 && router->is_running) { if (j) --j; @@ -98,11 +98,11 @@ routerinfo_t *router_pick_randomly_from_running(void) { int i,j; int num_running=0; - if(!directory) + if(!routerlist) return NULL; - for(i=0;i<directory->n_routers;i++) { - if(directory->routers[i]->is_running) + for(i=0;i<routerlist->n_routers;i++) { + if(routerlist->routers[i]->is_running) num_running++; } @@ -111,13 +111,13 @@ routerinfo_t *router_pick_randomly_from_running(void) { return NULL; } j = crypto_pseudo_rand_int(num_running); - for (i=0;i<directory->n_routers;i++) { - if (directory->routers[i]->is_running) { + for (i=0;i<routerlist->n_routers;i++) { + if (routerlist->routers[i]->is_running) { if (j) --j; else { - log_fn(LOG_DEBUG, "Chose server '%s'", directory->routers[i]->nickname); - return directory->routers[i]; + log_fn(LOG_DEBUG, "Chose server '%s'", routerlist->routers[i]->nickname); + return routerlist->routers[i]; } } } @@ -129,7 +129,7 @@ void router_upload_desc_to_dirservers(void) { int i; routerinfo_t *router; - if(!directory) + if(!routerlist) return; if (!router_get_my_descriptor()) { @@ -137,8 +137,8 @@ void router_upload_desc_to_dirservers(void) { return; } - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if(router->dir_port > 0) directory_initiate_command(router, DIR_CONN_STATE_CONNECTING_UPLOAD); } @@ -148,10 +148,10 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { int i; routerinfo_t *router; - assert(directory); + assert(routerlist); - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if ((router->addr == addr) && (router->or_port == port)) return router; } @@ -163,10 +163,10 @@ routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk) int i; routerinfo_t *router; - assert(directory); + assert(routerlist); - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if (0 == crypto_pk_cmp_keys(router->link_pkey, pk)) return router; } @@ -178,25 +178,26 @@ routerinfo_t *router_get_by_nickname(char *nickname) int i; routerinfo_t *router; - assert(directory); + assert(routerlist); - for(i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for(i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if (0 == strcmp(router->nickname, nickname)) return router; } return NULL; } -void router_get_directory(directory_t **pdirectory) { - *pdirectory = directory; +/* a way to access routerlist outside this file */ +void router_get_routerlist(routerlist_t **prouterlist) { + *prouterlist = routerlist; } /* delete a router from memory */ void routerinfo_free(routerinfo_t *router) { struct exit_policy_t *e; - + if (!router) return; @@ -217,14 +218,14 @@ void routerinfo_free(routerinfo_t *router) free(router); } -void directory_free(directory_t *dir) +void routerlist_free(routerlist_t *rl) { int i; - for (i = 0; i < dir->n_routers; ++i) - routerinfo_free(dir->routers[i]); - tor_free(dir->routers); - tor_free(dir->software_versions); - free(dir); + for (i = 0; i < rl->n_routers; ++i) + routerinfo_free(rl->routers[i]); + tor_free(rl->routers); + tor_free(rl->software_versions); + free(rl); } void router_mark_as_down(char *nickname) { @@ -236,7 +237,7 @@ void router_mark_as_down(char *nickname) { } /* load the router list */ -int router_get_list_from_file(char *routerfile) +int router_set_routerlist_from_file(char *routerfile) { char *string; @@ -246,7 +247,7 @@ int router_get_list_from_file(char *routerfile) return -1; } - if(router_get_list_from_string(string) < 0) { + if(router_set_routerlist_from_string(string) < 0) { log_fn(LOG_WARN,"The routerfile itself was corrupt."); free(string); return -1; @@ -256,13 +257,12 @@ int router_get_list_from_file(char *routerfile) return 0; } - typedef enum { K_ACCEPT, K_DIRECTORY_SIGNATURE, K_RECOMMENDED_SOFTWARE, - K_REJECT, - K_ROUTER, + K_REJECT, + K_ROUTER, K_SIGNED_DIRECTORY, K_SIGNING_KEY, K_ONION_KEY, @@ -271,10 +271,10 @@ typedef enum { K_PUBLISHED, K_RUNNING_ROUTERS, K_PLATFORM, - _SIGNATURE, - _PUBLIC_KEY, - _ERR, - _EOF + _SIGNATURE, + _PUBLIC_KEY, + _ERR, + _EOF } directory_keyword; struct token_table_ent { char *t; int v; }; @@ -301,7 +301,7 @@ struct directory_token { directory_keyword tp; union { struct { - char *args[MAX_ARGS+1]; + char *args[MAX_ARGS+1]; int n_args; } cmd; char *signature; @@ -471,21 +471,23 @@ router_get_next_token(char **s, directory_token_t *tok) { #define router_get_next_token _router_get_next_token #endif -int router_get_list_from_string(char *s) +/* read routerinfo elements from s, and throw out the ones that + * don't parse and resolve. */ +int router_set_routerlist_from_string(char *s) { - if (router_get_list_from_string_impl(&s, &directory, -1, NULL)) { + if (router_get_list_from_string_impl(&s, &routerlist, -1, NULL)) { log(LOG_WARN, "Error parsing router file"); return -1; } - if (router_resolve_directory(directory)) { - log(LOG_WARN, "Error resolving directory"); + if (router_resolve_routerlist(routerlist)) { + log(LOG_WARN, "Error resolving routerlist"); return -1; } return 0; } static int router_get_hash_impl(char *s, char *digest, const char *start_str, - const char *end_str) + const char *end_str) { char *start, *end; start = strstr(s, start_str); @@ -504,7 +506,7 @@ static int router_get_hash_impl(char *s, char *digest, const char *start_str, return -1; } ++end; - + if (crypto_SHA_digest(start, end-start, digest)) { log_fn(LOG_WARN,"couldn't compute digest"); return -1; @@ -535,29 +537,30 @@ int compare_recommended_versions(char *myversion, char *start) { for(;;) { comma = strchr(start, ','); if( ((comma ? comma : end) - start == len_myversion) && - !strncmp(start, myversion, len_myversion)) /* only do strncmp if the length matches */ - return 0; /* success, it's there */ + !strncmp(start, myversion, len_myversion)) + /* only do strncmp if the length matches */ + return 0; /* success, it's there */ if(!comma) return -1; /* nope */ start = comma+1; } } -int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey) +int router_set_routerlist_from_directory(char *s, crypto_pk_env_t *pkey) { - if (router_get_dir_from_string_impl(s, &directory, pkey)) { + if (router_get_routerlist_from_directory_impl(s, &routerlist, pkey)) { log_fn(LOG_WARN, "Couldn't parse directory."); return -1; } - if (router_resolve_directory(directory)) { - log_fn(LOG_WARN, "Error resolving directory"); + if (router_resolve_routerlist(routerlist)) { + log_fn(LOG_WARN, "Error resolving routerlist"); return -1; } - if (compare_recommended_versions(VERSION, directory->software_versions) < 0) { + if (compare_recommended_versions(VERSION, routerlist->software_versions) < 0) { log(options.IgnoreVersion ? LOG_WARN : LOG_ERR, "You are running Tor version %s, which is not recommended.\n" "Please upgrade to one of %s.", - VERSION, directory->software_versions); + VERSION, routerlist->software_versions); if(options.IgnoreVersion) { log(LOG_WARN, "IgnoreVersion is set. If it breaks, we told you so."); } else { @@ -569,13 +572,13 @@ int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey) return 0; } -int router_get_dir_from_string_impl(char *s, directory_t **dest, - crypto_pk_env_t *pkey) +int router_get_routerlist_from_directory_impl(char *s, routerlist_t **dest, + crypto_pk_env_t *pkey) { directory_token_t tok; char digest[20]; char signed_digest[128]; - directory_t *new_dir = NULL; + routerlist_t *new_dir = NULL; char *versions; struct tm published; time_t published_on; @@ -666,21 +669,21 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest, TOK_IS(_EOF, "end of directory"); if (*dest) - directory_free(*dest); + routerlist_free(*dest); *dest = new_dir; return 0; err: if (new_dir) - directory_free(new_dir); + routerlist_free(new_dir); return -1; #undef NEXT_TOK #undef TOK_IS } -int router_get_list_from_string_impl(char **s, directory_t **dest, - int n_good_nicknames, +int router_get_list_from_string_impl(char **s, routerlist_t **dest, + int n_good_nicknames, const char **good_nickname_lst) { routerinfo_t *router; @@ -725,15 +728,15 @@ int router_get_list_from_string_impl(char **s, directory_t **dest, } if (*dest) - directory_free(*dest); - *dest = (directory_t *)tor_malloc(sizeof(directory_t)); + routerlist_free(*dest); + *dest = (routerlist_t *)tor_malloc(sizeof(routerlist_t)); (*dest)->routers = rarray; (*dest)->n_routers = rarray_len; (*dest)->software_versions = NULL; return 0; } -static int +static int router_resolve(routerinfo_t *router) { struct hostent *rent; @@ -750,38 +753,38 @@ router_resolve(routerinfo_t *router) return 0; } -static int -router_resolve_directory(directory_t *dir) +static int +router_resolve_routerlist(routerlist_t *rl) { int i, max, remove; - if (!dir) - dir = directory; + if (!rl) + rl = routerlist; - max = dir->n_routers; + max = rl->n_routers; for (i = 0; i < max; ++i) { remove = 0; - if (router_resolve(dir->routers[i])) { + if (router_resolve(rl->routers[i])) { log_fn(LOG_WARN, "Couldn't resolve router %s; not using", - dir->routers[i]->address); + rl->routers[i]->address); remove = 1; } else if (options.Nickname && - !strcmp(dir->routers[i]->nickname, options.Nickname)) { + !strcmp(rl->routers[i]->nickname, options.Nickname)) { remove = 1; } if (remove) { - routerinfo_free(dir->routers[i]); - dir->routers[i] = dir->routers[--max]; - --dir->n_routers; + routerinfo_free(rl->routers[i]); + rl->routers[i] = rl->routers[--max]; + --rl->n_routers; --i; } } - + return 0; } /* reads a single router entry from s. * updates s so it points to after the router it just read. - * mallocs a new router, returns it if all goes well, else returns NULL. + * mallocs a new router and returns it if all goes well, else returns NULL. */ routerinfo_t *router_get_entry_from_string(char**s) { routerinfo_t *router = NULL; @@ -1008,7 +1011,7 @@ router_add_exit_policy_from_string(routerinfo_t *router, return r; } -static int router_add_exit_policy(routerinfo_t *router, +static int router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { struct exit_policy_t *tmpe, *newe; struct in_addr in; @@ -1071,7 +1074,7 @@ static int router_add_exit_policy(routerinfo_t *router, } if (strcmp(port, "*") == 0) { newe->prt = 0; - } else { + } else { endptr = NULL; newe->prt = strtol(port, &endptr, 10); if (*endptr) { @@ -1190,8 +1193,8 @@ int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port) { int i; routerinfo_t *router; - for (i=0;i<directory->n_routers;i++) { - router = directory->routers[i]; + for (i=0;i<routerlist->n_routers;i++) { + router = routerlist->routers[i]; if (router->is_running && router_compare_addr_to_exit_policy(addr, port, router->exit_policy) >= 0) return 0; /* this one could be ok. good enough. */ @@ -1214,13 +1217,6 @@ const char *router_get_my_descriptor(void) { log_fn(LOG_DEBUG,"my desc is '%s'",descriptor); return descriptor; } -const routerinfo_t *router_get_desc_routerinfo(void) { - if (!desc_routerinfo) { - if (router_rebuild_descriptor()) - return NULL; - } - return desc_routerinfo; -} int router_rebuild_descriptor(void) { routerinfo_t *ri; diff --git a/src/or/test.c b/src/or/test.c index 9f2c97edcb..ef830d5449 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -534,7 +534,7 @@ test_dir_format() crypto_pk_env_t *pk1 = NULL, *pk2 = NULL, *pk3 = NULL; routerinfo_t *rp1 = NULL, *rp2 = NULL; struct exit_policy_t ex1, ex2; - directory_t *dir1 = NULL, *dir2 = NULL; + routerlist_t *dir1 = NULL, *dir2 = NULL; test_assert( (pk1 = crypto_new_pk_env(CRYPTO_PK_RSA)) ); test_assert( (pk2 = crypto_new_pk_env(CRYPTO_PK_RSA)) ); |