[or-cvs] Implement hold_open_until_flushed. I may have missed somet...

Nick Mathewson nickm at seul.org
Wed Mar 3 05:08:03 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv23243/src/or

Modified Files:
	connection.c main.c or.h 
Log Message:
Implement hold_open_until_flushed.  I may have missed something important.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- connection.c	3 Mar 2004 02:07:57 -0000	1.170
+++ connection.c	3 Mar 2004 05:08:00 -0000	1.171
@@ -209,6 +209,27 @@
   return retval;
 }
 
+void connection_expire_held_open(void)
+{
+  connection_t **carray, *conn;
+  int n, i;
+  time_t now;
+
+  now = time(NULL);
+
+  get_connection_array(&carray, &n);
+  for (i = 0; i < n; ++i) {
+    conn = carray[i];
+    /* If we've been holding the connection open, but we haven't written
+     * for 15 seconds...
+     */
+    if (conn->marked_for_close && conn->hold_open_until_flushed &&
+        now - conn->timestamp_lastwritten >= 15) {
+      conn->hold_open_until_flushed = 0;
+    }
+  }
+}
+
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type) {
   struct sockaddr_in bindaddr; /* where to bind */
   struct hostent *rent;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.187
retrieving revision 1.188
diff -u -d -r1.187 -r1.188
--- main.c	3 Mar 2004 04:54:16 -0000	1.187
+++ main.c	3 Mar 2004 05:08:00 -0000	1.188
@@ -229,6 +229,10 @@
   conn = connection_array[i];
   assert_connection_ok(conn, time(NULL));
   if(conn->marked_for_close) {
+    if (conn->hold_open_until_flushed && conn->s >= 0 &&
+        connection_wants_to_flush(conn))
+      return;
+
     log_fn(LOG_INFO,"Cleaning up connection (fd %d).",conn->s);
     if(conn->s >= 0 && connection_wants_to_flush(conn)) {
       /* -1 means it's an incomplete edge connection, or that the socket
@@ -237,7 +241,6 @@
       log_fn(LOG_WARN,
              "Conn (fd %d, type %d, state %d) marked for close, but wants to flush.",
              conn->s, conn->type, conn->state);
-
       if(connection_speaks_cells(conn)) {
         if(conn->state == OR_CONN_STATE_OPEN) {
           flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen);
@@ -348,6 +351,11 @@
    */
   connection_ap_expire_beginning();
 
+
+  /* 2c. And expire connections that we've holding open for too long.
+   */
+  connection_expire_held_open();
+
   /* 3. Every second, we try a new circuit if there are no valid
    *    circuits. Every NewCircuitPeriod seconds, we expire circuits
    *    that became dirty more than NewCircuitPeriod seconds ago,

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.242
retrieving revision 1.243
diff -u -d -r1.242 -r1.243
--- or.h	3 Mar 2004 04:54:16 -0000	1.242
+++ or.h	3 Mar 2004 05:08:01 -0000	1.243
@@ -318,6 +318,7 @@
                          */
   char *marked_for_close_file; /* for debugging: in which file were we marked
                                 * for close? */
+  int hold_open_until_flushed;
 
   buf_t *inbuf;
   int inbuf_reached_eof; /* did read() return 0 on this conn? */
@@ -668,6 +669,8 @@
     }                                                                   \
   } while (0)
 
+void connection_expire_held_open(void);
+
 int connection_create_listener(char *bindaddress, uint16_t bindport, int type);
 
 int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_t port);
@@ -787,6 +790,7 @@
 int connection_is_reading(connection_t *conn);
 void connection_stop_reading(connection_t *conn);
 void connection_start_reading(connection_t *conn);
+
 int connection_is_writing(connection_t *conn);
 void connection_stop_writing(connection_t *conn);
 void connection_start_writing(connection_t *conn);



More information about the tor-commits mailing list