aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-10-07 19:56:49 +0000
committerNick Mathewson <nickm@torproject.org>2006-10-07 19:56:49 +0000
commite230fe8ea688db023db8b4ff8b5e2c49228a2672 (patch)
tree91d83966f3a621ab4a79685979702fb168d617ce /src
parentd6601d7f0d7083ca3873ea2138f08385762ce524 (diff)
downloadtor-e230fe8ea688db023db8b4ff8b5e2c49228a2672.tar
tor-e230fe8ea688db023db8b4ff8b5e2c49228a2672.tar.gz
r8926@totoro: nickm | 2006-10-07 15:56:14 -0400
refactor circuit_list_path and circuit_list_path_verbose into a common _impl function. svn:r8642
Diffstat (limited to 'src')
-rw-r--r--src/or/circuitbuild.c101
1 files changed, 49 insertions, 52 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index d59d4fa67..7c4501356 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -91,13 +91,14 @@ get_unique_circ_id_by_conn(or_connection_t *conn)
return test_circ_id;
}
-/** If <b>verbose</b> is false, allocate and return a comma-separated
- * list of the currently built elements of circuit_t. If
- * <b>verbose</b> is true, also list information about link status in
- * a more verbose format using spaces.
+/** If <b>verbose</b> is false, allocate and return a comma-separated list of
+ * the currently built elements of circuit_t. If <b>verbose</b> is true, also
+ * list information about link status in a more verbose format using spaces.
+ * If <b>verbose_names</b> is false, give nicknames for Named routers and hex
+ * digests for others; if <b>verbose_names</b> is true,
*/
-char *
-circuit_list_path(origin_circuit_t *circ, int verbose)
+static char *
+circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
{
crypt_path_t *hop;
smartlist_t *elements;
@@ -129,14 +130,33 @@ circuit_list_path(origin_circuit_t *circ, int verbose)
break;
if (!hop->extend_info)
break;
- if ((ri = router_get_by_digest(hop->extend_info->identity_digest)) &&
- ri->is_named) {
- elt = tor_strdup(hop->extend_info->nickname);
- } else {
- elt = tor_malloc(HEX_DIGEST_LEN+2);
- elt[0] = '$';
- base16_encode(elt+1, HEX_DIGEST_LEN+1,
- hop->extend_info->identity_digest, DIGEST_LEN);
+ if (verbose_names) {
+ elt = tor_malloc(MAX_VERBOSE_NICKNAME_LEN+1);
+ if ((ri = router_get_by_digest(hop->extend_info->identity_digest))) {
+ router_get_verbose_nickname(elt, ri);
+ } else if (hop->extend_info->nickname &&
+ is_legal_nickname(hop->extend_info->nickname)) {
+ elt[0] = '$';
+ base16_encode(elt+1, HEX_DIGEST_LEN+1,
+ hop->extend_info->identity_digest, DIGEST_LEN);
+ elt[HEX_DIGEST_LEN+1]= '~';
+ strlcpy(elt+HEX_DIGEST_LEN+2,
+ hop->extend_info->nickname, MAX_NICKNAME_LEN+1);
+ } else {
+ elt[0] = '$';
+ base16_encode(elt+1, HEX_DIGEST_LEN+1,
+ hop->extend_info->identity_digest, DIGEST_LEN);
+ }
+ } else { /* ! verbose_names */
+ if ((ri = router_get_by_digest(hop->extend_info->identity_digest)) &&
+ ri->is_named) {
+ elt = tor_strdup(hop->extend_info->nickname);
+ } else {
+ elt = tor_malloc(HEX_DIGEST_LEN+2);
+ elt[0] = '$';
+ base16_encode(elt+1, HEX_DIGEST_LEN+1,
+ hop->extend_info->identity_digest, DIGEST_LEN);
+ }
}
tor_assert(elt);
if (verbose) {
@@ -158,47 +178,24 @@ circuit_list_path(origin_circuit_t *circ, int verbose)
return s;
}
-/* DOCDOC long names only */
+/** If <b>verbose</b> is false, allocate and return a comma-separated
+ * list of the currently built elements of circuit_t. If
+ * <b>verbose</b> is true, also list information about link status in
+ * a more verbose format using spaces.
+ */
char *
-circuit_list_path_for_controller(origin_circuit_t *circ)
+circuit_list_path(origin_circuit_t *circ, int verbose)
{
- smartlist_t *elements = smartlist_create();
- crypt_path_t *hop;
- char *elt, *s;
- routerinfo_t *ri;
-
- hop = circ->cpath;
- do {
- if (!hop)
- break;
- if (hop->state != CPATH_STATE_OPEN)
- break;
- if (!hop->extend_info)
- break;
- elt = tor_malloc(MAX_VERBOSE_NICKNAME_LEN+1);
- if ((ri = router_get_by_digest(hop->extend_info->identity_digest))) {
- router_get_verbose_nickname(elt, ri);
- } else if (hop->extend_info->nickname &&
- is_legal_nickname(hop->extend_info->nickname)) {
- elt[0] = '$';
- base16_encode(elt+1, HEX_DIGEST_LEN+1,
- hop->extend_info->identity_digest, DIGEST_LEN);
- elt[HEX_DIGEST_LEN+1]= '~';
- strlcpy(elt+HEX_DIGEST_LEN+2,
- hop->extend_info->nickname, MAX_NICKNAME_LEN+1);
- } else {
- elt[0] = '$';
- base16_encode(elt+1, HEX_DIGEST_LEN+1,
- hop->extend_info->identity_digest, DIGEST_LEN);
- }
- smartlist_add(elements, elt);
- hop = hop->next;
- } while (hop != circ->cpath);
+ return circuit_list_path_impl(circ, verbose, 0);
+}
- s = smartlist_join_strings(elements, ",", 0, NULL);
- SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
- smartlist_free(elements);
- return s;
+/** Allocate and return a comma-separated list of the currently built elements
+ * of circuit_t, giving each as a verbose nickname.
+ */
+char *
+circuit_list_path_for_controller(origin_circuit_t *circ)
+{
+ return circuit_list_path_impl(circ, 0, 1);
}
/** Log, at severity <b>severity</b>, the nicknames of each router in