mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +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;
|
||||
/* This cell is for us. Keep a record of this cell because we will
|
||||
* use it in the next SENDME cell. */
|
||||
if (sendme_circuit_is_next_cell(thishop->deliver_window)) {
|
||||
sendme_circuit_note_inbound_cell(thishop);
|
||||
if (sendme_circuit_cell_is_next(thishop->deliver_window)) {
|
||||
sendme_circuit_record_inbound_cell(thishop);
|
||||
}
|
||||
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
|
||||
* 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)) {
|
||||
sendme_circuit_note_outbound_cell(or_circ);
|
||||
if (sendme_circuit_cell_is_next(TO_CIRCUIT(or_circ)->package_window)) {
|
||||
sendme_circuit_record_outbound_cell(or_circ);
|
||||
}
|
||||
|
||||
/* 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()
|
||||
* because the cell digest is set within that function. */
|
||||
if (relay_command == RELAY_COMMAND_DATA) {
|
||||
sendme_note_cell_digest(circ);
|
||||
sendme_record_cell_digest(circ);
|
||||
}
|
||||
|
||||
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
|
||||
* is only done by the client as the circuit came back from the Exit. */
|
||||
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);
|
||||
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
|
||||
* is only done by the client as the circuit came back from the Exit. */
|
||||
void
|
||||
sendme_circuit_note_inbound_cell(crypt_path_t *cpath)
|
||||
sendme_circuit_record_inbound_cell(crypt_path_t *cpath)
|
||||
{
|
||||
tor_assert(cpath);
|
||||
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
|
||||
* window value. */
|
||||
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
|
||||
* 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.
|
||||
* It is safe to pass a circuit that isn't meant to track those digests. */
|
||||
void
|
||||
sendme_note_cell_digest(circuit_t *circ)
|
||||
sendme_record_cell_digest(circuit_t *circ)
|
||||
{
|
||||
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
|
||||
* package_window reaches a multiple of the increment, after this cell, we
|
||||
* should expect a SENDME. */
|
||||
if (!sendme_circuit_is_next_cell(circ->package_window)) {
|
||||
if (!sendme_circuit_cell_is_next(circ->package_window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,12 @@ int sendme_note_circuit_data_packaged(circuit_t *circ,
|
||||
int sendme_note_stream_data_packaged(edge_connection_t *conn);
|
||||
|
||||
/* Track cell digest. */
|
||||
void sendme_note_cell_digest(circuit_t *circ);
|
||||
void sendme_circuit_note_inbound_cell(crypt_path_t *cpath);
|
||||
void sendme_circuit_note_outbound_cell(or_circuit_t *or_circ);
|
||||
void sendme_record_cell_digest(circuit_t *circ);
|
||||
void sendme_circuit_record_inbound_cell(crypt_path_t *cpath);
|
||||
void sendme_circuit_record_outbound_cell(or_circuit_t *or_circ);
|
||||
|
||||
/* Circuit level information. */
|
||||
bool sendme_circuit_is_next_cell(int window);
|
||||
bool sendme_circuit_cell_is_next(int window);
|
||||
|
||||
/* Private section starts. */
|
||||
#ifdef SENDME_PRIVATE
|
||||
|
@ -43,7 +43,7 @@ free_mock_consensus(void)
|
||||
}
|
||||
|
||||
static void
|
||||
test_v1_note_digest(void *arg)
|
||||
test_v1_record_digest(void *arg)
|
||||
{
|
||||
or_circuit_t *or_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;
|
||||
|
||||
/* 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);
|
||||
/* We do not need the origin circuit for now. */
|
||||
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
|
||||
* shouldn't be noted. */
|
||||
circ->package_window = CIRCWINDOW_INCREMENT;
|
||||
sendme_note_cell_digest(circ);
|
||||
sendme_record_cell_digest(circ);
|
||||
tt_assert(!circ->sendme_last_digests);
|
||||
|
||||
/* This should work now. Package window at CIRCWINDOW_INCREMENT + 1. */
|
||||
circ->package_window++;
|
||||
sendme_note_cell_digest(circ);
|
||||
sendme_record_cell_digest(circ);
|
||||
tt_assert(circ->sendme_last_digests);
|
||||
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
|
||||
|
||||
/* Next cell in the package window shouldn't do anything. */
|
||||
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);
|
||||
|
||||
/* The next CIRCWINDOW_INCREMENT should add one more digest. */
|
||||
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);
|
||||
|
||||
done:
|
||||
@ -188,7 +188,7 @@ test_v1_build_cell(void *arg)
|
||||
|
||||
/* Note the wrong digest in the circuit, cell should fail validation. */
|
||||
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);
|
||||
setup_full_capture_of_logs(LOG_INFO);
|
||||
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. */
|
||||
memcpy(or_circ->crypto.sendme_digest, digest, sizeof(digest));
|
||||
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(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, true);
|
||||
/* 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[] = {
|
||||
{ "v1_note_digest", test_v1_note_digest, TT_FORK,
|
||||
{ "v1_record_digest", test_v1_record_digest, TT_FORK,
|
||||
NULL, NULL },
|
||||
{ "v1_consensus_params", test_v1_consensus_params, TT_FORK,
|
||||
NULL, NULL },
|
||||
|
Loading…
Reference in New Issue
Block a user