Ticket #7912: 223477

File 223477, 1.8 KB (added by asn, 6 years ago)
Line 
1int
2connection_or_send_destroy(circid_t circ_id, or_connection_t *conn, int reason)
3{
4  cell_t cell;
5  circuit_t *circ;
6  cell_direction_t direction = CELL_DIRECTION_IN;
7
8  tor_assert(conn);
9  circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
10  if (circ && conn == circ->n_conn)
11    direction = CELL_DIRECTION_OUT
12
13  memset(&cell, 0, sizeof(cell_t));
14  cell.circ_id = circ_id;
15  cell.command = CELL_DESTROY;
16  cell.payload[0] = (uint8_t) reason;
17  log_debug(LD_OR,"Sending destroy (circID %d).", circ_id);
18  if (!circ)
19    connection_or_write_cell_to_buf(&cell, conn);
20  else
21    append_cell_to_circuit_queue(circ, conn, &cell, direction, 0)
22  return 0;
23}
24
25void
26circuit_close_all_marked(void)
27{
28  circuit_t *tmp,*m;
29  int cells_on_queue;
30
31  while (global_circuitlist && global_circuitlist->marked_for_close) {
32    if (CIRCUIT_IS_ORIGIN(circ)) {
33      cells_on_queue = global_circuitlist->n_conn_cells.n;
34    } else {
35      or_circuit_t *or_circ = TO_OR_CIRCUIT(global_circuitlist);
36      cells_on_queue = or_circ->p_conn_cells.n +
37                       or_circ->n_conn_cells.n;
38    }
39    if (cells_on_queue)
40      break;
41    tmp = global_circuitlist->next;
42    circuit_free(global_circuitlist);
43    global_circuitlist = tmp;
44  }
45
46  tmp = global_circuitlist;
47  while (tmp && tmp->next) {
48    if (CIRCUIT_IS_ORIGIN(circ)) {
49      cells_on_queue = tmp->next->n_conn_cells.n;
50    } else {
51      or_circuit_t *or_circ = TO_OR_CIRCUIT(tmp->next);
52      cells_on_queue = or_circ->p_conn_cells.n +
53                       or_circ->n_conn_cells.n;
54    }
55    if (tmp->next->marked_for_close && !cells_on_queue) {
56      m = tmp->next->next;
57      circuit_free(tmp->next);
58      tmp->next = m;
59      /* Need to check new tmp->next; don't advance tmp. */
60    } else {
61      /* Advance tmp. */
62      tmp = tmp->next;
63    }
64  }
65}