diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-03-17 10:14:35 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-03-17 10:16:41 -0400 |
commit | 320dcf65b7c8e382b27260a037bd1e93e563ccb9 (patch) | |
tree | a42f76d15d4cbee6bf685e4aad199cc8f08b49de /src/or/relay.c | |
parent | 298932605495dc9ef3e8e068c36a80a517036195 (diff) | |
download | tor-320dcf65b7c8e382b27260a037bd1e93e563ccb9.tar.gz tor-320dcf65b7c8e382b27260a037bd1e93e563ccb9.zip |
Extract the crypto parts of circuit_package_relay_cell.
Diffstat (limited to 'src/or/relay.c')
-rw-r--r-- | src/or/relay.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/or/relay.c b/src/or/relay.c index fad8b38b42..9431c93be9 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -487,6 +487,42 @@ relay_decrypt_cell(circuit_t *circ, cell_t *cell, return 0; } +/** + * Encrypt a cell <b>cell</b> that we are creating, and sending outbound on + * <b>circ</b> until the hop corresponding to <b>layer_hint</b>. + */ +void +relay_encrypt_cell_outbound(cell_t *cell, + origin_circuit_t *circ, + crypt_path_t *layer_hint) +{ + crypt_path_t *thishop; /* counter for repeated crypts */ + relay_set_digest(layer_hint->f_digest, cell); + + thishop = layer_hint; + /* moving from farthest to nearest hop */ + do { + tor_assert(thishop); + log_debug(LD_OR,"encrypting a layer of the relay cell."); + relay_crypt_one_payload(thishop->f_crypto, cell->payload); + + thishop = thishop->prev; + } while (thishop != circ->cpath->prev); +} + +/** + * Encrypt a cell <b>cell</b> that we are creating, and sending on + * <b>circuit</b> to the origin. + */ +void +relay_encrypt_cell_inbound(cell_t *cell, + or_circuit_t *or_circ) +{ + relay_set_digest(or_circ->p_digest, cell); + /* encrypt one layer */ + relay_crypt_one_payload(or_circ->p_crypto, cell->payload); +} + /** Package a relay cell from an edge: * - Encrypt it to the right layer * - Append it to the appropriate cell_queue on <b>circ</b>. @@ -505,7 +541,6 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ, } if (cell_direction == CELL_DIRECTION_OUT) { - crypt_path_t *thishop; /* counter for repeated crypts */ chan = circ->n_chan; if (!chan) { log_warn(LD_BUG,"outgoing relay cell sent from %s:%d has n_chan==NULL." @@ -528,20 +563,8 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ, return 0; /* just drop it */ } - relay_set_digest(layer_hint->f_digest, cell); - - thishop = layer_hint; - /* moving from farthest to nearest hop */ - do { - tor_assert(thishop); - log_debug(LD_OR,"encrypting a layer of the relay cell."); - relay_crypt_one_payload(thishop->f_crypto, cell->payload); - - thishop = thishop->prev; - } while (thishop != TO_ORIGIN_CIRCUIT(circ)->cpath->prev); - + relay_encrypt_cell_outbound(cell, TO_ORIGIN_CIRCUIT(circ), layer_hint); } else { /* incoming cell */ - or_circuit_t *or_circ; if (CIRCUIT_IS_ORIGIN(circ)) { /* We should never package an _incoming_ cell from the circuit * origin; that means we messed up somewhere. */ @@ -549,11 +572,9 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ, assert_circuit_ok(circ); return 0; /* just drop it */ } - or_circ = TO_OR_CIRCUIT(circ); + or_circuit_t *or_circ = TO_OR_CIRCUIT(circ); + relay_encrypt_cell_inbound(cell, or_circ); chan = or_circ->p_chan; - relay_set_digest(or_circ->p_digest, cell); - /* encrypt one layer */ - relay_crypt_one_payload(or_circ->p_crypto, cell->payload); } ++stats_n_relay_cells_relayed; |