diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/connection.c | 6 | ||||
-rw-r--r-- | src/or/directory.c | 23 | ||||
-rw-r--r-- | src/or/main.c | 17 | ||||
-rw-r--r-- | src/or/or.h | 1 |
4 files changed, 25 insertions, 22 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 63adb408d..8e7fcb7c0 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -123,6 +123,9 @@ connection_t *connection_new(int type) { return NULL; } } + if(type == CONN_TYPE_OR) { + directory_set_dirty(); + } return conn; } @@ -150,6 +153,9 @@ void connection_free(connection_t *conn) { log(LOG_INFO,"connection_free(): closing fd %d.",conn->s); close(conn->s); } + if(conn->type == CONN_TYPE_OR) { + directory_set_dirty(); + } free(conn); } diff --git a/src/or/directory.c b/src/or/directory.c index 11bd90181..e3c7b7821 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -13,6 +13,7 @@ extern or_options_t options; /* command-line and config-file options */ static char the_directory[MAX_DIR_SIZE+1]; static int directorylen=0; static int reading_headers=0; +static int directory_dirty=1; static char getstring[] = "GET / HTTP/1.0\r\n\r\n"; static char answerstring[] = "HTTP/1.0 200 OK\r\n\r\n"; @@ -44,8 +45,7 @@ void directory_initiate_fetch(routerinfo_t *router) { conn->bandwidth = -1; s=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); - if (s < 0) - { + if(s < 0) { log(LOG_ERR,"directory_initiate_fetch(): Error creating network socket."); connection_free(conn); return; @@ -110,12 +110,19 @@ int directory_send_command(connection_t *conn) { return 0; } -void directory_rebuild(void) { - - dump_directory_to_string(the_directory, MAX_DIR_SIZE); - log(LOG_DEBUG,"New directory:\n%s",the_directory); - directorylen = strlen(the_directory); +void directory_set_dirty(void) { + directory_dirty = 1; +} +void directory_rebuild(void) { + if(directory_dirty) { + dump_directory_to_string(the_directory, MAX_DIR_SIZE); + log(LOG_INFO,"New directory:\n%s",the_directory); + directorylen = strlen(the_directory); + directory_dirty = 0; + } else { + log(LOG_INFO,"Directory still clean, reusing."); + } } int connection_dir_process_inbuf(connection_t *conn) { @@ -175,6 +182,8 @@ int directory_handle_command(connection_t *conn) { return -1; } + directory_rebuild(); /* rebuild it now, iff it's dirty */ + if(directorylen == 0) { log(LOG_DEBUG,"directory_handle_command(): My directory is empty. Closing."); return -1; diff --git a/src/or/main.c b/src/or/main.c index c3c5b7692..7add4dada 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -302,7 +302,6 @@ int prepare_for_poll(int *timeout) { connection_t *tmpconn; struct timeval now; //soonest; static long current_second = 0; /* from previous calls to gettimeofday */ - static long time_to_rebuild_directory = 0; static long time_to_fetch_directory = 0; // int ms_until_conn; cell_t cell; @@ -312,19 +311,7 @@ int prepare_for_poll(int *timeout) { if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */ - if(options.Role & ROLE_DIR_SERVER) { - if(time_to_rebuild_directory < now.tv_sec) { - /* it's time to rebuild our directory */ - if(time_to_rebuild_directory == 0) { - /* we just started up. if we build a directory now it will be meaningless. */ - log(LOG_DEBUG,"prepare_for_poll(): Delaying initial dir build for 10 seconds."); - time_to_rebuild_directory = now.tv_sec + 10; /* try in 10 seconds */ - } else { - directory_rebuild(); - time_to_rebuild_directory = now.tv_sec + options.DirRebuildPeriod; - } - } - } else { + if(!(options.Role & ROLE_DIR_SERVER)) { if(time_to_fetch_directory < now.tv_sec) { /* it's time to fetch a new directory */ /* NOTE directory servers do not currently fetch directories. @@ -561,7 +548,7 @@ int dump_router_to_string(char *s, int maxlen, routerinfo_t *router) { 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!"); + log(LOG_ERR,"dump_router_to_string(): write pkey to string failed!"); return 0; } written = snprintf(s, maxlen, "%s %d %d %d %d %d\n%s\n", diff --git a/src/or/or.h b/src/or/or.h index c3ad8479a..13a24203a 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -634,6 +634,7 @@ int connection_or_handle_listener_read(connection_t *conn); void directory_initiate_fetch(routerinfo_t *router); int directory_send_command(connection_t *conn); +void directory_set_dirty(void); void directory_rebuild(void); int connection_dir_process_inbuf(connection_t *conn); int directory_handle_command(connection_t *conn); |