[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r8642: refactor circuit_list_path and circuit_list_path_verbose int (in tor/trunk: . src/or)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r8642: refactor circuit_list_path and circuit_list_path_verbose int (in tor/trunk: . src/or)
- From: nickm@xxxxxxxx
- Date: Sat, 7 Oct 2006 15:56:49 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Sat, 07 Oct 2006 15:56:57 -0400
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2006-10-07 15:56:49 -0400 (Sat, 07 Oct 2006)
New Revision: 8642
Modified:
tor/trunk/
tor/trunk/src/or/circuitbuild.c
Log:
r8926@totoro: nickm | 2006-10-07 15:56:14 -0400
refactor circuit_list_path and circuit_list_path_verbose into a common _impl function.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r8926] on 96637b51-b116-0410-a10e-9941ebb49b64
Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c 2006-10-07 19:47:11 UTC (rev 8641)
+++ tor/trunk/src/or/circuitbuild.c 2006-10-07 19:56:49 UTC (rev 8642)
@@ -91,13 +91,14 @@
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 @@
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 @@
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;
+ return circuit_list_path_impl(circ, verbose, 0);
+}
- 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);
-
- 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