Commit e0952d07 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

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
parent 727a260a
......@@ -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.");
......
......@@ -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);
}
......
......@@ -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);
......@@ -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.
*/
......@@ -640,7 +643,7 @@ static int do_main_loop(void) {
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,9 +684,7 @@ static int do_main_loop(void) {
exit(1);
}
/* fetch a new directory */
if(options.DirPort) {
/* reload the fingerprint file */
char keydir[512];
sprintf(keydir,"%s/approved-routers", options.DataDirectory);
......@@ -692,10 +693,12 @@ static int do_main_loop(void) {
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);
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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,18 +178,19 @@ 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 */
......@@ -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,7 +257,6 @@ int router_get_list_from_file(char *routerfile)
return 0;
}
typedef enum {
K_ACCEPT,
K_DIRECTORY_SIGNATURE,
......@@ -471,14 +471,16 @@ 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;
......@@ -535,7 +537,8 @@ 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 */
!strncmp(start, myversion, len_myversion))
/* only do strncmp if the length matches */
return 0; /* success, it's there */
if(!comma)
return -1; /* nope */
......@@ -543,21 +546,21 @@ int compare_recommended_versions(char *myversion, char *start) {
}
}
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,
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,20 +669,20 @@ 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 router_get_list_from_string_impl(char **s, routerlist_t **dest,
int n_good_nicknames,
const char **good_nickname_lst)
{
......@@ -725,8 +728,8 @@ 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;
......@@ -751,27 +754,27 @@ router_resolve(routerinfo_t *router)
}
static int
router_resolve_directory(directory_t *dir)
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;
}
}
......@@ -781,7 +784,7 @@ router_resolve_directory(directory_t *dir)
/* 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;
......@@ -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;
......
......@@ -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)) );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment