diff --git a/ChangeLog b/ChangeLog
index 331ba32fa0..10fe39d6eb 100644
--- a/ChangeLog
+++ b/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
diff --git a/src/or/connection.c b/src/or/connection.c
index 9d71db5d4b..fbd2a8aa41 100644
--- a/src/or/connection.c
+++ b/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 global_bucket
+ * we're willing to use for this transaction. base is the size
+ * of a cell on the network; priority says whether we should
+ * write many of them or just a few; and conn_bucket (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.
*