summaryrefslogtreecommitdiff
path: root/src/or/circuituse.c
diff options
context:
space:
mode:
authorRobert Ransom <rransom.8774@gmail.com>2011-11-24 06:52:38 -0800
committerRobert Ransom <rransom.8774@gmail.com>2011-11-24 06:52:38 -0800
commit104c50fedb1b9217fbb2a8cc5fcf9ec9c9be2674 (patch)
tree42003d995346a7a91035d32946eb332c6cacabdb /src/or/circuituse.c
parentd0ed7cbf8b83f675dcd858abbdfda98eb3bafc88 (diff)
downloadtor-104c50fedb1b9217fbb2a8cc5fcf9ec9c9be2674.tar.gz
tor-104c50fedb1b9217fbb2a8cc5fcf9ec9c9be2674.zip
Log whenever a circuit's purpose is changed
Diffstat (limited to 'src/or/circuituse.c')
-rw-r--r--src/or/circuituse.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 23efe05348..46c0b8a0fa 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -467,7 +467,7 @@ circuit_expire_building(void)
control_event_circuit_status(TO_ORIGIN_CIRCUIT(victim),
CIRC_EVENT_FAILED,
END_CIRC_REASON_TIMEOUT);
- victim->purpose = CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT;
+ circuit_change_purpose(victim, CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT);
/* Record this failure to check for too many timeouts
* in a row. This function does not record a time value yet
* (we do that later); it only counts the fact that we did
@@ -1218,7 +1218,7 @@ circuit_launch_by_extend_info(uint8_t purpose,
log_info(LD_CIRC,"Cannibalizing circ '%s' for purpose %d (%s)",
build_state_get_exit_nickname(circ->build_state), purpose,
circuit_purpose_to_string(purpose));
- circ->_base.purpose = purpose;
+ circuit_change_purpose(TO_CIRCUIT(circ), purpose);
/* reset the birth date of this circ, else expire_building
* will see it and think it's been trying to build since it
* began. */
@@ -1925,3 +1925,32 @@ connection_ap_handshake_attach_circuit(entry_connection_t *conn)
}
}
+/** Change <b>circ</b>'s purpose to <b>new_purpose</b>. */
+void
+circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
+{
+ /* Don't allow an OR circ to become an origin circ or vice versa. */
+ tor_assert(!!(CIRCUIT_IS_ORIGIN(circ)) ==
+ !!(CIRCUIT_PURPOSE_IS_ORIGIN(new_purpose)));
+
+ if (circ->purpose == new_purpose) return;
+
+ if (CIRCUIT_IS_ORIGIN(circ)) {
+ char old_purpose[80] = "";
+
+ strncpy(old_purpose, circuit_purpose_to_string(circ->purpose), 80-1);
+ old_purpose[80-1] = '\0';
+
+ log_debug(LD_CIRC,
+ "changing purpose of origin circ %d "
+ "from \"%s\" (%d) to \"%s\" (%d)",
+ TO_ORIGIN_CIRCUIT(circ)->global_identifier,
+ old_purpose,
+ circ->purpose,
+ circuit_purpose_to_string(new_purpose),
+ new_purpose);
+ }
+
+ circ->purpose = new_purpose;
+}
+