[or-cvs] fix rare race condition

Roger Dingledine arma at seul.org
Mon Mar 24 02:50:09 UTC 2003


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

Modified Files:
	connection.c connection_or.c or.h 
Log Message:
fix rare race condition
if the directory is remade while an OR is handshaking, the directory
needs to become dirty again when the handshake succeeds


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- connection.c	19 Mar 2003 22:47:34 -0000	1.47
+++ connection.c	24 Mar 2003 02:50:06 -0000	1.48
@@ -123,9 +123,6 @@
       return NULL;
     }
   }
-  if(type == CONN_TYPE_OR) {
-    directory_set_dirty();
-  }
 #ifdef USE_ZLIB
   if (type == CONN_TYPE_AP || type == CONN_TYPE_EXIT)  {
     if (buf_new(&conn->z_outbuf, &conn->z_outbuflen, &conn->z_outbuf_datalen) < 0)

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- connection_or.c	19 Mar 2003 22:02:35 -0000	1.22
+++ connection_or.c	24 Mar 2003 02:50:07 -0000	1.23
@@ -86,9 +86,8 @@
     case OR_CONN_STATE_CLIENT_SENDING_NONCE:
       log(LOG_DEBUG,"connection_or_finished_flushing(): client finished sending nonce.");
       conn_or_init_crypto(conn);
-      conn->state = OR_CONN_STATE_OPEN;
-      connection_init_timeval(conn);
-      connection_watch_events(conn, POLLIN);
+      connection_or_set_open(conn);
+
       return connection_process_inbuf(conn); /* in case there's anything waiting on it */
     case OR_CONN_STATE_SERVER_SENDING_AUTH:
       log(LOG_DEBUG,"connection_or_finished_flushing(): server finished sending auth.");
@@ -110,6 +109,13 @@
 
 /*********************/
 
+void connection_or_set_open(connection_t *conn) {
+  conn->state = OR_CONN_STATE_OPEN;
+  directory_set_dirty();
+  connection_init_timeval(conn);
+  connection_watch_events(conn, POLLIN);
+}
+
 void conn_or_init_crypto(connection_t *conn) {
   //int x;
   unsigned char iv[16];
@@ -327,9 +333,7 @@
   /* do crypto initialization, etc */
   conn_or_init_crypto(conn);
 
-  conn->state = OR_CONN_STATE_OPEN;
-  connection_init_timeval(conn);
-  connection_watch_events(conn, POLLIN); /* give it a default, tho the ap_handshake call may change it */
+  connection_or_set_open(conn);
   ap_handshake_n_conn_open(conn); /* send the pending onions */
   return 0;
 }
@@ -532,9 +536,7 @@
   /* it finished sending */
   log(LOG_DEBUG,"or_handshake_client_process_auth(): Finished sending nonce.");
   conn_or_init_crypto(conn);
-  conn->state = OR_CONN_STATE_OPEN;
-  connection_init_timeval(conn);
-  connection_watch_events(conn, POLLIN);
+  connection_or_set_open(conn);
   return connection_process_inbuf(conn); /* process the rest of the inbuf */
 
 }
@@ -719,9 +721,7 @@
   log(LOG_DEBUG,"or_handshake_server_process_nonce() : Response valid. Authentication complete.");
 
   conn_or_init_crypto(conn);
-  conn->state = OR_CONN_STATE_OPEN;
-  connection_init_timeval(conn);
-  connection_watch_events(conn, POLLIN);
+  connection_or_set_open(conn);
   return connection_process_inbuf(conn); /* process the rest of the inbuf */
 
 }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- or.h	19 Mar 2003 22:27:37 -0000	1.54
+++ or.h	24 Mar 2003 02:50:07 -0000	1.55
@@ -649,6 +649,7 @@
 int connection_or_process_inbuf(connection_t *conn);
 int connection_or_finished_flushing(connection_t *conn);
 
+void connection_or_set_open(connection_t *conn);
 void conn_or_init_crypto(connection_t *conn);
 
 int or_handshake_op_send_keys(connection_t *conn);



More information about the tor-commits mailing list