aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-02-26 09:51:30 -0500
committerNick Mathewson <nickm@torproject.org>2014-02-26 09:51:30 -0500
commit833d027778ba97020fb5ded1d94e4b21fbcab766 (patch)
treed7e3d9b859cc8da448e0620b8f95ca25f22c5733 /src/or
parent79c234e0e3fa22d76029bd3b5e2c52072709cff3 (diff)
downloadtor-833d027778ba97020fb5ded1d94e4b21fbcab766.tar
tor-833d027778ba97020fb5ded1d94e4b21fbcab766.tar.gz
Monotonize the OOM-killer data timers
In a couple of places, to implement the OOM-circuit-killer defense against sniper attacks, we have counters to remember the age of cells or data chunks. These timers were based on wall clock time, which can move backwards, thus giving roll-over results for our age calculation. This commit creates a low-budget monotonic time, based on ratcheting gettimeofday(), so that even in the event of a time rollback, we don't do anything _really_ stupid. A future version of Tor should update this function to do something even less stupid here, like employ clock_gettime() or its kin.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/buffers.c2
-rw-r--r--src/or/circuitlist.c2
-rw-r--r--src/or/relay.c2
3 files changed, 3 insertions, 3 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 352e60a97..b16ee6efa 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -632,7 +632,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
chunk = chunk_new_with_alloc_size(preferred_chunk_size(capacity));
}
- tor_gettimeofday_cached(&now);
+ tor_gettimeofday_cached_monotonic(&now);
chunk->inserted_time = (uint32_t)tv_to_msec(&now);
if (buf->tail) {
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 45fc95b56..0534e3555 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1551,7 +1551,7 @@ circuits_handle_oom(size_t current_allocation)
mem_to_recover = current_allocation - mem_target;
}
- tor_gettimeofday_cached(&now);
+ tor_gettimeofday_cached_monotonic(&now);
now_ms = (uint32_t)tv_to_msec(&now);
/* This algorithm itself assumes that you've got enough memory slack
diff --git a/src/or/relay.c b/src/or/relay.c
index e6d0f50ac..4cbc8fa47 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -1906,7 +1906,7 @@ cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell)
{
struct timeval now;
packed_cell_t *copy = packed_cell_copy(cell);
- tor_gettimeofday_cached(&now);
+ tor_gettimeofday_cached_monotonic(&now);
copy->inserted_time = (uint32_t)tv_to_msec(&now);
/* Remember the time when this cell was put in the queue. */