mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
sendme: Better function names
From nickm's review, improve the names of some functions. Part of #26288 Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
67c2254183
commit
0d8b9b56c5
@ -154,8 +154,8 @@ relay_decrypt_cell(circuit_t *circ, cell_t *cell,
|
|||||||
*layer_hint = thishop;
|
*layer_hint = thishop;
|
||||||
/* This cell is for us. Keep a record of this cell because we will
|
/* This cell is for us. Keep a record of this cell because we will
|
||||||
* use it in the next SENDME cell. */
|
* use it in the next SENDME cell. */
|
||||||
if (sendme_circuit_is_next_cell(thishop->deliver_window)) {
|
if (sendme_circuit_cell_is_next(thishop->deliver_window)) {
|
||||||
sendme_circuit_note_inbound_cell(thishop);
|
sendme_circuit_record_inbound_cell(thishop);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -230,8 +230,8 @@ relay_encrypt_cell_inbound(cell_t *cell,
|
|||||||
|
|
||||||
/* We are about to send this cell outbound on the circuit. Keep a record of
|
/* We are about to send this cell outbound on the circuit. Keep a record of
|
||||||
* this cell if we are expecting that the next cell is a SENDME. */
|
* this cell if we are expecting that the next cell is a SENDME. */
|
||||||
if (sendme_circuit_is_next_cell(TO_CIRCUIT(or_circ)->package_window)) {
|
if (sendme_circuit_cell_is_next(TO_CIRCUIT(or_circ)->package_window)) {
|
||||||
sendme_circuit_note_outbound_cell(or_circ);
|
sendme_circuit_record_outbound_cell(or_circ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* encrypt one layer */
|
/* encrypt one layer */
|
||||||
|
@ -701,7 +701,7 @@ relay_send_command_from_edge_,(streamid_t stream_id, circuit_t *circ,
|
|||||||
* we need to. This call needs to be after the circuit_package_relay_cell()
|
* we need to. This call needs to be after the circuit_package_relay_cell()
|
||||||
* because the cell digest is set within that function. */
|
* because the cell digest is set within that function. */
|
||||||
if (relay_command == RELAY_COMMAND_DATA) {
|
if (relay_command == RELAY_COMMAND_DATA) {
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -294,7 +294,7 @@ send_circuit_level_sendme(circuit_t *circ, crypt_path_t *layer_hint,
|
|||||||
/** Keep the current inbound cell digest for the next SENDME digest. This part
|
/** Keep the current inbound cell digest for the next SENDME digest. This part
|
||||||
* is only done by the client as the circuit came back from the Exit. */
|
* is only done by the client as the circuit came back from the Exit. */
|
||||||
void
|
void
|
||||||
sendme_circuit_note_outbound_cell(or_circuit_t *or_circ)
|
sendme_circuit_record_outbound_cell(or_circuit_t *or_circ)
|
||||||
{
|
{
|
||||||
tor_assert(or_circ);
|
tor_assert(or_circ);
|
||||||
relay_crypto_record_sendme_digest(&or_circ->crypto);
|
relay_crypto_record_sendme_digest(&or_circ->crypto);
|
||||||
@ -303,7 +303,7 @@ sendme_circuit_note_outbound_cell(or_circuit_t *or_circ)
|
|||||||
/** Keep the current inbound cell digest for the next SENDME digest. This part
|
/** Keep the current inbound cell digest for the next SENDME digest. This part
|
||||||
* is only done by the client as the circuit came back from the Exit. */
|
* is only done by the client as the circuit came back from the Exit. */
|
||||||
void
|
void
|
||||||
sendme_circuit_note_inbound_cell(crypt_path_t *cpath)
|
sendme_circuit_record_inbound_cell(crypt_path_t *cpath)
|
||||||
{
|
{
|
||||||
tor_assert(cpath);
|
tor_assert(cpath);
|
||||||
relay_crypto_record_sendme_digest(&cpath->crypto);
|
relay_crypto_record_sendme_digest(&cpath->crypto);
|
||||||
@ -316,7 +316,7 @@ sendme_circuit_note_inbound_cell(crypt_path_t *cpath)
|
|||||||
* one cell (the possible SENDME cell) should be a multiple of the increment
|
* one cell (the possible SENDME cell) should be a multiple of the increment
|
||||||
* window value. */
|
* window value. */
|
||||||
bool
|
bool
|
||||||
sendme_circuit_is_next_cell(int window)
|
sendme_circuit_cell_is_next(int window)
|
||||||
{
|
{
|
||||||
/* Is this the last cell before a SENDME? The idea is that if the package or
|
/* Is this the last cell before a SENDME? The idea is that if the package or
|
||||||
* deliver window reaches a multiple of the increment, after this cell, we
|
* deliver window reaches a multiple of the increment, after this cell, we
|
||||||
@ -578,7 +578,7 @@ sendme_note_stream_data_packaged(edge_connection_t *conn)
|
|||||||
/* Note the cell digest in the circuit sendme last digests FIFO if applicable.
|
/* Note the cell digest in the circuit sendme last digests FIFO if applicable.
|
||||||
* It is safe to pass a circuit that isn't meant to track those digests. */
|
* It is safe to pass a circuit that isn't meant to track those digests. */
|
||||||
void
|
void
|
||||||
sendme_note_cell_digest(circuit_t *circ)
|
sendme_record_cell_digest(circuit_t *circ)
|
||||||
{
|
{
|
||||||
const uint8_t *digest;
|
const uint8_t *digest;
|
||||||
|
|
||||||
@ -592,7 +592,7 @@ sendme_note_cell_digest(circuit_t *circ)
|
|||||||
/* Is this the last cell before a SENDME? The idea is that if the
|
/* Is this the last cell before a SENDME? The idea is that if the
|
||||||
* package_window reaches a multiple of the increment, after this cell, we
|
* package_window reaches a multiple of the increment, after this cell, we
|
||||||
* should expect a SENDME. */
|
* should expect a SENDME. */
|
||||||
if (!sendme_circuit_is_next_cell(circ->package_window)) {
|
if (!sendme_circuit_cell_is_next(circ->package_window)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ int sendme_note_circuit_data_packaged(circuit_t *circ,
|
|||||||
int sendme_note_stream_data_packaged(edge_connection_t *conn);
|
int sendme_note_stream_data_packaged(edge_connection_t *conn);
|
||||||
|
|
||||||
/* Track cell digest. */
|
/* Track cell digest. */
|
||||||
void sendme_note_cell_digest(circuit_t *circ);
|
void sendme_record_cell_digest(circuit_t *circ);
|
||||||
void sendme_circuit_note_inbound_cell(crypt_path_t *cpath);
|
void sendme_circuit_record_inbound_cell(crypt_path_t *cpath);
|
||||||
void sendme_circuit_note_outbound_cell(or_circuit_t *or_circ);
|
void sendme_circuit_record_outbound_cell(or_circuit_t *or_circ);
|
||||||
|
|
||||||
/* Circuit level information. */
|
/* Circuit level information. */
|
||||||
bool sendme_circuit_is_next_cell(int window);
|
bool sendme_circuit_cell_is_next(int window);
|
||||||
|
|
||||||
/* Private section starts. */
|
/* Private section starts. */
|
||||||
#ifdef SENDME_PRIVATE
|
#ifdef SENDME_PRIVATE
|
||||||
|
@ -43,7 +43,7 @@ free_mock_consensus(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_v1_note_digest(void *arg)
|
test_v1_record_digest(void *arg)
|
||||||
{
|
{
|
||||||
or_circuit_t *or_circ = NULL;
|
or_circuit_t *or_circ = NULL;
|
||||||
origin_circuit_t *orig_circ = NULL;
|
origin_circuit_t *orig_circ = NULL;
|
||||||
@ -61,7 +61,7 @@ test_v1_note_digest(void *arg)
|
|||||||
circ->purpose = CIRCUIT_PURPOSE_S_REND_JOINED;
|
circ->purpose = CIRCUIT_PURPOSE_S_REND_JOINED;
|
||||||
|
|
||||||
/* We should never note SENDME digest on origin circuit. */
|
/* We should never note SENDME digest on origin circuit. */
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_assert(!circ->sendme_last_digests);
|
tt_assert(!circ->sendme_last_digests);
|
||||||
/* We do not need the origin circuit for now. */
|
/* We do not need the origin circuit for now. */
|
||||||
orig_circ = NULL;
|
orig_circ = NULL;
|
||||||
@ -73,23 +73,23 @@ test_v1_note_digest(void *arg)
|
|||||||
* in order to catched the CIRCWINDOW_INCREMENT-nth cell. Try something that
|
* in order to catched the CIRCWINDOW_INCREMENT-nth cell. Try something that
|
||||||
* shouldn't be noted. */
|
* shouldn't be noted. */
|
||||||
circ->package_window = CIRCWINDOW_INCREMENT;
|
circ->package_window = CIRCWINDOW_INCREMENT;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_assert(!circ->sendme_last_digests);
|
tt_assert(!circ->sendme_last_digests);
|
||||||
|
|
||||||
/* This should work now. Package window at CIRCWINDOW_INCREMENT + 1. */
|
/* This should work now. Package window at CIRCWINDOW_INCREMENT + 1. */
|
||||||
circ->package_window++;
|
circ->package_window++;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_assert(circ->sendme_last_digests);
|
tt_assert(circ->sendme_last_digests);
|
||||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
||||||
|
|
||||||
/* Next cell in the package window shouldn't do anything. */
|
/* Next cell in the package window shouldn't do anything. */
|
||||||
circ->package_window++;
|
circ->package_window++;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
||||||
|
|
||||||
/* The next CIRCWINDOW_INCREMENT should add one more digest. */
|
/* The next CIRCWINDOW_INCREMENT should add one more digest. */
|
||||||
circ->package_window = (CIRCWINDOW_INCREMENT * 2) + 1;
|
circ->package_window = (CIRCWINDOW_INCREMENT * 2) + 1;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 2);
|
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 2);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -188,7 +188,7 @@ test_v1_build_cell(void *arg)
|
|||||||
|
|
||||||
/* Note the wrong digest in the circuit, cell should fail validation. */
|
/* Note the wrong digest in the circuit, cell should fail validation. */
|
||||||
circ->package_window = CIRCWINDOW_INCREMENT + 1;
|
circ->package_window = CIRCWINDOW_INCREMENT + 1;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
||||||
setup_full_capture_of_logs(LOG_INFO);
|
setup_full_capture_of_logs(LOG_INFO);
|
||||||
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, false);
|
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, false);
|
||||||
@ -200,7 +200,7 @@ test_v1_build_cell(void *arg)
|
|||||||
/* Record the cell digest into the circuit, cell should validate. */
|
/* Record the cell digest into the circuit, cell should validate. */
|
||||||
memcpy(or_circ->crypto.sendme_digest, digest, sizeof(digest));
|
memcpy(or_circ->crypto.sendme_digest, digest, sizeof(digest));
|
||||||
circ->package_window = CIRCWINDOW_INCREMENT + 1;
|
circ->package_window = CIRCWINDOW_INCREMENT + 1;
|
||||||
sendme_note_cell_digest(circ);
|
sendme_record_cell_digest(circ);
|
||||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
||||||
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, true);
|
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, true);
|
||||||
/* After a validation, the last digests is always popped out. */
|
/* After a validation, the last digests is always popped out. */
|
||||||
@ -254,7 +254,7 @@ test_cell_payload_pad(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct testcase_t sendme_tests[] = {
|
struct testcase_t sendme_tests[] = {
|
||||||
{ "v1_note_digest", test_v1_note_digest, TT_FORK,
|
{ "v1_record_digest", test_v1_record_digest, TT_FORK,
|
||||||
NULL, NULL },
|
NULL, NULL },
|
||||||
{ "v1_consensus_params", test_v1_consensus_params, TT_FORK,
|
{ "v1_consensus_params", test_v1_consensus_params, TT_FORK,
|
||||||
NULL, NULL },
|
NULL, NULL },
|
||||||
|
Loading…
Reference in New Issue
Block a user