Browse Source

r16570@catbus: nickm | 2007-11-08 11:04:20 -0500
Keep track, for each OR connection, of the last time we added a non-padding cell to its outbuf. Use this timestamp, not "lastwritten" to tell if it is time to close a circuitless connection. (We can'tuse lastwritten, since lastwritten is updated when ever the connection flushes anything, and by that point we can no longer tell what is a padding cell and what is not.)


svn:r12437

Nick Mathewson 18 years ago
parent
commit
c3a745951b
5 changed files with 15 additions and 5 deletions
  1. 3 3
      doc/TODO
  2. 3 1
      src/or/connection.c
  3. 5 0
      src/or/connection_or.c
  4. 2 1
      src/or/main.c
  5. 2 0
      src/or/or.h

+ 3 - 3
doc/TODO

@@ -15,7 +15,7 @@ J       - Jeff claims
         X Abandoned
         X Abandoned
 
 
 Items blocking 0.2.0.10-alpha:
 Items blocking 0.2.0.10-alpha:
-  - Some resolution for (the reopened) bug 546.
+  . Some resolution for (the reopened) bug 546.
   - We should back out the MBTF->WFU Guard factors, since they open us
   - We should back out the MBTF->WFU Guard factors, since they open us
     up to new attacks, and don't this "median" notion doesn't necessarily
     up to new attacks, and don't this "median" notion doesn't necessarily
     help us distinguish between "was good enough to be a guard when
     help us distinguish between "was good enough to be a guard when
@@ -32,9 +32,9 @@ Here's a go:
   median WFU of the set. In addition, anybody born more than a month ago
   median WFU of the set. In addition, anybody born more than a month ago
   who has >=50% WFU is always a winner.
   who has >=50% WFU is always a winner.
 
 
-  - If 1.5*MaxCircuitDirtiness is more than KeepAlive, do we then send
+  o If 1.5*MaxCircuitDirtiness is more than KeepAlive, do we then send
     a KeepAlive and reset our timeout, thus never reaching 1.5*MCD?
     a KeepAlive and reset our timeout, thus never reaching 1.5*MCD?
-    - Aw, crud.  We could keep track of how long it's been since
+    o Aw, crud.  We could keep track of how long it's been since
       we last did anything _other_ than a keepalive, I guess. -NM
       we last did anything _other_ than a keepalive, I guess. -NM
 
 
 For Tor 0.2.0.11-alpha:
 For Tor 0.2.0.11-alpha:

+ 3 - 1
src/or/connection.c

@@ -209,8 +209,10 @@ connection_new(int type, int socket_family)
   if (CONN_IS_EDGE(conn)) {
   if (CONN_IS_EDGE(conn)) {
     TO_EDGE_CONN(conn)->global_identifier = n_connections_allocated++;
     TO_EDGE_CONN(conn)->global_identifier = n_connections_allocated++;
   }
   }
-  if (type == CONN_TYPE_OR)
+  if (type == CONN_TYPE_OR) {
+    TO_OR_CONN(conn)->timestamp_last_added_nonpadding = now;
     TO_OR_CONN(conn)->next_circ_id = crypto_rand_int(1<<15);
     TO_OR_CONN(conn)->next_circ_id = crypto_rand_int(1<<15);
+  }
 
 
   conn->timestamp_created = now;
   conn->timestamp_created = now;
   conn->timestamp_lastread = now;
   conn->timestamp_lastread = now;

+ 5 - 0
src/or/connection_or.c

@@ -855,6 +855,9 @@ connection_or_write_cell_to_buf(const cell_t *cell, or_connection_t *conn)
   cell_pack(&networkcell, cell);
   cell_pack(&networkcell, cell);
 
 
   connection_write_to_buf(networkcell.body, CELL_NETWORK_SIZE, TO_CONN(conn));
   connection_write_to_buf(networkcell.body, CELL_NETWORK_SIZE, TO_CONN(conn));
+
+  if (cell->command != CELL_PADDING)
+    conn->timestamp_last_added_nonpadding = time(NULL);
 }
 }
 
 
 /**DOCDOC*/
 /**DOCDOC*/
@@ -868,6 +871,8 @@ connection_or_write_var_cell_to_buf(const var_cell_t *cell,
   var_cell_pack_header(cell, hdr);
   var_cell_pack_header(cell, hdr);
   connection_write_to_buf(hdr, sizeof(hdr), TO_CONN(conn));
   connection_write_to_buf(hdr, sizeof(hdr), TO_CONN(conn));
   connection_write_to_buf(cell->payload, cell->payload_len, TO_CONN(conn));
   connection_write_to_buf(cell->payload, cell->payload_len, TO_CONN(conn));
+  if (cell->command != CELL_PADDING)
+    conn->timestamp_last_added_nonpadding = time(NULL);
 }
 }
 
 
 /** DOCDOC */
 /** DOCDOC */

+ 2 - 1
src/or/main.c

@@ -780,7 +780,8 @@ run_connection_housekeeping(int i, time_t now)
       connection_mark_for_close(conn);
       connection_mark_for_close(conn);
       conn->hold_open_until_flushed = 1;
       conn->hold_open_until_flushed = 1;
     } else if (!clique_mode(options) && !or_conn->n_circuits &&
     } else if (!clique_mode(options) && !or_conn->n_circuits &&
-               now >= conn->timestamp_lastwritten + maxCircuitlessPeriod &&
+               now >= or_conn->timestamp_last_added_nonpadding +
+                                           maxCircuitlessPeriod &&
                (!router || !server_mode(options) ||
                (!router || !server_mode(options) ||
                 !router_is_clique_mode(router))) {
                 !router_is_clique_mode(router))) {
       log_info(LD_OR,"Expiring non-used OR connection to fd %d (%s:%d) "
       log_info(LD_OR,"Expiring non-used OR connection to fd %d (%s:%d) "

+ 2 - 0
src/or/or.h

@@ -926,6 +926,8 @@ typedef struct or_connection_t {
 
 
   or_handshake_state_t *handshake_state;/**< DOCDOC */
   or_handshake_state_t *handshake_state;/**< DOCDOC */
   time_t timestamp_lastempty; /**< When was the outbuf last completely empty?*/
   time_t timestamp_lastempty; /**< When was the outbuf last completely empty?*/
+  time_t timestamp_last_added_nonpadding; /** When did we last add a
+                                           * non-padding cell to the outbuf? */
 
 
   /* bandwidth* and read_bucket only used by ORs in OPEN state: */
   /* bandwidth* and read_bucket only used by ORs in OPEN state: */
   int bandwidthrate; /**< Bytes/s added to the bucket. (OPEN ORs only.) */
   int bandwidthrate; /**< Bytes/s added to the bucket. (OPEN ORs only.) */