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.
This commit is contained in:
George Kadianakis 2019-03-13 14:54:01 +02:00 committed by teor
parent fe78ba855a
commit bc64fb4e33
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A
3 changed files with 16 additions and 1 deletions

View File

@ -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) {

View File

@ -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 */

View File

@ -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();