Debug code for task 878.

svn:r17828
This commit is contained in:
Karsten Loesing 2008-12-30 11:43:50 +00:00
parent 52932d6f1a
commit 9a04358d87
2 changed files with 58 additions and 1 deletions

View File

@ -1997,6 +1997,14 @@ typedef struct origin_circuit_t {
* 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;

View File

@ -458,6 +458,38 @@ relay_header_unpack(relay_header_t *dest, const char *src)
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 @@ relay_send_command_from_edge(uint16_t stream_id, circuit_t *circ,
--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);
}
}