aboutsummaryrefslogtreecommitdiff
path: root/src/core/mainloop/mainloop.c
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/mainloop/mainloop.c
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/mainloop/mainloop.c')
-rw-r--r--src/core/mainloop/mainloop.c19
1 files changed, 10 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);