Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket25573 034 #299

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions changes/ticket25573
@@ -0,0 +1,5 @@
o Minor features (controller):
- For purposes of CIRC_BW-based dropped cell detection, track half-closed
stream ids, and allow their ENDs, SENDMEs, DATA and path bias check
cells to arrive without counting it as dropped until either the END arrvies,
or the windows are empty. Closes ticket 25573.
2 changes: 1 addition & 1 deletion src/common/container.c
Expand Up @@ -628,7 +628,7 @@ smartlist_uniq(smartlist_t *sl,
* less than member, and greater than 0 if key is greater then member.
*/
void *
smartlist_bsearch(smartlist_t *sl, const void *key,
smartlist_bsearch(const smartlist_t *sl, const void *key,
int (*compare)(const void *key, const void **member))
{
int found, idx;
Expand Down
2 changes: 1 addition & 1 deletion src/common/container.h
Expand Up @@ -120,7 +120,7 @@ const uint8_t *smartlist_get_most_frequent_digest256(smartlist_t *sl);
void smartlist_uniq_strings(smartlist_t *sl);
void smartlist_uniq_digests(smartlist_t *sl);
void smartlist_uniq_digests256(smartlist_t *sl);
void *smartlist_bsearch(smartlist_t *sl, const void *key,
void *smartlist_bsearch(const smartlist_t *sl, const void *key,
int (*compare)(const void *key, const void **member));
int smartlist_bsearch_idx(const smartlist_t *sl, const void *key,
int (*compare)(const void *key, const void **member),
Expand Down
63 changes: 63 additions & 0 deletions src/or/circpathbias.c
Expand Up @@ -893,6 +893,7 @@ pathbias_check_probe_response(circuit_t *circ, const cell_t *cell)
/* Check nonce */
if (ipv4_host == ocirc->pathbias_probe_nonce) {
pathbias_mark_use_success(ocirc);
circuit_read_valid_data(ocirc, rh.length);
circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
log_info(LD_CIRC,
"Got valid path bias probe back for circ %d, stream %d.",
Expand All @@ -913,6 +914,68 @@ pathbias_check_probe_response(circuit_t *circ, const cell_t *cell)
return -1;
}

/**
* Check if a cell is counts as valid data for a circuit,
* and if so, count it as valid.
*/
void
pathbias_count_valid_cells(circuit_t *circ, const cell_t *cell)
{
origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
relay_header_t rh;

relay_header_unpack(&rh, cell->payload);

/* Check to see if this is a cell from a previous connection,
* or is a request to close the circuit. */
switch (rh.command) {
case RELAY_COMMAND_TRUNCATED:
/* Truncated cells can arrive on path bias circs. When they do,
* just process them. This closes the circ, but it was junk anyway.
* No reason to wait for the probe. */
circuit_read_valid_data(ocirc, rh.length);
circuit_truncated(TO_ORIGIN_CIRCUIT(circ),
get_uint8(cell->payload + RELAY_HEADER_SIZE));

break;

case RELAY_COMMAND_END:
if (connection_half_edge_is_valid_end(ocirc->half_streams,
rh.stream_id)) {
circuit_read_valid_data(TO_ORIGIN_CIRCUIT(circ), rh.length);
}
break;

case RELAY_COMMAND_DATA:
if (connection_half_edge_is_valid_data(ocirc->half_streams,
rh.stream_id)) {
circuit_read_valid_data(TO_ORIGIN_CIRCUIT(circ), rh.length);
}
break;

case RELAY_COMMAND_SENDME:
if (connection_half_edge_is_valid_sendme(ocirc->half_streams,
rh.stream_id)) {
circuit_read_valid_data(TO_ORIGIN_CIRCUIT(circ), rh.length);
}
break;

case RELAY_COMMAND_CONNECTED:
if (connection_half_edge_is_valid_connected(ocirc->half_streams,
rh.stream_id)) {
circuit_read_valid_data(TO_ORIGIN_CIRCUIT(circ), rh.length);
}
break;

case RELAY_COMMAND_RESOLVED:
if (connection_half_edge_is_valid_resolved(ocirc->half_streams,
rh.stream_id)) {
circuit_read_valid_data(TO_ORIGIN_CIRCUIT(circ), rh.length);
}
break;
}
}

/**
* Check if a circuit was used and/or closed successfully.
*
Expand Down
1 change: 1 addition & 0 deletions src/or/circpathbias.h
Expand Up @@ -20,6 +20,7 @@ void pathbias_count_build_success(origin_circuit_t *circ);
int pathbias_count_build_attempt(origin_circuit_t *circ);
int pathbias_check_close(origin_circuit_t *circ, int reason);
int pathbias_check_probe_response(circuit_t *circ, const cell_t *cell);
void pathbias_count_valid_cells(circuit_t *circ, const cell_t *cell);
void pathbias_count_use_attempt(origin_circuit_t *circ);
void pathbias_mark_use_success(origin_circuit_t *circ);
void pathbias_mark_use_rollback(origin_circuit_t *circ);
Expand Down
3 changes: 1 addition & 2 deletions src/or/circuitbuild.c
Expand Up @@ -1419,13 +1419,12 @@ circuit_finish_handshake(origin_circuit_t *circ,
* just give up: force circ to close, and return 0.
*/
int
circuit_truncated(origin_circuit_t *circ, crypt_path_t *layer, int reason)
circuit_truncated(origin_circuit_t *circ, int reason)
{
// crypt_path_t *victim;
// connection_t *stream;

tor_assert(circ);
tor_assert(layer);

/* XXX Since we don't send truncates currently, getting a truncated
* means that a connection broke or an extend failed. For now,
Expand Down
3 changes: 1 addition & 2 deletions src/or/circuitbuild.h
Expand Up @@ -37,8 +37,7 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath,
struct created_cell_t;
int circuit_finish_handshake(origin_circuit_t *circ,
const struct created_cell_t *created_cell);
int circuit_truncated(origin_circuit_t *circ, crypt_path_t *layer,
int reason);
int circuit_truncated(origin_circuit_t *circ, int reason);
int onionskin_answer(or_circuit_t *circ,
const struct created_cell_t *created_cell,
const char *keys, size_t keys_len,
Expand Down
8 changes: 8 additions & 0 deletions src/or/circuitlist.c
Expand Up @@ -1041,6 +1041,14 @@ circuit_free_(circuit_t *circ)

circuit_remove_from_origin_circuit_list(ocirc);

if (ocirc->half_streams) {
SMARTLIST_FOREACH_BEGIN(ocirc->half_streams, half_edge_t*,
half_conn) {
tor_free(half_conn);
} SMARTLIST_FOREACH_END(half_conn);
smartlist_free(ocirc->half_streams);
}

if (ocirc->build_state) {
extend_info_free(ocirc->build_state->chosen_exit);
circuit_free_cpath_node(ocirc->build_state->pending_final_cpath);
Expand Down