[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[or-cvs] lazy (just in time) directory rebuilding



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home/arma/work/onion/cvs/src/or

Modified Files:
	connection.c directory.c main.c or.h 
Log Message:
lazy (just in time) directory rebuilding


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- connection.c	5 Mar 2003 20:03:05 -0000	1.38
+++ connection.c	11 Mar 2003 01:51:41 -0000	1.39
@@ -123,6 +123,9 @@
       return NULL;
     }
   }
+  if(type == CONN_TYPE_OR) {
+    directory_set_dirty();
+  }
   return conn;
 }
 
@@ -149,6 +152,9 @@
   if(conn->s > 0) {
     log(LOG_INFO,"connection_free(): closing fd %d.",conn->s);
     close(conn->s);
+  }
+  if(conn->type == CONN_TYPE_OR) {
+    directory_set_dirty();
   }
   free(conn);
 }

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- directory.c	14 Oct 2002 06:44:48 -0000	1.6
+++ directory.c	11 Mar 2003 01:51:41 -0000	1.7
@@ -13,6 +13,7 @@
 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 @@
   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 @@
   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) {
@@ -174,6 +181,8 @@
     log(LOG_DEBUG,"directory_handle_command(): Command doesn't seem to be a get. Closing,");
     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.");

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- main.c	6 Mar 2003 04:52:02 -0000	1.41
+++ main.c	11 Mar 2003 01:51:41 -0000	1.42
@@ -302,7 +302,6 @@
   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 @@
 
   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 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",

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- or.h	7 Mar 2003 08:24:55 -0000	1.49
+++ or.h	11 Mar 2003 01:51:41 -0000	1.50
@@ -634,6 +634,7 @@
 
 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);