mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Add unittests for the new machines.
This commit is contained in:
parent
ac895fa405
commit
953dc601d9
@ -2034,7 +2034,8 @@ circpad_shutdown_old_machines(origin_circuit_t *on_circ)
|
||||
}
|
||||
|
||||
/**
|
||||
* Negotiate new machines that would apply to this circuit.
|
||||
* Negotiate new machines that would apply to this circuit, given the machines
|
||||
* inside <b>machines_sl</b>.
|
||||
*
|
||||
* This function checks to see if we have any free machine indexes,
|
||||
* and for each free machine index, it initializes the most recently
|
||||
@ -2042,14 +2043,15 @@ circpad_shutdown_old_machines(origin_circuit_t *on_circ)
|
||||
* index and circuit conditions, and negotiates it with the appropriate
|
||||
* middle relay.
|
||||
*/
|
||||
static void
|
||||
circpad_add_matching_machines(origin_circuit_t *on_circ)
|
||||
STATIC void
|
||||
circpad_add_matching_machines(origin_circuit_t *on_circ,
|
||||
smartlist_t *machines_sl)
|
||||
{
|
||||
circuit_t *circ = TO_CIRCUIT(on_circ);
|
||||
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
/* Tests don't have to init our padding machines */
|
||||
if (!origin_padding_machines)
|
||||
if (!machines_sl)
|
||||
return;
|
||||
#endif
|
||||
|
||||
@ -2066,7 +2068,7 @@ circpad_add_matching_machines(origin_circuit_t *on_circ)
|
||||
/* We have a free machine index. Check the origin padding
|
||||
* machines in reverse order, so that more recently added
|
||||
* machines take priority over older ones. */
|
||||
SMARTLIST_FOREACH_REVERSE_BEGIN(origin_padding_machines,
|
||||
SMARTLIST_FOREACH_REVERSE_BEGIN(machines_sl,
|
||||
circpad_machine_spec_t *,
|
||||
machine) {
|
||||
/* Machine definitions have a specific target machine index.
|
||||
@ -2117,7 +2119,7 @@ circpad_machine_event_circ_added_hop(origin_circuit_t *on_circ)
|
||||
{
|
||||
/* Since our padding conditions do not specify a max_hops,
|
||||
* all we can do is add machines here */
|
||||
circpad_add_matching_machines(on_circ);
|
||||
circpad_add_matching_machines(on_circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2130,7 +2132,7 @@ void
|
||||
circpad_machine_event_circ_built(origin_circuit_t *circ)
|
||||
{
|
||||
circpad_shutdown_old_machines(circ);
|
||||
circpad_add_matching_machines(circ);
|
||||
circpad_add_matching_machines(circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2143,7 +2145,7 @@ void
|
||||
circpad_machine_event_circ_purpose_changed(origin_circuit_t *circ)
|
||||
{
|
||||
circpad_shutdown_old_machines(circ);
|
||||
circpad_add_matching_machines(circ);
|
||||
circpad_add_matching_machines(circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2157,7 +2159,7 @@ void
|
||||
circpad_machine_event_circ_has_no_relay_early(origin_circuit_t *circ)
|
||||
{
|
||||
circpad_shutdown_old_machines(circ);
|
||||
circpad_add_matching_machines(circ);
|
||||
circpad_add_matching_machines(circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2172,7 +2174,7 @@ void
|
||||
circpad_machine_event_circ_has_streams(origin_circuit_t *circ)
|
||||
{
|
||||
circpad_shutdown_old_machines(circ);
|
||||
circpad_add_matching_machines(circ);
|
||||
circpad_add_matching_machines(circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2187,7 +2189,7 @@ void
|
||||
circpad_machine_event_circ_has_no_streams(origin_circuit_t *circ)
|
||||
{
|
||||
circpad_shutdown_old_machines(circ);
|
||||
circpad_add_matching_machines(circ);
|
||||
circpad_add_matching_machines(circ, origin_padding_machines);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2682,8 +2684,8 @@ circpad_node_supports_padding(const node_t *node)
|
||||
* Returns node_t from the consensus for that hop, if it is opened.
|
||||
* Otherwise returns NULL.
|
||||
*/
|
||||
static const node_t *
|
||||
circuit_get_nth_node(origin_circuit_t *circ, int hop)
|
||||
MOCK_IMPL(STATIC const node_t *,
|
||||
circuit_get_nth_node,(origin_circuit_t *circ, int hop))
|
||||
{
|
||||
crypt_path_t *iter = circuit_get_cpath_hop(circ, hop);
|
||||
|
||||
|
@ -786,10 +786,17 @@ circpad_send_command_to_hop,(struct origin_circuit_t *circ, uint8_t hopnum,
|
||||
uint8_t relay_command, const uint8_t *payload,
|
||||
ssize_t payload_len));
|
||||
|
||||
MOCK_DECL(STATIC const node_t *,
|
||||
circuit_get_nth_node,(origin_circuit_t *circ, int hop));
|
||||
|
||||
STATIC circpad_delay_t
|
||||
histogram_get_bin_upper_bound(const circpad_machine_runtime_t *mi,
|
||||
circpad_hist_index_t bin);
|
||||
|
||||
STATIC void
|
||||
circpad_add_matching_machines(origin_circuit_t *on_circ,
|
||||
smartlist_t *machines_sl);
|
||||
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
extern smartlist_t *origin_padding_machines;
|
||||
extern smartlist_t *relay_padding_machines;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#define TOR_CHANNEL_INTERNAL_
|
||||
#define TOR_TIMERS_PRIVATE
|
||||
#define CIRCUITPADDING_PRIVATE
|
||||
#define CIRCUITPADDING_MACHINES_PRIVATE
|
||||
#define NETWORKSTATUS_PRIVATE
|
||||
#define CRYPT_PATH_PRIVATE
|
||||
|
||||
@ -19,6 +20,7 @@
|
||||
#include "core/or/circuitlist.h"
|
||||
#include "core/or/circuitbuild.h"
|
||||
#include "core/or/circuitpadding.h"
|
||||
#include "core/or/circuitpadding_machines.h"
|
||||
#include "core/mainloop/netstatus.h"
|
||||
#include "core/crypto/relay_crypto.h"
|
||||
#include "core/or/protover.h"
|
||||
@ -112,6 +114,15 @@ node_get_by_id_mock(const char *identity_digest)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const node_t *
|
||||
circuit_get_nth_node_mock(origin_circuit_t *circ, int hop)
|
||||
{
|
||||
(void) circ;
|
||||
(void) hop;
|
||||
|
||||
return &padding_node;
|
||||
}
|
||||
|
||||
static or_circuit_t *
|
||||
new_fake_orcirc(channel_t *nchan, channel_t *pchan)
|
||||
{
|
||||
@ -2652,8 +2663,8 @@ test_circuitpadding_reduce_disable(void *arg)
|
||||
simulate_single_hop_extend(client_side, relay_side, 1);
|
||||
|
||||
/* Verify that machine #0 is added */
|
||||
tt_int_op(client_side->padding_machine[0]->machine_num, OP_EQ, 0);
|
||||
tt_int_op(relay_side->padding_machine[0]->machine_num, OP_EQ, 0);
|
||||
tt_int_op(client_side->padding_machine[0]->machine_num, OP_EQ, 2);
|
||||
tt_int_op(relay_side->padding_machine[0]->machine_num, OP_EQ, 2);
|
||||
|
||||
tt_int_op(
|
||||
circpad_machine_reached_padding_limit(client_side->padding_info[0]),
|
||||
@ -2698,8 +2709,8 @@ test_circuitpadding_reduce_disable(void *arg)
|
||||
simulate_single_hop_extend(client_side, relay_side, 1);
|
||||
|
||||
/* Verify that machine #0 is added */
|
||||
tt_int_op(client_side->padding_machine[0]->machine_num, OP_EQ, 0);
|
||||
tt_int_op(relay_side->padding_machine[0]->machine_num, OP_EQ, 0);
|
||||
tt_int_op(client_side->padding_machine[0]->machine_num, OP_EQ, 2);
|
||||
tt_int_op(relay_side->padding_machine[0]->machine_num, OP_EQ, 2);
|
||||
|
||||
tt_int_op(
|
||||
circpad_machine_reached_padding_limit(client_side->padding_info[0]),
|
||||
@ -2989,18 +3000,12 @@ helper_test_hs_machines(bool test_intro_circs)
|
||||
tt_int_op(relay_side->padding_info[0]->current_state, OP_EQ,
|
||||
CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP);
|
||||
|
||||
/* For rendezvous circuit machines we can stop early since are simpler than
|
||||
* the intro circuit machines. */
|
||||
if (!test_intro_circs) {
|
||||
tt_int_op(client_side->padding_info[0]->histogram[0], OP_EQ, 1);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Check that the state lengths have been sampled and are within range */
|
||||
circpad_machine_runtime_t *client_machine_runtime =
|
||||
client_side->padding_info[0];
|
||||
circpad_machine_runtime_t *relay_machine_runtime =
|
||||
relay_side->padding_info[0];
|
||||
|
||||
if (test_intro_circs) {
|
||||
tt_int_op(client_machine_runtime->state_length, OP_GE,
|
||||
INTRO_MACHINE_MINIMUM_PADDING);
|
||||
@ -3127,5 +3132,6 @@ struct testcase_t circuitpadding_tests[] = {
|
||||
TEST_CIRCUITPADDING(circuitpadding_closest_token_removal_usec, TT_FORK),
|
||||
TEST_CIRCUITPADDING(circuitpadding_token_removal_exact, TT_FORK),
|
||||
TEST_CIRCUITPADDING(circuitpadding_manage_circuit_lifetime, TT_FORK),
|
||||
TEST_CIRCUITPADDING(circuitpadding_hs_machines, TT_FORK),
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user