diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-11-05 21:46:35 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-11-05 21:46:35 +0000 |
commit | 9a20a64b62b149b102a487b6dc099fa310553f3c (patch) | |
tree | 4bf53c0aa275547f296b70fecdd72cca40c752a6 /src/or/command.c | |
parent | 42f7ae3eaeb3d0f1067234f3acf9c0f0f4e6cf1a (diff) | |
download | tor-9a20a64b62b149b102a487b6dc099fa310553f3c.tar.gz tor-9a20a64b62b149b102a487b6dc099fa310553f3c.zip |
r16438@catbus: nickm | 2007-11-05 16:45:45 -0500
Initial code for variable-length cells. CERT and VERSIONS need to use them.
svn:r12390
Diffstat (limited to 'src/or/command.c')
-rw-r--r-- | src/or/command.c | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/src/or/command.c b/src/or/command.c index a1724dc709..d46012ade5 100644 --- a/src/or/command.c +++ b/src/or/command.c @@ -35,9 +35,10 @@ static void command_process_create_cell(cell_t *cell, or_connection_t *conn); static void command_process_created_cell(cell_t *cell, or_connection_t *conn); static void command_process_relay_cell(cell_t *cell, or_connection_t *conn); static void command_process_destroy_cell(cell_t *cell, or_connection_t *conn); -static void command_process_versions_cell(cell_t *cell, or_connection_t *conn); +static void command_process_versions_cell(var_cell_t *cell, + or_connection_t *conn); static void command_process_netinfo_cell(cell_t *cell, or_connection_t *conn); -static void command_process_cert_cell(cell_t *cell, or_connection_t *conn); +static void command_process_cert_cell(var_cell_t *cell, or_connection_t *conn); static void command_process_link_auth_cell(cell_t *cell,or_connection_t *conn); #ifdef KEEP_TIMING_STATS @@ -143,16 +144,14 @@ command_process_cell(cell_t *cell, or_connection_t *conn) PROCESS_CELL(destroy, cell, conn); break; case CELL_VERSIONS: - ++stats_n_versions_cells_processed; - PROCESS_CELL(versions, cell, conn); + tor_fragile_assert(); break; case CELL_NETINFO: ++stats_n_netinfo_cells_processed; PROCESS_CELL(netinfo, cell, conn); break; case CELL_CERT: - ++stats_n_cert_cells_processed; - PROCESS_CELL(cert, cell, conn); + tor_fragile_assert(); break; case CELL_LINK_AUTH: ++stats_n_link_auth_cells_processed; @@ -165,6 +164,55 @@ command_process_cell(cell_t *cell, or_connection_t *conn) } } +/** Process a <b>cell</b> that was just received on <b>conn</b>. Keep internal + * statistics about how many of each cell we've processed so far + * this second, and the total number of microseconds it took to + * process each type of cell. + */ +void +command_process_var_cell(var_cell_t *cell, or_connection_t *conn) +{ +#ifdef KEEP_TIMING_STATS + /* how many of each cell have we seen so far this second? needs better + * name. */ + static int num_versions=0, num_cert=0; + + time_t now = time(NULL); + + if (now > current_second) { /* the second has rolled over */ + /* print stats */ + log_info(LD_OR, + "At end of second: %d versions (%d ms), %d cert (%d ms)", + num_versions, versions_time/1000, + cert, cert_time/1000); + + num_versions = num_cert = 0; + versions_time = cert_time = 0; + + /* remember which second it is, for next time */ + current_second = now; + } +#endif + + /*XXXX020 reject all when not handshaking. */ + switch (cell->command) { + case CELL_VERSIONS: + ++stats_n_versions_cells_processed; + PROCESS_CELL(versions, cell, conn); + break; + case CELL_CERT: + ++stats_n_cert_cells_processed; + PROCESS_CELL(cert, cell, conn); + break; + default: + log_warn(LD_BUG, + "Variable-length cell of unknown type (%d) received.", + cell->command); + tor_fragile_assert(); + break; + } +} + /** Process a 'create' <b>cell</b> that just arrived from <b>conn</b>. Make a * new circuit with the p_circ_id specified in cell. Put the circuit in state * onionskin_pending, and pass the onionskin to the cpuworker. Circ will get @@ -404,7 +452,7 @@ command_process_destroy_cell(cell_t *cell, or_connection_t *conn) /** Process a 'versions' cell. The current link protocol version must be 0 * to indicate that no version has yet been negotiated. DOCDOC say more. */ static void -command_process_versions_cell(cell_t *cell, or_connection_t *conn) +command_process_versions_cell(var_cell_t *cell, or_connection_t *conn) { uint16_t versionslen; int highest_supported_version = 0; @@ -560,7 +608,7 @@ connection_or_act_on_netinfo(or_connection_t *conn) } static void -command_process_cert_cell(cell_t *cell, or_connection_t *conn) +command_process_cert_cell(var_cell_t *cell, or_connection_t *conn) { (void) cell; (void) conn; |