aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-11-15 13:16:58 -0500
committerNick Mathewson <nickm@torproject.org>2018-11-26 16:32:40 -0500
commit3743f7969587079a2f2bb03d0b7e5038557fd64a (patch)
treeaf8e96b1be0384be223e96167065e76e96922727 /src/core
parent53ccdb6945f0d4a9b27a9939211a3c9125ca4427 (diff)
downloadtor-3743f7969587079a2f2bb03d0b7e5038557fd64a.tar.gz
tor-3743f7969587079a2f2bb03d0b7e5038557fd64a.zip
Add options to control dormant-client feature.
The DormantClientTimeout option controls how long Tor will wait before going dormant. It also provides a way to disable the feature by setting DormantClientTimeout to e.g. "50 years". The DormantTimeoutDisabledByIdleStreams option controls whether open but inactive streams count as "client activity". To implement it, I had to make it so that reading or writing on a client stream *always* counts as activity. Closes ticket 28429.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/mainloop/mainloop.c19
-rw-r--r--src/core/or/connection_edge.c11
2 files changed, 21 insertions, 9 deletions
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index 2d12e26485..1bd186d856 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -2018,24 +2018,25 @@ check_network_participation_callback(time_t now, const or_options_t *options)
goto found_activity;
}
- /* XXXX Add an option to never become dormant. */
-
/* If we have any currently open entry streams other than "linked"
* connections used for directory requests, those count as user activity.
*/
- /* XXXX make this configurable? */
- if (connection_get_by_type_nonlinked(CONN_TYPE_AP) != NULL) {
- goto found_activity;
+ if (options->DormantTimeoutDisabledByIdleStreams) {
+ if (connection_get_by_type_nonlinked(CONN_TYPE_AP) != NULL) {
+ goto found_activity;
+ }
}
/* XXXX Make this configurable? */
/** How often do we check whether we have had network activity? */
#define CHECK_PARTICIPATION_INTERVAL (5*60)
- /** Become dormant if there has been no user activity in this long. */
- /* XXXX make this configurable! */
-#define BECOME_DORMANT_AFTER_INACTIVITY (24*60*60)
- if (get_last_user_activity_time() + BECOME_DORMANT_AFTER_INACTIVITY >= now) {
+ /* Become dormant if there has been no user activity in a long time.
+ * (The funny checks below are in order to prevent overflow.) */
+ time_t time_since_last_activity = 0;
+ if (get_last_user_activity_time() < now)
+ time_since_last_activity = now - get_last_user_activity_time();
+ if (time_since_last_activity >= options->DormantClientTimeout) {
log_notice(LD_GENERAL, "No user activity in a long time: becoming"
" dormant.");
set_network_participation(false);
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index 58aefcf8f2..7b51313e8a 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -62,6 +62,7 @@
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
@@ -297,6 +298,11 @@ connection_edge_process_inbuf(edge_connection_t *conn, int package_partial)
}
return 0;
case AP_CONN_STATE_OPEN:
+ if (! conn->base_.linked) {
+ note_user_activity(approx_time());
+ }
+
+ /* falls through. */
case EXIT_CONN_STATE_OPEN:
if (connection_edge_package_raw_inbuf(conn, package_partial, NULL) < 0) {
/* (We already sent an end cell if possible) */
@@ -751,6 +757,11 @@ connection_edge_flushed_some(edge_connection_t *conn)
{
switch (conn->base_.state) {
case AP_CONN_STATE_OPEN:
+ if (! conn->base_.linked) {
+ note_user_activity(approx_time());
+ }
+
+ /* falls through. */
case EXIT_CONN_STATE_OPEN:
connection_edge_consider_sending_sendme(conn);
break;