aboutsummaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index a992b6e08e..29f34ca033 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -255,12 +255,12 @@ circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
if (! CIRCUIT_IS_ORIGIN(circ) &&
TO_OR_CIRCUIT(circ)->rend_splice &&
cell_direction == CELL_DIRECTION_OUT) {
- or_circuit_t *splice = TO_OR_CIRCUIT(circ)->rend_splice;
+ or_circuit_t *splice_ = TO_OR_CIRCUIT(circ)->rend_splice;
tor_assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
- tor_assert(splice->base_.purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
- cell->circ_id = splice->p_circ_id;
+ tor_assert(splice_->base_.purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
+ cell->circ_id = splice_->p_circ_id;
cell->command = CELL_RELAY; /* can't be relay_early anyway */
- if ((reason = circuit_receive_relay_cell(cell, TO_CIRCUIT(splice),
+ if ((reason = circuit_receive_relay_cell(cell, TO_CIRCUIT(splice_),
CELL_DIRECTION_IN)) < 0) {
log_warn(LD_REND, "Error relaying cell across rendezvous; closing "
"circuits");
@@ -383,6 +383,11 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
{
channel_t *chan; /* where to send the cell */
+ if (circ->marked_for_close) {
+ /* Circuit is marked; send nothing. */
+ return 0;
+ }
+
if (cell_direction == CELL_DIRECTION_OUT) {
crypt_path_t *thishop; /* counter for repeated crypts */
chan = circ->n_chan;
@@ -696,6 +701,12 @@ connection_edge_send_command(edge_connection_t *fromconn,
return -1;
}
+ if (circ->marked_for_close) {
+ /* The circuit has been marked, but not freed yet. When it's freed, it
+ * will mark this connection for close. */
+ return -1;
+ }
+
return relay_send_command_from_edge(fromconn->stream_id, circ,
relay_command, payload,
payload_len, cpath_layer);
@@ -859,6 +870,7 @@ connection_ap_process_end_not_open(
break; /* break means it'll close, below */
/* Else fall through: expire this circuit, clear the
* chosen_exit_name field, and try again. */
+ /* Falls through. */
case END_STREAM_REASON_RESOLVEFAILED:
case END_STREAM_REASON_TIMEOUT:
case END_STREAM_REASON_MISC:
@@ -1374,7 +1386,7 @@ connection_edge_process_relay_cell_not_open(
/* This is definitely a success, so forget about any pending data we
* had sent. */
if (entry_conn->pending_optimistic_data) {
- generic_buffer_free(entry_conn->pending_optimistic_data);
+ buf_free(entry_conn->pending_optimistic_data);
entry_conn->pending_optimistic_data = NULL;
}
@@ -1877,7 +1889,7 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
entry_conn->sending_optimistic_data != NULL;
if (PREDICT_UNLIKELY(sending_from_optimistic)) {
- bytes_to_process = generic_buffer_len(entry_conn->sending_optimistic_data);
+ bytes_to_process = buf_datalen(entry_conn->sending_optimistic_data);
if (PREDICT_UNLIKELY(!bytes_to_process)) {
log_warn(LD_BUG, "sending_optimistic_data was non-NULL but empty");
bytes_to_process = connection_get_inbuf_len(TO_CONN(conn));
@@ -1905,9 +1917,9 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
/* XXXX We could be more efficient here by sometimes packing
* previously-sent optimistic data in the same cell with data
* from the inbuf. */
- generic_buffer_get(entry_conn->sending_optimistic_data, payload, length);
- if (!generic_buffer_len(entry_conn->sending_optimistic_data)) {
- generic_buffer_free(entry_conn->sending_optimistic_data);
+ fetch_from_buf(payload, length, entry_conn->sending_optimistic_data);
+ if (!buf_datalen(entry_conn->sending_optimistic_data)) {
+ buf_free(entry_conn->sending_optimistic_data);
entry_conn->sending_optimistic_data = NULL;
}
} else {
@@ -1922,8 +1934,8 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
/* This is new optimistic data; remember it in case we need to detach and
retry */
if (!entry_conn->pending_optimistic_data)
- entry_conn->pending_optimistic_data = generic_buffer_new();
- generic_buffer_add(entry_conn->pending_optimistic_data, payload, length);
+ entry_conn->pending_optimistic_data = buf_new();
+ write_to_buf(payload, length, entry_conn->pending_optimistic_data);
}
if (connection_edge_send_command(conn, RELAY_COMMAND_DATA,
@@ -2321,14 +2333,12 @@ cell_queue_append_packed_copy(circuit_t *circ, cell_queue_t *queue,
int exitward, const cell_t *cell,
int wide_circ_ids, int use_stats)
{
- struct timeval now;
packed_cell_t *copy = packed_cell_copy(cell, wide_circ_ids);
(void)circ;
(void)exitward;
(void)use_stats;
- tor_gettimeofday_cached_monotonic(&now);
- copy->inserted_time = (uint32_t)tv_to_msec(&now);
+ copy->inserted_time = (uint32_t) monotime_coarse_absolute_msec();
cell_queue_append(queue, copy);
}
@@ -2407,14 +2417,11 @@ destroy_cell_queue_append(destroy_cell_queue_t *queue,
circid_t circid,
uint8_t reason)
{
- struct timeval now;
-
destroy_cell_t *cell = tor_malloc_zero(sizeof(destroy_cell_t));
cell->circid = circid;
cell->reason = reason;
- tor_gettimeofday_cached_monotonic(&now);
/* Not yet used, but will be required for OOM handling. */
- cell->inserted_time = (uint32_t)tv_to_msec(&now);
+ cell->inserted_time = (uint32_t) monotime_coarse_absolute_msec();
TOR_SIMPLEQ_INSERT_TAIL(&queue->head, cell, next);
++queue->n;
@@ -2526,7 +2533,7 @@ update_circuit_on_cmux_(circuit_t *circ, cell_direction_t direction,
/* Cmux sanity check */
if (! circuitmux_is_circuit_attached(cmux, circ)) {
- log_warn(LD_BUG, "called on non-attachd circuit from %s:%d",
+ log_warn(LD_BUG, "called on non-attached circuit from %s:%d",
file, lineno);
return;
}
@@ -2595,7 +2602,7 @@ set_streams_blocked_on_circ(circuit_t *circ, channel_t *chan,
edge->edge_blocked_on_circ = block;
}
- if (!conn->read_event && !HAS_BUFFEREVENT(conn)) {
+ if (!conn->read_event) {
/* This connection is a placeholder for something; probably a DNS
* request. It can't actually stop or start reading.*/
continue;
@@ -2716,9 +2723,8 @@ channel_flush_from_first_active_circuit, (channel_t *chan, int max))
if (get_options()->CellStatistics ||
get_options()->TestingEnableCellStatsEvent) {
uint32_t msec_waiting;
- struct timeval tvnow;
- tor_gettimeofday_cached(&tvnow);
- msec_waiting = ((uint32_t)tv_to_msec(&tvnow)) - cell->inserted_time;
+ uint32_t msec_now = (uint32_t)monotime_coarse_absolute_msec();
+ msec_waiting = msec_now - cell->inserted_time;
if (get_options()->CellStatistics && !CIRCUIT_IS_ORIGIN(circ)) {
or_circ = TO_OR_CIRCUIT(circ);