diff options
author | Roger Dingledine <arma@torproject.org> | 2002-09-26 13:17:14 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-09-26 13:17:14 +0000 |
commit | f033442be292f9f573794913ca99fca83d622535 (patch) | |
tree | 9164a722f93e24b532af6b5e7387842b9f272a0a /src | |
parent | 01f6727306c784f790fcf50077007a8b958c4e03 (diff) | |
download | tor-f033442be292f9f573794913ca99fca83d622535.tar.gz tor-f033442be292f9f573794913ca99fca83d622535.zip |
dirserver should include itself in the directory
if connecting to a dirserver fails, remove it from the router array
svn:r113
Diffstat (limited to 'src')
-rw-r--r-- | src/or/directory.c | 6 | ||||
-rw-r--r-- | src/or/main.c | 55 | ||||
-rw-r--r-- | src/or/or.h | 1 | ||||
-rw-r--r-- | src/or/routers.c | 25 |
4 files changed, 68 insertions, 19 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index be0f6cb1ee..356d4ffd03 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1,4 +1,4 @@ -/* Copyright 2001,2002 Roger Dingledine, Matej Pfaêfar. */ +/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */ /* See LICENSE for licensing information */ /* $Id$ */ @@ -56,6 +56,7 @@ void directory_initiate_fetch(routerinfo_t *router) { if(connect(s,(struct sockaddr *)&router_addr,sizeof(router_addr)) < 0){ if(errno != EINPROGRESS){ /* yuck. kill it. */ + router_forget_router(conn->addr, conn->port); /* don't try him again */ connection_free(conn); return; } else { @@ -210,6 +211,7 @@ int connection_dir_finished_flushing(connection_t *conn) { if(errno != EINPROGRESS){ /* yuck. kill it. */ log(LOG_DEBUG,"connection_dir_finished_flushing(): in-progress connect failed. Removing."); + router_forget_router(conn->addr, conn->port); /* don't try him again */ return -1; } else { return 0; /* no change, see if next time is better */ @@ -217,7 +219,7 @@ int connection_dir_finished_flushing(connection_t *conn) { } /* the connect has finished. */ - log(LOG_DEBUG,"connection_dir_finished_flushing(): DIR connection to router %s:%u established.", + log(LOG_DEBUG,"connection_dir_finished_flushing(): Dir connection to router %s:%u established.", conn->address,conn->port); return directory_send_command(conn); diff --git a/src/or/main.c b/src/or/main.c index 7a1fbc39f8..83d22c3608 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -21,6 +21,8 @@ static int please_dumpstats=0; /* whether we should dump stats during the loop * /* private key */ static crypto_pk_env_t *prkey; +routerinfo_t *my_routerinfo=NULL; + /********* END VARIABLES ************/ /**************************************************************************** @@ -214,6 +216,10 @@ void check_conn_read(int i) { retval = connection_dir_handle_listener_read(conn); } else { retval = connection_read_to_buf(conn); + if (retval < 0 && conn->type == CONN_TYPE_DIR) { + /* as a special case: forget about this router */ + router_forget_router(conn->addr,conn->port); + } if (retval >= 0) { /* all still well */ retval = connection_process_inbuf(conn); // log(LOG_DEBUG,"check_conn_read(): connection_process_inbuf returned %d.",retval); @@ -501,14 +507,42 @@ void dumpstats (void) { /* dump stats to stdout */ please_dumpstats = 0; } -void dump_directory_to_string(char *s, int maxlen) { - int i; - connection_t *conn; +int dump_router_to_string(char *s, int maxlen, routerinfo_t *router) { char *pkey; int pkeylen; int written; + + if(crypto_pk_write_public_key_to_string(router->pkey,&pkey,&pkeylen)<0) { + log(LOG_ERR,"dump_directory_to_string(): write pkey to string failed!"); + return 0; + } + written = snprintf(s, maxlen, "%s %d %d %d %d %d\n%s\n", + router->address, + router->or_port, + router->op_port, + router->ap_port, + router->dir_port, + router->bandwidth, + pkey); + + free(pkey); + + return written; +} + +void dump_directory_to_string(char *s, int maxlen) { + int i; + connection_t *conn; routerinfo_t *router; + int written; + /* first write my own info */ + /* XXX should check for errors here too */ + written = dump_router_to_string(s, maxlen, my_routerinfo); + maxlen -= written; + s += written; + + /* now write info for other routers */ for(i=0;i<nfds;i++) { conn = connection_array[i]; @@ -519,20 +553,8 @@ void dump_directory_to_string(char *s, int maxlen) { log(LOG_ERR,"dump_directory_to_string(): couldn't find router %d:%d!",conn->addr,conn->port); return; } - if(crypto_pk_write_public_key_to_string(router->pkey,&pkey,&pkeylen)<0) { - log(LOG_ERR,"dump_directory_to_string(): write pkey to string failed!"); - return; - } - written = snprintf(s, maxlen, "%s %d %d %d %d %d\n%s\n", - router->address, - router->or_port, - router->op_port, - router->ap_port, - router->dir_port, - router->bandwidth, - pkey); - free(pkey); + written = dump_router_to_string(s, maxlen, router); if(written < 0 || written > maxlen) { /* apparently different glibcs do different things on error.. so check both */ @@ -543,7 +565,6 @@ void dump_directory_to_string(char *s, int maxlen) { maxlen -= written; s += written; - } } diff --git a/src/or/or.h b/src/or/or.h index e417cc9de7..b06b0aceca 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -653,6 +653,7 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port); unsigned int *router_new_route(int *routelen); unsigned char *router_create_onion(unsigned int *route, int routelen, int *len, crypt_path_t **cpath); routerinfo_t *router_get_first_in_route(unsigned int *route, int routelen); +void router_forget_router(uint32_t addr, uint16_t port); int router_get_list_from_file(char *routerfile, uint16_t or_listenport); int router_get_list_from_string(char *s, uint16_t or_listenport); diff --git a/src/or/routers.c b/src/or/routers.c index b7984fe593..a0e4da6d84 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -21,6 +21,7 @@ static int rarray_len = 0; extern int global_role; /* from main.c */ extern or_options_t options; /* command-line and config-file options */ +extern routerinfo_t *my_routerinfo; /* from main.c */ /****************************************************************************/ @@ -175,6 +176,27 @@ void rarray_free(routerinfo_t **list) { free(list); } +void router_forget_router(uint32_t addr, uint16_t port) { + int i; + routerinfo_t *router; + + router = router_get_by_addr_port(addr,port); + if(!router) /* we don't seem to know about him in the first place */ + return; + + /* now walk down router_array until we get to router */ + for(i=0;i<rarray_len;i++) + if(router_array[i] == router) + break; + + assert(i != rarray_len); /* if so then router_get_by_addr_port should have returned null */ + + free(router); +// log(LOG_DEBUG,"router_forget_router(): Forgot about router %d:%d",addr,port); + for(; i<rarray_len-1;i++) + router_array[i] = router_array[i+1]; +} + /* create a NULL-terminated array of pointers pointing to elements of a router list */ /* this is done in two passes through the list - inefficient but irrelevant as this is * only done once when op/or start up */ @@ -289,6 +311,9 @@ int router_get_list_from_string(char *s, uint16_t or_listenport) { if(!router_is_me(router->addr, router->or_port, or_listenport)) { router->next = routerlist; routerlist = router; + } else { + if(!my_routerinfo) /* save it, so we can use it for directories */ + my_routerinfo = router; } s = eat_whitespace(s); } |