diff options
author | Andrea Shepard <andrea@torproject.org> | 2016-06-30 13:27:35 +0000 |
---|---|---|
committer | Andrea Shepard <andrea@torproject.org> | 2016-08-20 01:43:50 +0000 |
commit | 2bc19171ef6d3d569b3116ce49e93b20bd9b7449 (patch) | |
tree | 2cf3699d7468fdbfd7340a7dfc791d7982931d36 | |
parent | 4f253d4c676caba979ddf4bc2668273700f279ae (diff) | |
download | tor-2bc19171ef6d3d569b3116ce49e93b20bd9b7449.tar.gz tor-2bc19171ef6d3d569b3116ce49e93b20bd9b7449.zip |
Implement connection_count_moribund() for OOS handler
-rw-r--r-- | src/or/connection.c | 22 | ||||
-rw-r--r-- | src/or/main.c | 22 | ||||
-rw-r--r-- | src/or/main.h | 2 |
3 files changed, 41 insertions, 5 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 77ad56775c..6ef20b2371 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -4508,7 +4508,7 @@ connection_reached_eof(connection_t *conn) void connection_handle_oos(int n_socks, int failed) { - int target_n_socks = 0; + int target_n_socks = 0, moribund_socks, socks_to_kill; /* Sanity-check args */ tor_assert(n_socks >= 0); @@ -4554,13 +4554,25 @@ connection_handle_oos(int n_socks, int failed) /* * It's an OOS! * - * TODO count moribund sockets; it'll be important that anything we decide + * Count moribund sockets; it's be important that anything we decide * to get rid of here but don't immediately close get counted as moribund * on subsequent invocations so we don't try to kill too many things if - * this gets called multiple times. + * connection_handle_oos() gets called multiple times. */ - - /* TODO pick what to try to close */ + moribund_socks = connection_count_moribund(); + + if (moribund_socks < n_socks - target_n_socks) { + socks_to_kill = n_socks - target_n_socks - moribund_socks; + /* TODO actually kill them */ + log_notice(LD_NET, + "OOS handler wants to kill %d sockets", + socks_to_kill); + } else { + log_notice(LD_NET, + "Not killing any sockets for OOS because there are %d " + "already moribund, and we only want to eliminate %d", + moribund_socks, n_socks - target_n_socks); + } } } diff --git a/src/or/main.c b/src/or/main.c index 261118a81e..30041c5e2b 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -651,6 +651,28 @@ close_closeable_connections(void) } } +/** Count moribund connections for the OOS handler */ +int +connection_count_moribund(void) +{ + int i, moribund = 0; + connection_t *conn; + + /* + * Count things we'll try to kill when close_closeable_connections() + * runs next. + */ + for (i = 0; i < smartlist_len(closeable_connection_lst); ++i) { + conn = smartlist_get(closeable_connection_lst, i); + if (conn->conn_array_index < 0 || + conn->marked_for_close) { + ++moribund; + } + } + + return moribund; +} + /** Libevent callback: this gets invoked when (connection_t*)<b>conn</b> has * some data to read. */ static void diff --git a/src/or/main.h b/src/or/main.h index 31a22de424..4f58f170d5 100644 --- a/src/or/main.h +++ b/src/or/main.h @@ -47,6 +47,8 @@ MOCK_DECL(void,connection_start_writing,(connection_t *conn)); void connection_stop_reading_from_linked_conn(connection_t *conn); +int connection_count_moribund(void); + void directory_all_unreachable(time_t now); void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs); |