[tor-commits] [tor/maint-0.2.2] Add a circuit_purpose_to_string() function, and use it
nickm at torproject.org
nickm at torproject.org
Wed Apr 27 18:02:16 UTC 2011
commit 8ee92f28e056fd32f1faef62ae1523ad4d553a64
Author: Nick Mathewson <nickm at torproject.org>
Date: Fri Apr 8 13:27:25 2011 -0400
Add a circuit_purpose_to_string() function, and use it
We had a circuit_purpose_to_controller_string() function, but it was
pretty coarse-grained and didn't try to be human-readable.
---
src/or/circuitbuild.c | 10 +++++---
src/or/circuitlist.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
src/or/circuitlist.h | 1 +
src/or/circuituse.c | 22 ++++++++++--------
4 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 681f524..b963f1a 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2051,8 +2051,9 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
*/
if (timediff < 0 || timediff > 2*circ_times.close_ms+1000) {
log_notice(LD_CIRC, "Strange value for circuit build time: %ldmsec. "
- "Assuming clock jump. Purpose %d", timediff,
- circ->_base.purpose);
+ "Assuming clock jump. Purpose %d (%s)", timediff,
+ circ->_base.purpose,
+ circuit_purpose_to_string(circ->_base.purpose));
} else if (!circuit_build_times_disabled()) {
/* Only count circuit times if the network is live */
if (circuit_build_times_network_check_live(&circ_times)) {
@@ -2890,8 +2891,9 @@ warn_if_last_router_excluded(origin_circuit_t *circ, const extend_info_t *exit)
case CIRCUIT_PURPOSE_INTRO_POINT:
case CIRCUIT_PURPOSE_REND_POINT_WAITING:
case CIRCUIT_PURPOSE_REND_ESTABLISHED:
- log_warn(LD_BUG, "Called on non-origin circuit (purpose %d)",
- (int)purpose);
+ log_warn(LD_BUG, "Called on non-origin circuit (purpose %d, %s)",
+ (int)purpose,
+ circuit_purpose_to_string(purpose));
return;
case CIRCUIT_PURPOSE_C_GENERAL:
if (circ->build_state->is_internal)
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index ce324ca..33dc8f0 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -378,6 +378,62 @@ circuit_purpose_to_controller_string(uint8_t purpose)
}
}
+/** Return a human-readable string for the circuit purpose <b>purpose</b>. */
+const char *
+circuit_purpose_to_string(uint8_t purpose)
+{
+ static char buf[32];
+
+ switch (purpose)
+ {
+ case CIRCUIT_PURPOSE_OR:
+ return "Circuit at relay";
+ case CIRCUIT_PURPOSE_INTRO_POINT:
+ return "Acting as intro point";
+ case CIRCUIT_PURPOSE_REND_POINT_WAITING:
+ return "Acting as rendevous (pending)";
+ case CIRCUIT_PURPOSE_REND_ESTABLISHED:
+ return "Acting as rendevous (established)";
+ case CIRCUIT_PURPOSE_C_GENERAL:
+ return "General-purpose client";
+ case CIRCUIT_PURPOSE_C_INTRODUCING:
+ return "Hidden service client: Connecting to intro point";
+ case CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT:
+ return "Hidden service client: Waiting for ack from intro point";
+ case CIRCUIT_PURPOSE_C_INTRODUCE_ACKED:
+ return "Hidden service client: Received ack from intro point";
+ case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
+ return "Hidden service client: Establishing rendezvous point";
+ case CIRCUIT_PURPOSE_C_REND_READY:
+ return "Hidden service client: Pending rendezvous point";
+ case CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED:
+ return "Hidden service client: Pending rendezvous point (ack received)";
+ case CIRCUIT_PURPOSE_C_REND_JOINED:
+ return "Hidden service client: Active rendezvous point";
+ case CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT:
+ return "Measuring circuit timeout";
+
+ case CIRCUIT_PURPOSE_S_ESTABLISH_INTRO:
+ return "Hidden service: Establishing introduction point";
+ case CIRCUIT_PURPOSE_S_INTRO:
+ return "Hidden service: Introduction point";
+ case CIRCUIT_PURPOSE_S_CONNECT_REND:
+ return "Hidden service: Connecting to rendezvous point";
+ case CIRCUIT_PURPOSE_S_REND_JOINED:
+ return "Hidden service: Active rendezvous point";
+
+ case CIRCUIT_PURPOSE_TESTING:
+ return "Testing circuit";
+
+ case CIRCUIT_PURPOSE_CONTROLLER:
+ return "Circuit made by controller";
+
+ default:
+ tor_snprintf(buf, sizeof(buf), "UNKNOWN_%d", (int)purpose);
+ return buf;
+ }
+}
+
/** Pick a reasonable package_window to start out for our circuits.
* Originally this was hard-coded at 1000, but now the consensus votes
* on the answer. See proposal 168. */
diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h
index ef6fc3a..7b01ca3 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -15,6 +15,7 @@
circuit_t * _circuit_get_global_list(void);
const char *circuit_state_to_string(int state);
const char *circuit_purpose_to_controller_string(uint8_t purpose);
+const char *circuit_purpose_to_string(uint8_t purpose);
void circuit_dump_by_conn(connection_t *conn, int severity);
void circuit_set_p_circid_orconn(or_circuit_t *circ, circid_t id,
or_connection_t *conn);
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 7b20f7f..530941c 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -392,10 +392,11 @@ circuit_expire_building(void)
TO_ORIGIN_CIRCUIT(victim)->cpath->state == CPATH_STATE_OPEN;
if (TO_ORIGIN_CIRCUIT(victim)->p_streams != NULL) {
- log_warn(LD_BUG, "Circuit %d (purpose %d) has timed out, "
+ log_warn(LD_BUG, "Circuit %d (purpose %d, %s) has timed out, "
"yet has attached streams!",
TO_ORIGIN_CIRCUIT(victim)->global_identifier,
- victim->purpose);
+ victim->purpose,
+ circuit_purpose_to_string(victim->purpose));
tor_fragile_assert();
continue;
}
@@ -426,9 +427,10 @@ circuit_expire_building(void)
if (timercmp(&victim->timestamp_created, &extremely_old_cutoff, <)) {
log_notice(LD_CIRC,
"Extremely large value for circuit build timeout: %lds. "
- "Assuming clock jump. Purpose %d",
+ "Assuming clock jump. Purpose %d (%s)",
(long)(now.tv_sec - victim->timestamp_created.tv_sec),
- victim->purpose);
+ victim->purpose,
+ circuit_purpose_to_string(victim->purpose));
} else if (circuit_build_times_count_close(&circ_times,
first_hop_succeeded,
victim->timestamp_created.tv_sec)) {
@@ -794,12 +796,11 @@ circuit_expire_old_circuits_clientside(void)
circ->purpose != CIRCUIT_PURPOSE_S_INTRO) {
log_notice(LD_CIRC,
"Ancient non-dirty circuit %d is still around after "
- "%ld milliseconds. Purpose: %d",
+ "%ld milliseconds. Purpose: %d (%s)",
TO_ORIGIN_CIRCUIT(circ)->global_identifier,
tv_mdiff(&circ->timestamp_created, &now),
- circ->purpose);
- /* FFFF implement a new circuit_purpose_to_string() so we don't
- * just print out a number for circ->purpose */
+ circ->purpose,
+ circuit_purpose_to_string(circ->purpose));
TO_ORIGIN_CIRCUIT(circ)->is_ancient = 1;
}
}
@@ -1136,8 +1137,9 @@ circuit_launch_by_extend_info(uint8_t purpose,
* internal circs rather than exit circs? -RD */
circ = circuit_find_to_cannibalize(purpose, extend_info, flags);
if (circ) {
- log_info(LD_CIRC,"Cannibalizing circ '%s' for purpose %d",
- build_state_get_exit_nickname(circ->build_state), 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;
/* reset the birth date of this circ, else expire_building
* will see it and think it's been trying to build since it
More information about the tor-commits
mailing list