Browse Source

Be willing to read or write on local connections (e.g. controller
connections) even when the global rate limiting buckets are empty.


svn:r9368

Roger Dingledine 17 years ago
parent
commit
a3eaabfeb2
2 changed files with 19 additions and 1 deletions
  1. 2 0
      ChangeLog
  2. 17 1
      src/or/connection.c

+ 2 - 0
ChangeLog

@@ -19,6 +19,8 @@ Changes in version 0.1.2.7-alpha - 2007-??-??
     - Servers decline directory requests much more aggressively when
       they're low on bandwidth. Otherwise they end up queueing more and
       more directory responses, which can't be good for latency.
+    - Be willing to read or write on local connections (e.g. controller
+      connections) even when the global rate limiting buckets are empty.
 
   o Minor bugfixes:
     - When computing clock skew from directory HTTP headers, consider what

+ 17 - 1
src/or/connection.c

@@ -1099,8 +1099,16 @@ retry_all_listeners(int force, smartlist_t *replaced_conns,
 
 extern int global_read_bucket, global_write_bucket;
 
+/** Did our global write bucket run dry last second? If so, we are
+ * likely to run dry again this second, so be stingy with the tokens
+ * we just put in. */
 static int global_write_bucket_empty_last_second = 0;
 
+/** Helper function to decide how many bytes out of <b>global_bucket</b>
+ * we're willing to use for this transaction. <b>base</b> is the size
+ * of a cell on the network; <b>priority</b> says whether we should
+ * write many of them or just a few; and <b>conn_bucket</b> (if
+ * non-negative) provides an upper limit for our answer. */
 static int
 connection_bucket_round_robin(int base, int priority,
                               int global_bucket, int conn_bucket)
@@ -1142,6 +1150,10 @@ connection_bucket_read_limit(connection_t *conn)
     or_connection_t *or_conn = TO_OR_CONN(conn);
     conn_bucket = or_conn->read_bucket;
   }
+  if (conn_is_internal(conn->addr, 0)) {
+    /* be willing to read on local conns even if our buckets are empty */
+    return conn_bucket>=0 ? conn_bucket : 2**14;
+  }
   return connection_bucket_round_robin(base, priority,
                                        global_read_bucket, conn_bucket);
 }
@@ -1154,6 +1166,10 @@ connection_bucket_write_limit(connection_t *conn)
                CELL_NETWORK_SIZE : RELAY_PAYLOAD_SIZE;
   int priority = conn->type != CONN_TYPE_DIR;
 
+  if (conn_is_internal(conn->addr, 0)) {
+    /* be willing to write to local conns even if our buckets are empty */
+    return conn->outbuf_flushlen;
+  }
   return connection_bucket_round_robin(base, priority, global_write_bucket,
                                        conn->outbuf_flushlen);
 }
@@ -1590,7 +1606,7 @@ connection_outbuf_too_full(connection_t *conn)
  * from connection_write_to_buf() when an entire TLS record is ready.
  *
  * Update conn-\>timestamp_lastwritten to now, and call flush_buf
- * or flush_buf_tls appropriately. If it succeeds and there no more
+ * or flush_buf_tls appropriately. If it succeeds and there are no more
  * more bytes on conn->outbuf, then call connection_finished_flushing
  * on it too.
  *