Fix critical bug in circuit_list_path: cpath is a circular list! (Also reimplement circuit_log_cpath using circuit_list_cpath).

svn:r2946
This commit is contained in:
Nick Mathewson 2004-11-23 00:11:36 +00:00
parent cd70264377
commit 0a58bbe0dd
3 changed files with 43 additions and 16 deletions

View File

@ -61,36 +61,57 @@ static uint16_t get_unique_circ_id_by_conn(connection_t *conn) {
return test_circ_id;
}
/** Allocate and return a comma-separated list of the currently built
* elements of circuit_t.
/** 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(circuit_t *circ)
char *
circuit_list_path(circuit_t *circ, int verbose)
{
struct crypt_path_t *hop;
routerinfo_t *r;
smartlist_t *elements;
const char *states[] = {"closed", "waiting for keys", "open"};
char buf[128];
char *s;
tor_assert(CIRCUIT_IS_ORIGIN(circ));
tor_assert(circ->cpath);
elements = smartlist_create();
for (hop = circ->cpath; hop; hop = hop->next) {
if (hop->state != CPATH_STATE_OPEN)
if (verbose) {
tor_snprintf(buf, sizeof(buf)-1, "circ (length %d, exit %s):",
circ->build_state->desired_path_len,
circ->build_state->chosen_exit_name);
smartlist_add(elements, tor_strdup(buf));
}
for (hop = circ->cpath; hop && hop != circ->cpath; hop = hop->next) {
const char *elt;
routerinfo_t *r;
if (!verbose && hop->state != CPATH_STATE_OPEN)
break;
if ((r = router_get_by_digest(hop->identity_digest))) {
smartlist_add(elements, tor_strdup(r->nickname));
elt = r->nickname;
} else if (circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
smartlist_add(elements, tor_strdup("<rendezvous splice>"));
elt = "<rendezvous splice>";
} else {
s = tor_malloc(HEX_DIGEST_LEN+2);
s[0]='$';
base16_encode(s+1,HEX_DIGEST_LEN+1,hop->identity_digest,DIGEST_LEN);
smartlist_add(elements, s);
buf[0]='$';
base16_encode(buf+1,sizeof(buf)-1,hop->identity_digest,DIGEST_LEN);
elt = buf;
}
if (verbose) {
size_t len = strlen(elt)+2+strlen(states[hop->state])+1;
char *v = tor_malloc(len);
tor_assert(hop->state <= 2);
tor_snprintf(v,len,"%s(%s)",elt,states[hop->state]);
smartlist_add(elements, v);
} else {
smartlist_add(elements, tor_strdup(elt));
}
}
s = smartlist_join_strings(elements, ",", 0, NULL);
s = smartlist_join_strings(elements, verbose?" ":",", 0, NULL);
SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
return s;
}
@ -100,6 +121,11 @@ char *circuit_list_path(circuit_t *circ)
* exit point.
*/
void circuit_log_path(int severity, circuit_t *circ) {
#if 1
char *s = circuit_list_path(circ,1);
log_fn(severity,"%s",s);
tor_free(s);
#else
char buf[1024];
char *s = buf;
struct crypt_path_t *hop;
@ -127,6 +153,7 @@ void circuit_log_path(int severity, circuit_t *circ) {
hop=hop->next;
} while(hop!=circ->cpath);
log_fn(severity,"%s",buf);
#endif
}
/** Tell the rep(utation)hist(ory) module about the status of the links
@ -631,7 +658,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
}
hop->state = CPATH_STATE_OPEN;
log_fn(LOG_INFO,"finished");
log_fn(LOG_INFO,"Finished building circuit:");
circuit_log_path(LOG_INFO,circ);
control_event_circuit_status(circ, CIRC_EVENT_EXTENDED);

View File

@ -492,7 +492,7 @@ control_event_circuit_status(circuit_t *circ, circuit_status_event_t tp)
tor_assert(circ);
tor_assert(CIRCUIT_IS_ORIGIN(circ));
path = circuit_list_path(circ);
path = circuit_list_path(circ,0);
path_len = strlen(path);
msg = tor_malloc(1+4+path_len+1); /* event, circid, path, NUL. */
msg[0] = (uint8_t) tp;

View File

@ -1032,7 +1032,7 @@ void assert_buf_ok(buf_t *buf);
/********************************* circuitbuild.c **********************/
char *circuit_list_path(circuit_t *circ);
char *circuit_list_path(circuit_t *circ, int verbose);
void circuit_log_path(int severity, circuit_t *circ);
void circuit_rep_hist_note_result(circuit_t *circ);
void circuit_dump_by_conn(connection_t *conn, int severity);