[or-cvs] r17828: {tor} Debug code for task 878. (tor/trunk/src/or)
kloesing at seul.org
kloesing at seul.org
Tue Dec 30 11:43:51 UTC 2008
Author: kloesing
Date: 2008-12-30 06:43:50 -0500 (Tue, 30 Dec 2008)
New Revision: 17828
Modified:
tor/trunk/src/or/or.h
tor/trunk/src/or/relay.c
Log:
Debug code for task 878.
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2008-12-30 04:16:49 UTC (rev 17827)
+++ tor/trunk/src/or/or.h 2008-12-30 11:43:50 UTC (rev 17828)
@@ -1997,6 +1997,14 @@
* to the specification? */
unsigned int remaining_relay_early_cells : 4;
+ /** What commands were sent over this circuit that decremented the
+ * RELAY_EARLY counter? This is for debugging task 878. */
+ uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT];
+
+ /** How many RELAY_EARLY cells have been sent over this circuit? This is
+ * for debugging task 878, too. */
+ int relay_early_cells_sent;
+
/** The next stream_id that will be tried when we're attempting to
* construct a new AP stream originating at this circuit. */
streamid_t next_stream_id;
Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c 2008-12-30 04:16:49 UTC (rev 17827)
+++ tor/trunk/src/or/relay.c 2008-12-30 11:43:50 UTC (rev 17828)
@@ -458,6 +458,38 @@
dest->length = ntohs(get_uint16(src+9));
}
+/** Convert the relay <b>command</b> into a human-readable string. */
+static const char *
+relay_command_to_string(uint8_t command)
+{
+ switch (command) {
+ case RELAY_COMMAND_BEGIN: return "BEGIN";
+ case RELAY_COMMAND_DATA: return "DATA";
+ case RELAY_COMMAND_END: return "END";
+ case RELAY_COMMAND_CONNECTED: return "CONNECTED";
+ case RELAY_COMMAND_SENDME: return "SENDME";
+ case RELAY_COMMAND_EXTEND: return "EXTEND";
+ case RELAY_COMMAND_EXTENDED: return "EXTENDED";
+ case RELAY_COMMAND_TRUNCATE: return "TRUNCATE";
+ case RELAY_COMMAND_TRUNCATED: return "TRUNCATED";
+ case RELAY_COMMAND_DROP: return "DROP";
+ case RELAY_COMMAND_RESOLVE: return "RESOLVE";
+ case RELAY_COMMAND_RESOLVED: return "RESOLVED";
+ case RELAY_COMMAND_BEGIN_DIR: return "BEGIN_DIR";
+ case RELAY_COMMAND_ESTABLISH_INTRO: return "ESTABLISH_INTRO";
+ case RELAY_COMMAND_ESTABLISH_RENDEZVOUS: return "ESTABLISH_RENDEZVOUS";
+ case RELAY_COMMAND_INTRODUCE1: return "INTRODUCE1";
+ case RELAY_COMMAND_INTRODUCE2: return "INTRODUCE2";
+ case RELAY_COMMAND_RENDEZVOUS1: return "RENDEZVOUS1";
+ case RELAY_COMMAND_RENDEZVOUS2: return "RENDEZVOUS2";
+ case RELAY_COMMAND_INTRO_ESTABLISHED: return "INTRO_ESTABLISHED";
+ case RELAY_COMMAND_RENDEZVOUS_ESTABLISHED:
+ return "RENDEZVOUS_ESTABLISHED";
+ case RELAY_COMMAND_INTRODUCE_ACK: return "INTRODUCE_ACK";
+ default: return "(unrecognized)";
+ }
+}
+
/** Make a relay cell out of <b>relay_command</b> and <b>payload</b>, and send
* it onto the open circuit <b>circ</b>. <b>stream_id</b> is the ID on
* <b>circ</b> for the stream that's sending the relay cell, or 0 if it's a
@@ -521,9 +553,26 @@
--origin_circ->remaining_relay_early_cells;
log_debug(LD_OR, "Sending a RELAY_EARLY cell; %d remaining.",
(int)origin_circ->remaining_relay_early_cells);
+ /* Memorize the command that is sent as RELAY_EARLY cell; helps debug
+ * task 878. */
+ origin_circ->relay_early_commands[
+ origin_circ->relay_early_cells_sent++] = relay_command;
} else if (relay_command == RELAY_COMMAND_EXTEND) {
+ /* If no RELAY_EARLY cells can be sent over this circuit, log which
+ * commands have been sent as RELAY_EARLY cells before; helps debug
+ * task 878. */
+ smartlist_t *commands_list = smartlist_create();
+ int i = 0;
+ char *commands = NULL;
+ for (; i < origin_circ->relay_early_cells_sent; i++)
+ smartlist_add(commands_list, (char *)
+ relay_command_to_string(origin_circ->relay_early_commands[i]));
+ commands = smartlist_join_strings(commands_list, ",", 0, NULL);
log_warn(LD_BUG, "Uh-oh. We're sending a RELAY_COMMAND_EXTEND cell, "
- "but we have run out of RELAY_EARLY cells on that circuit.");
+ "but we have run out of RELAY_EARLY cells on that circuit. "
+ "Commands sent before: %s", commands);
+ tor_free(commands);
+ smartlist_free(commands_list);
}
}
More information about the tor-commits
mailing list