[tor-commits] [tor/master] Implement connection_count_moribund() for OOS handler
nickm at torproject.org
nickm at torproject.org
Thu Aug 25 18:32:16 UTC 2016
commit 2bc19171ef6d3d569b3116ce49e93b20bd9b7449
Author: Andrea Shepard <andrea at torproject.org>
Date: Thu Jun 30 13:27:35 2016 +0000
Implement connection_count_moribund() for OOS handler
---
src/or/connection.c | 22 +++++++++++++++++-----
src/or/main.c | 22 ++++++++++++++++++++++
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 77ad567..6ef20b2 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 261118a..30041c5 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 31a22de..4f58f17 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);
More information about the tor-commits
mailing list