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/or/main.c | |
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/or/main.c')
-rw-r--r-- | src/or/main.c | 55 |
1 files changed, 38 insertions, 17 deletions
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; - } } |