aboutsummaryrefslogtreecommitdiff
path: root/src/or/directory.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-03-11 01:51:41 +0000
committerRoger Dingledine <arma@torproject.org>2003-03-11 01:51:41 +0000
commit70b35ce8c2fba086836c3c4069f3284918690b74 (patch)
treed53eb31390ad5d3d8d089686f311a37cea73cb01 /src/or/directory.c
parentfb2f4a0418d1bf16d28a14b4dc80c417e61917e8 (diff)
downloadtor-70b35ce8c2fba086836c3c4069f3284918690b74.tar.gz
tor-70b35ce8c2fba086836c3c4069f3284918690b74.zip
lazy (just in time) directory rebuilding
svn:r174
Diffstat (limited to 'src/or/directory.c')
-rw-r--r--src/or/directory.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 11bd901814..e3c7b7821e 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;