diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-01-13 09:52:07 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-12 12:48:20 -0500 |
commit | 9a07ec751ff73062b958a8fc9f8437bed72e144c (patch) | |
tree | f603ecc2eed23118c7e848f0a80d0b00a665e262 /src/or | |
parent | 52d222aafbc21d674624fdd4c8fc834a40af69c7 (diff) | |
download | tor-9a07ec751ff73062b958a8fc9f8437bed72e144c.tar.gz tor-9a07ec751ff73062b958a8fc9f8437bed72e144c.zip |
Refactor OOM-handling functions for more testability
This patch splits out some of the functions in OOM handling so that
it's easier to check them without involving the rest of Tor or
requiring that the circuits be "wired up".
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/circuitlist.c | 6 | ||||
-rw-r--r-- | src/or/circuitlist.h | 4 | ||||
-rw-r--r-- | src/or/relay.c | 11 | ||||
-rw-r--r-- | src/or/relay.h | 2 |
4 files changed, 16 insertions, 7 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c index eb652301ed..618a42ed36 100644 --- a/src/or/circuitlist.c +++ b/src/or/circuitlist.c @@ -1435,9 +1435,9 @@ circuit_mark_all_dirty_circs_as_unusable(void) * - If circ->rend_splice is set (we are the midpoint of a joined * rendezvous stream), then mark the other circuit to close as well. */ -void -circuit_mark_for_close_(circuit_t *circ, int reason, int line, - const char *file) +MOCK_IMPL(void, +circuit_mark_for_close_, (circuit_t *circ, int reason, int line, + const char *file)) { int orig_reason = reason; /* Passed to the controller */ assert_circuit_ok(circ); diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h index 1c8cf7de24..a6340c1f7a 100644 --- a/src/or/circuitlist.h +++ b/src/or/circuitlist.h @@ -53,8 +53,8 @@ origin_circuit_t *circuit_find_to_cannibalize(uint8_t purpose, extend_info_t *info, int flags); void circuit_mark_all_unused_circs(void); void circuit_mark_all_dirty_circs_as_unusable(void); -void circuit_mark_for_close_(circuit_t *circ, int reason, - int line, const char *file); +MOCK_DECL(void, circuit_mark_for_close_, (circuit_t *circ, int reason, + int line, const char *file)); int circuit_get_cpath_len(origin_circuit_t *circ); void circuit_clear_cpath(origin_circuit_t *circ); crypt_path_t *circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum); diff --git a/src/or/relay.c b/src/or/relay.c index 041a9e8b5c..dbc1710594 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -2199,12 +2199,19 @@ packed_cell_mem_cost(void) return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD; } +/** DOCDOC */ +STATIC size_t +cell_queues_get_total_allocation(void) +{ + return total_cells_allocated * packed_cell_mem_cost(); +} + /** Check whether we've got too much space used for cells. If so, * call the OOM handler and return 1. Otherwise, return 0. */ -static int +STATIC int cell_queues_check_size(void) { - size_t alloc = total_cells_allocated * packed_cell_mem_cost(); + size_t alloc = cell_queues_get_total_allocation(); alloc += buf_get_total_allocation(); if (alloc >= get_options()->MaxMemInQueues) { circuits_handle_oom(alloc); diff --git a/src/or/relay.h b/src/or/relay.h index 20eecfb400..2c7d0d8ae4 100644 --- a/src/or/relay.h +++ b/src/or/relay.h @@ -85,6 +85,8 @@ STATIC int connected_cell_parse(const relay_header_t *rh, const cell_t *cell, tor_addr_t *addr_out, int *ttl_out); STATIC packed_cell_t *packed_cell_new(void); STATIC packed_cell_t *cell_queue_pop(cell_queue_t *queue); +STATIC size_t cell_queues_get_total_allocation(void); +STATIC int cell_queues_check_size(void); #endif #endif |