summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-08-18 10:06:14 -0400
committerNick Mathewson <nickm@torproject.org>2010-08-18 10:06:14 -0400
commita509dbba504f7b5e2c1d93bad25e500493b06fb5 (patch)
tree07a6cd25208b82373b470e9160683df514debf81 /src/or/connection.c
parentd5c83f201441f2582dd074729d2ccdce90b1243e (diff)
parent58b6195455bcb173d260558e84e642c52d344c2f (diff)
downloadtor-a509dbba504f7b5e2c1d93bad25e500493b06fb5.tar.gz
tor-a509dbba504f7b5e2c1d93bad25e500493b06fb5.zip
Merge commit 'karsten/dirbytes2'
Conflicts: src/or/rephist.h
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index a16eb37a14..c040be041e 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -2082,8 +2082,6 @@ static void
connection_buckets_decrement(connection_t *conn, time_t now,
size_t num_read, size_t num_written)
{
- if (!connection_is_rate_limited(conn))
- return; /* local IPs are free */
if (num_written >= INT_MAX || num_read >= INT_MAX) {
log_err(LD_BUG, "Value out of range. num_read=%lu, num_written=%lu, "
"connection type=%s, state=%s",
@@ -2095,6 +2093,16 @@ connection_buckets_decrement(connection_t *conn, time_t now,
tor_fragile_assert();
}
+ /* Count bytes of answering direct and tunneled directory requests */
+ if (conn->type == CONN_TYPE_DIR && conn->purpose == DIR_PURPOSE_SERVER) {
+ if (num_read > 0)
+ rep_hist_note_dir_bytes_read(num_read, now);
+ if (num_written > 0)
+ rep_hist_note_dir_bytes_written(num_written, now);
+ }
+
+ if (!connection_is_rate_limited(conn))
+ return; /* local IPs are free */
if (num_read > 0) {
rep_hist_note_bytes_read(num_read, now);
}
@@ -2399,8 +2407,12 @@ connection_handle_read_impl(connection_t *conn)
connection_t *linked = conn->linked_conn;
if (n_read) {
- /* Probably a no-op, but hey. */
- connection_buckets_decrement(linked, approx_time(), n_read, 0);
+ /* Probably a no-op, since linked conns typically don't count for
+ * bandwidth rate limiting. But do it anyway so we can keep stats
+ * accurately. Note that since we read the bytes from conn, and
+ * we're writing the bytes onto the linked connection, we count
+ * these as <i>written</i> bytes. */
+ connection_buckets_decrement(linked, approx_time(), 0, n_read);
if (connection_flushed_some(linked) < 0)
connection_mark_for_close(linked);