1 /* Copyright 2001 Matej Pfajfar.
2 * Copyright 2001-2004 Roger Dingledine.
3 * Copyright 2004-2005 Roger Dingledine, Nick Mathewson. */
4 /* See LICENSE for licensing information */
6 const char circuitlist_c_id
[] = "$Id$";
10 * \brief Manage the global circuit list.
13 #define NEW_LOG_INTERFACE
16 /* Define RB_AUGMENT to avoid warnings about if statements with emtpy bodies.
18 #define RB_AUGMENT(x) do{}while(0)
21 /********* START VARIABLES **********/
23 /** A global list of all circuits at this hop. */
24 circuit_t
*global_circuitlist
=NULL
;
26 static void circuit_free(circuit_t
*circ
);
27 static void circuit_free_cpath(crypt_path_t
*cpath
);
28 static void circuit_free_cpath_node(crypt_path_t
*victim
);
30 /********* END VARIABLES ************/
32 /** A map from OR connection and circuit ID to circuit. (Lookup performance is
33 * very important here, since we need to do it every time a cell arrives.) */
34 typedef struct orconn_circid_circuit_map_t
{
35 RB_ENTRY(orconn_circid_circuit_map_t
) node
;
36 connection_t
*or_conn
;
39 } orconn_circid_circuit_map_t
;
41 /** Helper for RB tree: compare the OR connection and circuit ID for a and b,
42 * and return less than, equal to, or greater than zero appropriately.
45 compare_orconn_circid_entries(orconn_circid_circuit_map_t
*a
,
46 orconn_circid_circuit_map_t
*b
)
48 if (a
->or_conn
< b
->or_conn
)
50 else if (a
->or_conn
> b
->or_conn
)
53 return ((int)b
->circ_id
) - ((int)a
->circ_id
);
56 static RB_HEAD(orconn_circid_tree
, orconn_circid_circuit_map_t
) orconn_circid_circuit_map
= RB_INITIALIZER(orconn_circid_circuit_map
);
57 RB_PROTOTYPE(orconn_circid_tree
, orconn_circid_circuit_map_t
, node
, compare_orconn_circid_entries
);
58 RB_GENERATE(orconn_circid_tree
, orconn_circid_circuit_map_t
, node
, compare_orconn_circid_entries
);
60 /** The most recently returned entry from circuit_get_by_circid_orconn;
61 * used to improve performance when many cells arrive in a row from the
64 /* (We tried using splay trees, but round-robin turned out to make them
66 orconn_circid_circuit_map_t
*_last_circid_orconn_ent
= NULL
;
68 /** Set the p_conn or n_conn field of a circuit <b>circ</b>, along
69 * with the corresponding circuit ID, and add the circuit as appropriate
70 * to the (orconn,id)-\>circuit map. */
72 circuit_set_circid_orconn(circuit_t
*circ
, uint16_t id
,
74 enum which_conn_changed_t which
)
77 connection_t
*old_conn
;
78 orconn_circid_circuit_map_t search
;
79 orconn_circid_circuit_map_t
*found
;
81 tor_assert(!conn
|| conn
->type
== CONN_TYPE_OR
);
83 if (which
== P_CONN_CHANGED
) {
84 old_id
= circ
->p_circ_id
;
85 old_conn
= circ
->p_conn
;
89 old_id
= circ
->n_circ_id
;
90 old_conn
= circ
->n_conn
;
95 if (_last_circid_orconn_ent
&&
96 ((old_id
== _last_circid_orconn_ent
->circ_id
&&
97 old_conn
== _last_circid_orconn_ent
->or_conn
) ||
98 (id
== _last_circid_orconn_ent
->circ_id
&&
99 conn
== _last_circid_orconn_ent
->or_conn
))) {
100 _last_circid_orconn_ent
= NULL
;
104 search
.circ_id
= old_id
;
105 search
.or_conn
= old_conn
;
106 found
= RB_FIND(orconn_circid_tree
, &orconn_circid_circuit_map
, &search
);
108 RB_REMOVE(orconn_circid_tree
, &orconn_circid_circuit_map
, found
);
117 search
.or_conn
= conn
;
118 found
= RB_FIND(orconn_circid_tree
, &orconn_circid_circuit_map
, &search
);
120 found
->circuit
= circ
;
122 found
= tor_malloc_zero(sizeof(orconn_circid_circuit_map_t
));
124 found
->or_conn
= conn
;
125 found
->circuit
= circ
;
126 RB_INSERT(orconn_circid_tree
, &orconn_circid_circuit_map
, found
);
130 /** Add <b>circ</b> to the global list of circuits. This is called only from
131 * within circuit_new.
134 circuit_add(circuit_t
*circ
)
136 if (!global_circuitlist
) { /* first one */
137 global_circuitlist
= circ
;
140 circ
->next
= global_circuitlist
;
141 global_circuitlist
= circ
;
145 /** Detach from the global circuit list, and deallocate, all
146 * circuits that have been marked for close.
149 circuit_close_all_marked(void)
153 while (global_circuitlist
&& global_circuitlist
->marked_for_close
) {
154 tmp
= global_circuitlist
->next
;
155 circuit_free(global_circuitlist
);
156 global_circuitlist
= tmp
;
159 tmp
= global_circuitlist
;
160 while (tmp
&& tmp
->next
) {
161 if (tmp
->next
->marked_for_close
) {
163 circuit_free(tmp
->next
);
165 /* Need to check new tmp->next; don't advance tmp. */
173 /** Return the head of the global linked list of circuits. **/
175 _circuit_get_global_list(void)
177 return global_circuitlist
;
180 /** Function to make circ-\>state human-readable */
182 circuit_state_to_string(int state
)
186 case CIRCUIT_STATE_BUILDING
: return "doing handshakes";
187 case CIRCUIT_STATE_ONIONSKIN_PENDING
: return "processing the onion";
188 case CIRCUIT_STATE_OR_WAIT
: return "connecting to firsthop";
189 case CIRCUIT_STATE_OPEN
: return "open";
191 warn(LD_BUG
, "Bug: unknown circuit state %d", state
);
192 tor_snprintf(buf
, sizeof(buf
), "unknown state [%d]", state
);
197 /** Allocate space for a new circuit, initializing with <b>p_circ_id</b>
198 * and <b>p_conn</b>. Add it to the global circuit list.
201 circuit_new(uint16_t p_circ_id
, connection_t
*p_conn
)
204 static uint32_t n_circuits_allocated
= 1;
205 /* never zero, since a global ID of 0 is treated specially by the
208 circ
= tor_malloc_zero(sizeof(circuit_t
));
209 circ
->magic
= CIRCUIT_MAGIC
;
211 circ
->timestamp_created
= time(NULL
);
213 circ
->state
= CIRCUIT_STATE_ONIONSKIN_PENDING
;
217 circuit_set_circid_orconn(circ
, p_circ_id
, p_conn
, P_CONN_CHANGED
);
219 /* circ->n_circ_id remains 0 because we haven't identified the next hop yet */
221 circ
->package_window
= CIRCWINDOW_START
;
222 circ
->deliver_window
= CIRCWINDOW_START
;
224 circ
->next_stream_id
= crypto_rand_int(1<<16);
225 circ
->global_identifier
= n_circuits_allocated
++;
232 /** Deallocate space associated with circ.
235 circuit_free(circuit_t
*circ
)
238 tor_assert(circ
->magic
== CIRCUIT_MAGIC
);
240 crypto_free_cipher_env(circ
->n_crypto
);
242 crypto_free_cipher_env(circ
->p_crypto
);
244 crypto_free_digest_env(circ
->n_digest
);
246 crypto_free_digest_env(circ
->p_digest
);
247 if (circ
->build_state
) {
248 if (circ
->build_state
->chosen_exit
)
249 extend_info_free(circ
->build_state
->chosen_exit
);
250 if (circ
->build_state
->pending_final_cpath
)
251 circuit_free_cpath_node(circ
->build_state
->pending_final_cpath
);
253 tor_free(circ
->build_state
);
254 circuit_free_cpath(circ
->cpath
);
255 if (circ
->rend_splice
) {
256 circ
->rend_splice
->rend_splice
= NULL
;
258 /* Remove from map. */
259 circuit_set_circid_orconn(circ
, 0, NULL
, P_CONN_CHANGED
);
260 circuit_set_circid_orconn(circ
, 0, NULL
, N_CONN_CHANGED
);
262 memset(circ
, 0xAA, sizeof(circuit_t
)); /* poison memory */
266 /** Deallocate space associated with the linked list <b>cpath</b>. */
268 circuit_free_cpath(crypt_path_t
*cpath
)
270 crypt_path_t
*victim
, *head
=cpath
;
275 /* it's a doubly linked list, so we have to notice when we've
276 * gone through it once. */
277 while (cpath
->next
&& cpath
->next
!= head
) {
279 cpath
= victim
->next
;
280 circuit_free_cpath_node(victim
);
283 circuit_free_cpath_node(cpath
);
286 /** Release all storage held by circuits. */
288 circuit_free_all(void)
291 while (global_circuitlist
) {
292 next
= global_circuitlist
->next
;
293 while (global_circuitlist
->resolving_streams
) {
295 next
= global_circuitlist
->resolving_streams
->next_stream
;
296 connection_free(global_circuitlist
->resolving_streams
);
297 global_circuitlist
->resolving_streams
= next
;
299 circuit_free(global_circuitlist
);
300 global_circuitlist
= next
;
304 /** Deallocate space associated with the cpath node <b>victim</b>. */
306 circuit_free_cpath_node(crypt_path_t
*victim
)
308 if (victim
->f_crypto
)
309 crypto_free_cipher_env(victim
->f_crypto
);
310 if (victim
->b_crypto
)
311 crypto_free_cipher_env(victim
->b_crypto
);
312 if (victim
->f_digest
)
313 crypto_free_digest_env(victim
->f_digest
);
314 if (victim
->b_digest
)
315 crypto_free_digest_env(victim
->b_digest
);
316 if (victim
->dh_handshake_state
)
317 crypto_dh_free(victim
->dh_handshake_state
);
318 if (victim
->extend_info
)
319 extend_info_free(victim
->extend_info
);
321 victim
->magic
= 0xDEADBEEFu
;
325 /** Return the circuit whose global ID is <b>id</b>, or NULL if no
326 * such circuit exists. */
328 circuit_get_by_global_id(uint32_t id
)
331 for (circ
=global_circuitlist
;circ
;circ
= circ
->next
) {
332 if (circ
->global_identifier
== id
) {
333 if (circ
->marked_for_close
)
342 /** Return a circ such that:
343 * - circ-\>n_circ_id or circ-\>p_circ_id is equal to <b>circ_id</b>, and
344 * - circ is attached to <b>conn</b>, either as p_conn or n_conn.
345 * Return NULL if no such circuit exists.
347 static INLINE circuit_t
*
348 circuit_get_by_circid_orconn_impl(uint16_t circ_id
, connection_t
*conn
)
350 orconn_circid_circuit_map_t search
;
351 orconn_circid_circuit_map_t
*found
;
353 tor_assert(conn
->type
== CONN_TYPE_OR
);
355 if (_last_circid_orconn_ent
&&
356 circ_id
== _last_circid_orconn_ent
->circ_id
&&
357 conn
== _last_circid_orconn_ent
->or_conn
) {
358 found
= _last_circid_orconn_ent
;
360 search
.circ_id
= circ_id
;
361 search
.or_conn
= conn
;
362 found
= RB_FIND(orconn_circid_tree
, &orconn_circid_circuit_map
, &search
);
363 _last_circid_orconn_ent
= found
;
365 if (found
&& found
->circuit
)
366 return found
->circuit
;
368 /* The rest of this can be replaced with
369 "return NULL;" once we believe the code works. */
373 for (circ
=global_circuitlist
;circ
;circ
= circ
->next
) {
374 if (circ
->p_conn
== conn
&& circ
->p_circ_id
== circ_id
) {
375 warn(LD_BUG
, "circuit matches p_conn, but not in tree (Bug!)");
378 if (circ
->n_conn
== conn
&& circ
->n_circ_id
== circ_id
) {
379 warn(LD_BUG
, "circuit matches n_conn, but not in tree (Bug!)");
387 /** Return a circ such that:
388 * - circ-\>n_circ_id or circ-\>p_circ_id is equal to <b>circ_id</b>, and
389 * - circ is attached to <b>conn</b>, either as p_conn or n_conn.
390 * - circ is not marked for close.
391 * Return NULL if no such circuit exists.
394 circuit_get_by_circid_orconn(uint16_t circ_id
, connection_t
*conn
)
396 circuit_t
*circ
= circuit_get_by_circid_orconn_impl(circ_id
, conn
);
397 if (circ
->marked_for_close
)
403 /** Return true iff there is a circ such that
404 * - circ-\>n_circ_id or circ-\>p_circ_id is equal to <b>circ_id</b>, and
405 * - circ is attached to <b>conn</b>, either as p_conn or n_conn.
406 * Return NULL if no such circuit exists.
409 circuit_id_used_on_conn(uint16_t circ_id
, connection_t
*conn
)
411 circuit_t
*circ
= circuit_get_by_circid_orconn_impl(circ_id
, conn
);
412 if (circ
&& circ
->marked_for_close
)
413 log_fn(LOG_NOTICE
, LD_CIRC
,
414 "I was about to re-use a circuit ID that had been marked."
415 " Good thing we fixed that bug!");
419 /** Return the circuit that a given edge connection is using. */
421 circuit_get_by_edge_conn(connection_t
*conn
)
425 connection_t
*tmpconn
;
427 tor_assert(CONN_IS_EDGE(conn
));
429 if (! conn
->on_circuit
) {
431 circ
= circuit_get_by_conn(conn
);
433 warn(LD_BUG
, "BUG: conn->on_circuit==NULL, but there was in fact a circuit there.");
438 circ
= conn
->on_circuit
;
439 tor_assert(circ
->magic
== CIRCUIT_MAGIC
);
441 /* All this stuff here is sanity-checking. */
442 for (tmpconn
= circ
->p_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
445 for (tmpconn
= circ
->n_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
448 for (tmpconn
= circ
->resolving_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
457 /** Return a circ such that circ is attached to <b>conn</b>, either as
458 * p_conn, n_conn, or in p_streams or n_streams or resolving_streams.
460 * Return NULL if no such circuit exists.
463 circuit_get_by_conn(connection_t
*conn
)
466 connection_t
*tmpconn
;
468 for (circ
=global_circuitlist
;circ
;circ
= circ
->next
) {
469 if (circ
->marked_for_close
)
472 if (circ
->p_conn
== conn
)
474 if (circ
->n_conn
== conn
)
476 for (tmpconn
= circ
->p_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
479 for (tmpconn
= circ
->n_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
482 for (tmpconn
= circ
->resolving_streams
; tmpconn
; tmpconn
=tmpconn
->next_stream
)
489 /** Return a circ such that:
490 * - circ-\>rend_query is equal to <b>rend_query</b>, and
491 * - circ-\>purpose is equal to <b>purpose</b>.
493 * Return NULL if no such circuit exists.
496 circuit_get_by_rend_query_and_purpose(const char *rend_query
, uint8_t purpose
)
500 for (circ
= global_circuitlist
; circ
; circ
= circ
->next
) {
501 if (!circ
->marked_for_close
&&
502 circ
->purpose
== purpose
&&
503 !rend_cmp_service_ids(rend_query
, circ
->rend_query
))
509 /** Return the first circuit in global_circuitlist after <b>start</b>
510 * whose rend_pk_digest field is <b>digest</b> and whose purpose is
511 * <b>purpose</b>. Returns NULL if no circuit is found.
512 * If <b>start</b> is NULL, begin at the start of the list.
515 circuit_get_next_by_pk_and_purpose(circuit_t
*start
,
516 const char *digest
, uint8_t purpose
)
520 circ
= global_circuitlist
;
524 for ( ; circ
; circ
= circ
->next
) {
525 if (circ
->marked_for_close
)
527 if (circ
->purpose
!= purpose
)
529 if (!memcmp(circ
->rend_pk_digest
, digest
, DIGEST_LEN
))
535 /** Return the circuit waiting for a rendezvous with the provided cookie.
536 * Return NULL if no such circuit is found.
539 circuit_get_rendezvous(const char *cookie
)
542 for (circ
= global_circuitlist
; circ
; circ
= circ
->next
) {
543 if (! circ
->marked_for_close
&&
544 circ
->purpose
== CIRCUIT_PURPOSE_REND_POINT_WAITING
&&
545 ! memcmp(circ
->rend_cookie
, cookie
, REND_COOKIE_LEN
) )
551 /** Return a circuit that is open, has specified <b>purpose</b>,
552 * has a timestamp_dirty value of 0, and is uptime/capacity/internal
553 * if required; or NULL if no circuit fits this description.
555 * Avoid returning need_uptime circuits if not necessary.
556 * FFFF As a more important goal, not yet implemented, avoid returning
557 * internal circuits if not necessary.
560 circuit_get_clean_open(uint8_t purpose
, int need_uptime
,
561 int need_capacity
, int internal
)
564 circuit_t
*best
=NULL
;
566 debug(LD_CIRC
,"Hunting for a circ to cannibalize: purpose %d, uptime %d, capacity %d, internal %d", purpose
, need_uptime
, need_capacity
, internal
);
568 for (circ
=global_circuitlist
; circ
; circ
= circ
->next
) {
569 if (CIRCUIT_IS_ORIGIN(circ
) &&
570 circ
->state
== CIRCUIT_STATE_OPEN
&&
571 !circ
->marked_for_close
&&
572 circ
->purpose
== purpose
&&
573 !circ
->timestamp_dirty
&&
574 (!need_uptime
|| circ
->build_state
->need_uptime
) &&
575 (!need_capacity
|| circ
->build_state
->need_capacity
) &&
576 (!internal
|| circ
->build_state
->is_internal
)) {
577 if (!best
|| (best
->build_state
->need_uptime
&& !need_uptime
))
584 /** Go through the circuitlist; mark-for-close each circuit that starts
585 * at us but has not yet been used. */
587 circuit_mark_all_unused_circs(void)
591 for (circ
=global_circuitlist
; circ
; circ
= circ
->next
) {
592 if (CIRCUIT_IS_ORIGIN(circ
) &&
593 !circ
->marked_for_close
&&
594 !circ
->timestamp_dirty
)
595 circuit_mark_for_close(circ
);
599 /** Go through the circuitlist; for each circuit that starts at us
600 * and is dirty, frob its timestamp_dirty so we won't use it for any
603 * This is useful for letting the user change pseudonyms, so new
604 * streams will not be linkable to old streams.
607 circuit_expire_all_dirty_circs(void)
610 or_options_t
*options
= get_options();
612 for (circ
=global_circuitlist
; circ
; circ
= circ
->next
) {
613 if (CIRCUIT_IS_ORIGIN(circ
) &&
614 !circ
->marked_for_close
&&
615 circ
->timestamp_dirty
)
616 circ
->timestamp_dirty
-= options
->MaxCircuitDirtiness
;
620 /** Mark <b>circ</b> to be closed next time we call
621 * circuit_close_all_marked(). Do any cleanup needed:
622 * - If state is onionskin_pending, remove circ from the onion_pending
624 * - If circ isn't open yet: call circuit_build_failed() if we're
625 * the origin, and in either case call circuit_rep_hist_note_result()
627 * - If purpose is C_INTRODUCE_ACK_WAIT, remove the intro point we
628 * just tried from our list of intro points for that service
630 * - Send appropriate destroys and edge_destroys for conns and
631 * streams attached to circ.
632 * - If circ->rend_splice is set (we are the midpoint of a joined
633 * rendezvous stream), then mark the other circuit to close as well.
636 _circuit_mark_for_close(circuit_t
*circ
, int line
, const char *file
)
640 assert_circuit_ok(circ
);
644 if (circ
->marked_for_close
) {
646 "Duplicate call to circuit_mark_for_close at %s:%d"
647 " (first at %s:%d)", file
, line
,
648 circ
->marked_for_close_file
, circ
->marked_for_close
);
652 if (circ
->state
== CIRCUIT_STATE_ONIONSKIN_PENDING
) {
653 onion_pending_remove(circ
);
655 /* If the circuit ever became OPEN, we sent it to the reputation history
656 * module then. If it isn't OPEN, we send it there now to remember which
657 * links worked and which didn't.
659 if (circ
->state
!= CIRCUIT_STATE_OPEN
) {
660 if (CIRCUIT_IS_ORIGIN(circ
)) {
661 circuit_build_failed(circ
); /* take actions if necessary */
663 circuit_rep_hist_note_result(circ
);
665 if (CIRCUIT_IS_ORIGIN(circ
)) {
666 control_event_circuit_status(circ
,
667 (circ
->state
== CIRCUIT_STATE_OPEN
)?CIRC_EVENT_CLOSED
:CIRC_EVENT_FAILED
);
669 if (circ
->purpose
== CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
) {
670 tor_assert(circ
->state
== CIRCUIT_STATE_OPEN
);
671 tor_assert(circ
->build_state
->chosen_exit
);
672 /* treat this like getting a nack from it */
673 info(LD_REND
,"Failed intro circ %s to %s (awaiting ack). Removing from descriptor.",
674 safe_str(circ
->rend_query
),
675 safe_str(build_state_get_exit_nickname(circ
->build_state
)));
676 rend_client_remove_intro_point(circ
->build_state
->chosen_exit
,
681 connection_send_destroy(circ
->n_circ_id
, circ
->n_conn
);
682 for (conn
=circ
->n_streams
; conn
; conn
=conn
->next_stream
)
683 connection_edge_destroy(circ
->n_circ_id
, conn
);
684 while (circ
->resolving_streams
) {
685 conn
= circ
->resolving_streams
;
686 circ
->resolving_streams
= conn
->next_stream
;
687 if (!conn
->marked_for_close
) {
688 /* The other side will see a DESTROY, and infer that the connections
689 * are closing because the circuit is getting torn down. No need
690 * to send an end cell*/
691 conn
->has_sent_end
= 1; /* we're closing the circuit, nothing to send to */
692 connection_mark_for_close(conn
);
694 conn
->on_circuit
= NULL
;
697 connection_send_destroy(circ
->p_circ_id
, circ
->p_conn
);
698 for (conn
=circ
->p_streams
; conn
; conn
=conn
->next_stream
)
699 connection_edge_destroy(circ
->p_circ_id
, conn
);
701 circ
->marked_for_close
= line
;
702 circ
->marked_for_close_file
= file
;
704 if (circ
->rend_splice
&& !circ
->rend_splice
->marked_for_close
) {
705 /* do this after marking this circuit, to avoid infinite recursion. */
706 circuit_mark_for_close(circ
->rend_splice
);
707 circ
->rend_splice
= NULL
;
711 /** Verify that cpath layer <b>cp</b> has all of its invariants
712 * correct. Trigger an assert if anything is invalid.
715 assert_cpath_layer_ok(const crypt_path_t
*cp
)
717 // tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
718 // tor_assert(cp->port);
720 tor_assert(cp
->magic
== CRYPT_PATH_MAGIC
);
723 case CPATH_STATE_OPEN
:
724 tor_assert(cp
->f_crypto
);
725 tor_assert(cp
->b_crypto
);
727 case CPATH_STATE_CLOSED
:
728 tor_assert(!cp
->dh_handshake_state
);
730 case CPATH_STATE_AWAITING_KEYS
:
731 /* tor_assert(cp->dh_handshake_state); */
734 err("Unexpected state %d",cp
->state
);
737 tor_assert(cp
->package_window
>= 0);
738 tor_assert(cp
->deliver_window
>= 0);
741 /** Verify that cpath <b>cp</b> has all of its invariants
742 * correct. Trigger an assert if anything is invalid.
745 assert_cpath_ok(const crypt_path_t
*cp
)
747 const crypt_path_t
*start
= cp
;
750 assert_cpath_layer_ok(cp
);
751 /* layers must be in sequence of: "open* awaiting? closed*" */
753 if (cp
->state
== CPATH_STATE_AWAITING_KEYS
) {
754 tor_assert(cp
->prev
->state
== CPATH_STATE_OPEN
);
755 } else if (cp
->state
== CPATH_STATE_OPEN
) {
756 tor_assert(cp
->prev
->state
== CPATH_STATE_OPEN
);
761 } while (cp
!= start
);
764 /** Verify that circuit <b>c</b> has all of its invariants
765 * correct. Trigger an assert if anything is invalid.
768 assert_circuit_ok(const circuit_t
*c
)
773 tor_assert(c
->magic
== CIRCUIT_MAGIC
);
774 tor_assert(c
->purpose
>= _CIRCUIT_PURPOSE_MIN
&&
775 c
->purpose
<= _CIRCUIT_PURPOSE_MAX
);
778 tor_assert(c
->n_conn
->type
== CONN_TYPE_OR
);
779 tor_assert(!memcmp(c
->n_conn
->identity_digest
, c
->n_conn_id_digest
, DIGEST_LEN
));
781 tor_assert(c
== circuit_get_by_circid_orconn(c
->n_circ_id
, c
->n_conn
));
784 tor_assert(c
->p_conn
->type
== CONN_TYPE_OR
);
786 tor_assert(c
== circuit_get_by_circid_orconn(c
->p_circ_id
, c
->p_conn
));
788 for (conn
= c
->p_streams
; conn
; conn
= conn
->next_stream
)
789 tor_assert(conn
->type
== CONN_TYPE_AP
);
790 for (conn
= c
->n_streams
; conn
; conn
= conn
->next_stream
)
791 tor_assert(conn
->type
== CONN_TYPE_EXIT
);
793 tor_assert(c
->deliver_window
>= 0);
794 tor_assert(c
->package_window
>= 0);
795 if (c
->state
== CIRCUIT_STATE_OPEN
) {
797 tor_assert(CIRCUIT_IS_ORIGIN(c
));
798 tor_assert(!c
->n_crypto
);
799 tor_assert(!c
->p_crypto
);
800 tor_assert(!c
->n_digest
);
801 tor_assert(!c
->p_digest
);
803 tor_assert(!CIRCUIT_IS_ORIGIN(c
));
804 tor_assert(c
->n_crypto
);
805 tor_assert(c
->p_crypto
);
806 tor_assert(c
->n_digest
);
807 tor_assert(c
->p_digest
);
811 assert_cpath_ok(c
->cpath
);
813 if (c
->purpose
== CIRCUIT_PURPOSE_REND_ESTABLISHED
) {
814 if (!c
->marked_for_close
) {
815 tor_assert(c
->rend_splice
);
816 tor_assert(c
->rend_splice
->rend_splice
== c
);
818 tor_assert(c
->rend_splice
!= c
);
820 tor_assert(!c
->rend_splice
);