[tor-commits] [tor/master] circpad: Don't pad if Tor is in dormant mode.
teor at torproject.org
teor at torproject.org
Fri Mar 22 03:11:29 UTC 2019
commit bc64fb4e33ff98ca7271ee369fef24b3cf693574
Author: George Kadianakis <desnacked at riseup.net>
Date: Wed Mar 13 14:54:01 2019 +0200
circpad: Don't pad if Tor is in dormant mode.
This is something we should think about harder, but we probably want dormant
mode to be more powerful than padding in case a client has been inactive for a
day or so. After all, there are probably no circuits open at this point and
dormant mode will not allow the client to open more circuits.
Furthermore, padding should not block dormant mode from being activated, since
dormant mode relies on SocksPort activity, and circuit padding does not mess
with that.
---
src/core/or/circuitpadding.c | 9 ++++++++-
src/feature/hibernate/hibernate.h | 1 +
src/test/test_circuitpadding.c | 7 +++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c
index 2895d49e1..599d88f49 100644
--- a/src/core/or/circuitpadding.c
+++ b/src/core/or/circuitpadding.c
@@ -48,6 +48,7 @@
#include "core/or/circuitpadding.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/relay.h"
#include "feature/stats/rephist.h"
#include "feature/nodelist/networkstatus.h"
@@ -965,7 +966,7 @@ circpad_send_padding_cell_for_callback(circpad_machine_state_t *mi)
mi->padding_scheduled_at_usec = 0;
circpad_statenum_t state = mi->current_state;
- // Make sure circuit didn't close on us
+ /* Make sure circuit didn't close on us */
if (mi->on_circ->marked_for_close) {
log_fn(LOG_INFO,LD_CIRC,
"Padding callback on a circuit marked for close. Ignoring.");
@@ -1157,6 +1158,12 @@ circpad_machine_schedule_padding,(circpad_machine_state_t *mi))
struct timeval timeout;
tor_assert(mi);
+ /* Don't schedule padding if we are currently in dormant mode. */
+ if (!is_participating_on_network()) {
+ log_info(LD_CIRC, "Not scheduling padding because we are dormant.");
+ return CIRCPAD_STATE_UNCHANGED;
+ }
+
// Don't pad in end (but also don't cancel any previously
// scheduled padding either).
if (mi->current_state == CIRCPAD_STATE_END) {
diff --git a/src/feature/hibernate/hibernate.h b/src/feature/hibernate/hibernate.h
index 3309ef0ce..2e245f6ab 100644
--- a/src/feature/hibernate/hibernate.h
+++ b/src/feature/hibernate/hibernate.h
@@ -32,6 +32,7 @@ int getinfo_helper_accounting(control_connection_t *conn,
const char **errmsg);
uint64_t get_accounting_max_total(void);
void accounting_free_all(void);
+bool accounting_tor_is_dormant(void);
#ifdef HIBERNATE_PRIVATE
/** Possible values of hibernate_state */
diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c
index 1976e54bb..ba58cd0d9 100644
--- a/src/test/test_circuitpadding.c
+++ b/src/test/test_circuitpadding.c
@@ -17,6 +17,7 @@
#include "core/or/circuitlist.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitpadding.h"
+#include "core/mainloop/netstatus.h"
#include "core/crypto/relay_crypto.h"
#include "core/or/protover.h"
#include "feature/nodelist/nodelist.h"
@@ -1021,6 +1022,9 @@ test_circuitpadding_tokens(void *arg)
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
+ /* This is needed so that we are not considered to be dormant */
+ note_user_activity(20);
+
timers_initialize();
helper_create_basic_machine();
@@ -1750,6 +1754,9 @@ test_circuitpadding_conditions(void *arg)
monotime_coarse_set_mock_time_nsec(1*TOR_NSEC_PER_USEC);
curr_mocked_time = 1*TOR_NSEC_PER_USEC;
+ /* This is needed so that we are not considered to be dormant */
+ note_user_activity(20);
+
timers_initialize();
helper_create_conditional_machines();
More information about the tor-commits
mailing list