[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] bugfix: do directory_send_command only after we"ve establis...



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

Modified Files:
	circuit.c connection.c connection_or.c cpuworker.c directory.c 
	main.c or.h 
Log Message:
bugfix: do directory_send_command only after we've established a socket

also many comments, cleaning, etc


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.230
retrieving revision 1.231
diff -u -d -r1.230 -r1.231
--- circuit.c	6 May 2004 11:08:04 -0000	1.230
+++ circuit.c	9 May 2004 16:33:04 -0000	1.231
@@ -1,4 +1,4 @@
-/* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
+/* Copyright 2001 Matej Pfajfar, 2001-2004 Roger Dingledine. */
 /* See LICENSE for licensing information */
 /* $Id$ */
 
@@ -37,7 +37,10 @@
 
 /********* END VARIABLES ************/
 
-void circuit_add(circuit_t *circ) {
+/* add 'circ' to the global list of circuits. This is called only from
+ * within circuit_new.
+ */
+static void circuit_add(circuit_t *circ) {
   if(!global_circuitlist) { /* first one */
     global_circuitlist = circ;
     circ->next = NULL;

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.212
retrieving revision 1.213
diff -u -d -r1.212 -r1.213
--- connection.c	6 May 2004 11:08:04 -0000	1.212
+++ connection.c	9 May 2004 16:33:04 -0000	1.213
@@ -8,6 +8,7 @@
 
 extern or_options_t options; /* command-line and config-file options */
 
+/* Array of strings to make conn->type human-readable */
 char *conn_type_to_string[] = {
   "",            /* 0 */
   "OP listener", /* 1 */
@@ -23,6 +24,7 @@
   "CPU worker",  /* 11 */
 };
 
+/* Array of string arrays to make {conn->type,conn->state} human-readable */
 char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
   { NULL }, /* no type associated with 0 */
   { NULL }, /* op listener, obsolete */
@@ -72,6 +74,19 @@
 
 /**************************************************************/
 
+/* Allocate space for a new connection_t. This function just initializes
+ * conn; you must call connection_add() to link it into the main array.
+ *
+ * Set conn->type to 'type'. Set conn->s and conn->poll_index to
+ * -1 to signify they are not yet assigned.
+ *
+ * If conn is not a listener type, allocate buffers for it. If it's
+ * an AP type, allocate space to store the socks_request.
+ *
+ * Assign a pseudorandom next_circ_id between 0 and 2**15.
+ *
+ * Initialize conn's timestamps to now.
+ */
 connection_t *connection_new(int type) {
   connection_t *conn;
   time_t now = time(NULL);
@@ -99,6 +114,10 @@
   return conn;
 }
 
+/* Deallocate memory used by 'conn'. Deallocate its buffers if necessary,
+ * close its socket if necessary, and mark the directory as dirty if conn
+ * is an OR or OP connection.
+ */
 void connection_free(connection_t *conn) {
   tor_assert(conn);
   tor_assert(conn->magic == CONNECTION_MAGIC);
@@ -110,7 +129,7 @@
   tor_free(conn->address);
 
   if(connection_speaks_cells(conn)) {
-    directory_set_dirty();
+    directory_set_dirty(); /* XXX should only do this for an open OR conn */
     if (conn->tls)
       tor_tls_free(conn->tls);
   }

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- connection_or.c	7 May 2004 08:53:40 -0000	1.102
+++ connection_or.c	9 May 2004 16:33:04 -0000	1.103
@@ -122,7 +122,7 @@
  * state to 'connecting' and return. If connect to router succeeds, call
  * connection_tls_start_handshake() on it.
  *
- * This function is called from router_retry_connections() , for
+ * This function is called from router_retry_connections(), for
  * ORs connecting to ORs, and circuit_establish_circuit(), for
  * OPs connecting to ORs.
  *
@@ -193,7 +193,7 @@
   return 0;
 }
 
-/* Move forward with ths tls handshake. If it finishes, hand
+/* Move forward with the tls handshake. If it finishes, hand
  * conn to connection_tls_finish_handshake().
  *
  * Return -1 if conn is broken, else return 0.
@@ -221,9 +221,9 @@
  *
  * Make sure we are happy with the person we just handshaked with:
  * If it's an OP (that is, it has no certificate), make sure I'm an OR.
- * If it's an OR (is has a certificate), make sure it has a recognized
- * nickname, its cert is signed by the identity key of that nickname;
- * if I initiated the connection, make sure it's the right guy, and if
+ * If it's an OR (it has a certificate), make sure it has a recognized
+ * nickname, and its cert is signed by the identity key of that nickname.
+ * If I initiated the connection, make sure it's the right guy; and if
  * he initiated the connection, make sure he's not already connected.
  *
  * If he initiated the conn, also initialize conn from the information

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- cpuworker.c	6 May 2004 11:08:04 -0000	1.35
+++ cpuworker.c	9 May 2004 16:33:04 -0000	1.36
@@ -204,7 +204,7 @@
 
     if(recv(fd, &question_type, 1, 0) != 1) {
 //      log_fn(LOG_ERR,"read type failed. Exiting.");
-      log_fn(LOG_INFO,"cpuworker exiting because tor process died.");
+      log_fn(LOG_INFO,"cpuworker exiting because tor process closed connection (either rotated keys or died).");
       goto end;
     }
     tor_assert(question_type == CPUWORKER_TASK_ONION);

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- directory.c	6 May 2004 22:47:48 -0000	1.98
+++ directory.c	9 May 2004 16:33:04 -0000	1.99
@@ -75,9 +75,6 @@
 
   conn->purpose = purpose;
 
-  /* queue the command on the outbuf */
-  directory_send_command(conn, purpose, payload, payload_len);
-
   /* give it an initial state */
   conn->state = DIR_CONN_STATE_CONNECTING;
 
@@ -93,6 +90,9 @@
         conn->state = DIR_CONN_STATE_CLIENT_SENDING; /* start flushing conn */
         /* fall through */
       case 0:
+        /* queue the command on the outbuf */
+        directory_send_command(conn, purpose, payload, payload_len);
+
         connection_watch_events(conn, POLLIN | POLLOUT | POLLERR);
         /* writable indicates finish, readable indicates broken link,
            error indicates broken link in windowsland. */
@@ -111,7 +111,9 @@
 
     conn->state = DIR_CONN_STATE_CLIENT_SENDING;
     connection_add(conn);
-    connection_start_reading(conn);
+    /* queue the command on the outbuf */
+    directory_send_command(conn, purpose, payload, payload_len);
+    connection_watch_events(conn, POLLIN | POLLOUT | POLLERR);
   }
 }
 
@@ -286,7 +288,7 @@
           log_fn(LOG_WARN,"http status 400 (bad request) response from dirserver. Malformed server descriptor?");
           break;
         case 403:
-          log_fn(LOG_WARN,"http status 403 (unapproved server) response from dirserver. Is your clock skewed? Have you mailed arma your identity fingerprint? Are you using the right key? See README.");
+          log_fn(LOG_WARN,"http status 403 (unapproved server) response from dirserver. Is your clock skewed? Have you mailed us your identity fingerprint? Are you using the right key? See README.");
 
           break;
         default:

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.258
retrieving revision 1.259
diff -u -d -r1.258 -r1.259
--- main.c	6 May 2004 11:08:04 -0000	1.258
+++ main.c	9 May 2004 16:33:04 -0000	1.259
@@ -172,9 +172,7 @@
 
 /* Tell the main loop to stop notifying 'conn' of any write events. */
 void connection_stop_writing(connection_t *conn) {
-
   tor_assert(conn && conn->poll_index >= 0 && conn->poll_index < nfds);
-
   if(poll_array[conn->poll_index].events & POLLOUT)
     poll_array[conn->poll_index].events -= POLLOUT;
 }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.332
retrieving revision 1.333
diff -u -d -r1.332 -r1.333
--- or.h	6 May 2004 11:08:04 -0000	1.332
+++ or.h	9 May 2004 16:33:04 -0000	1.333
@@ -674,7 +674,6 @@
 /********************************* circuit.c ***************************/
 
 extern char *circuit_state_to_string[];
-void circuit_add(circuit_t *circ);
 void circuit_remove(circuit_t *circ);
 circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn);
 void circuit_close_all_marked(void);