|
@@ -1367,6 +1367,7 @@ CALLBACK(write_bridge_ns);
|
|
|
CALLBACK(write_stats_file);
|
|
|
CALLBACK(control_per_second_events);
|
|
|
CALLBACK(second_elapsed);
|
|
|
+CALLBACK(check_network_participation);
|
|
|
|
|
|
#undef CALLBACK
|
|
|
|
|
@@ -1396,6 +1397,7 @@ STATIC periodic_event_item_t periodic_events[] = {
|
|
|
CALLBACK(fetch_networkstatus, NET_PARTICIPANT, 0),
|
|
|
CALLBACK(launch_descriptor_fetches, NET_PARTICIPANT, FL(NEED_NET)),
|
|
|
CALLBACK(rotate_x509_certificate, NET_PARTICIPANT, 0),
|
|
|
+ CALLBACK(check_network_participation, NET_PARTICIPANT, 0),
|
|
|
|
|
|
/* We need to do these if we're participating in the Tor network, and
|
|
|
* immediately before we stop. */
|
|
@@ -1998,6 +2000,54 @@ add_entropy_callback(time_t now, const or_options_t *options)
|
|
|
return ENTROPY_INTERVAL;
|
|
|
}
|
|
|
|
|
|
+/** Periodic callback: if there has been no network usage in a while,
|
|
|
+ * enter a dormant state. */
|
|
|
+static int
|
|
|
+check_network_participation_callback(time_t now, const or_options_t *options)
|
|
|
+{
|
|
|
+ /* If we're a server, we can't become dormant. */
|
|
|
+ if (server_mode(options)) {
|
|
|
+ goto found_activity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* If we're running an onion service, we can't become dormant. */
|
|
|
+ /* XXXX this would be nice to change, so that we can be dormant with a
|
|
|
+ * service. */
|
|
|
+ if (hs_service_get_num_services() || rend_num_services()) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 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) {
|
|
|
+ log_notice(LD_GENERAL, "No user activity in a long time: becoming"
|
|
|
+ " dormant.");
|
|
|
+ set_network_participation(false);
|
|
|
+ rescan_periodic_events(options);
|
|
|
+ }
|
|
|
+
|
|
|
+ return CHECK_PARTICIPATION_INTERVAL;
|
|
|
+
|
|
|
+ found_activity:
|
|
|
+ note_user_activity(now);
|
|
|
+ return CHECK_PARTICIPATION_INTERVAL;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Periodic callback: if we're an authority, make sure we test
|
|
|
* the routers on the network for reachability.
|