mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Implement connection_count_moribund() for OOS handler
This commit is contained in:
parent
4f253d4c67
commit
2bc19171ef
@ -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.
|
||||
*/
|
||||
moribund_socks = connection_count_moribund();
|
||||
|
||||
/* TODO pick what to try to close */
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user