diff options
Diffstat (limited to 'src/or/channel.c')
-rw-r--r-- | src/or/channel.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/src/or/channel.c b/src/or/channel.c index 625d957811..104b018cf4 100644 --- a/src/or/channel.c +++ b/src/or/channel.c @@ -1,4 +1,4 @@ -/* * Copyright (c) 2012, The Tor Project, Inc. */ +/* * Copyright (c) 2012-2013, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** @@ -33,7 +33,7 @@ typedef struct cell_queue_entry_s cell_queue_entry_t; struct cell_queue_entry_s { - SIMPLEQ_ENTRY(cell_queue_entry_s) next; + TOR_SIMPLEQ_ENTRY(cell_queue_entry_s) next; enum { CELL_QUEUE_FIXED, CELL_QUEUE_VAR, @@ -89,7 +89,7 @@ HT_HEAD(channel_idmap, channel_idmap_entry_s) channel_identity_map = typedef struct channel_idmap_entry_s { HT_ENTRY(channel_idmap_entry_s) node; uint8_t digest[DIGEST_LEN]; - LIST_HEAD(channel_list_s, channel_s) channel_list; + TOR_LIST_HEAD(channel_list_s, channel_s) channel_list; } channel_idmap_entry_t; static INLINE unsigned @@ -554,10 +554,10 @@ channel_add_to_digest_map(channel_t *chan) if (! ent) { ent = tor_malloc(sizeof(channel_idmap_entry_t)); memcpy(ent->digest, chan->identity_digest, DIGEST_LEN); - LIST_INIT(&ent->channel_list); + TOR_LIST_INIT(&ent->channel_list); HT_INSERT(channel_idmap, &channel_identity_map, ent); } - LIST_INSERT_HEAD(&ent->channel_list, chan, next_with_same_id); + TOR_LIST_INSERT_HEAD(&ent->channel_list, chan, next_with_same_id); log_debug(LD_CHANNEL, "Added channel %p (global ID " U64_FORMAT ") " @@ -612,7 +612,7 @@ channel_remove_from_digest_map(channel_t *chan) #endif /* Pull it out of its list, wherever that list is */ - LIST_REMOVE(chan, next_with_same_id); + TOR_LIST_REMOVE(chan, next_with_same_id); memcpy(search.digest, chan->identity_digest, DIGEST_LEN); ent = HT_FIND(channel_idmap, &channel_identity_map, &search); @@ -621,7 +621,7 @@ channel_remove_from_digest_map(channel_t *chan) if (ent) { /* Okay, it's here */ - if (LIST_EMPTY(&ent->channel_list)) { + if (TOR_LIST_EMPTY(&ent->channel_list)) { HT_REMOVE(channel_idmap, &channel_identity_map, ent); tor_free(ent); } @@ -691,7 +691,7 @@ channel_find_by_remote_digest(const char *identity_digest) memcpy(search.digest, identity_digest, DIGEST_LEN); ent = HT_FIND(channel_idmap, &channel_identity_map, &search); if (ent) { - rv = LIST_FIRST(&ent->channel_list); + rv = TOR_LIST_FIRST(&ent->channel_list); } return rv; @@ -709,7 +709,7 @@ channel_next_with_digest(channel_t *chan) { tor_assert(chan); - return LIST_NEXT(chan, next_with_same_id); + return TOR_LIST_NEXT(chan, next_with_same_id); } /** @@ -735,8 +735,8 @@ channel_init(channel_t *chan) chan->next_circ_id = crypto_rand_int(1 << 15); /* Initialize queues. */ - SIMPLEQ_INIT(&chan->incoming_queue); - SIMPLEQ_INIT(&chan->outgoing_queue); + TOR_SIMPLEQ_INIT(&chan->incoming_queue); + TOR_SIMPLEQ_INIT(&chan->outgoing_queue); /* Initialize list entries. */ memset(&chan->next_with_same_id, 0, sizeof(chan->next_with_same_id)); @@ -879,16 +879,16 @@ channel_force_free(channel_t *chan) } /* We might still have a cell queue; kill it */ - SIMPLEQ_FOREACH_SAFE(cell, &chan->incoming_queue, next, cell_tmp) { + TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->incoming_queue, next, cell_tmp) { cell_queue_entry_free(cell, 0); } - SIMPLEQ_INIT(&chan->incoming_queue); + TOR_SIMPLEQ_INIT(&chan->incoming_queue); /* Outgoing cell queue is similar, but we can have to free packed cells */ - SIMPLEQ_FOREACH_SAFE(cell, &chan->outgoing_queue, next, cell_tmp) { + TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->outgoing_queue, next, cell_tmp) { cell_queue_entry_free(cell, 0); } - SIMPLEQ_INIT(&chan->outgoing_queue); + TOR_SIMPLEQ_INIT(&chan->outgoing_queue); tor_free(chan); } @@ -1051,7 +1051,7 @@ channel_set_cell_handlers(channel_t *chan, chan->var_cell_handler = var_cell_handler; /* Re-run the queue if we have one and there's any reason to */ - if (! SIMPLEQ_EMPTY(&chan->incoming_queue) && + if (! TOR_SIMPLEQ_EMPTY(&chan->incoming_queue) && try_again && (chan->cell_handler || chan->var_cell_handler)) channel_process_cells(chan); @@ -1686,7 +1686,7 @@ channel_write_cell_queue_entry(channel_t *chan, cell_queue_entry_t *q) } /* Can we send it right out? If so, try */ - if (SIMPLEQ_EMPTY(&chan->outgoing_queue) && + if (TOR_SIMPLEQ_EMPTY(&chan->outgoing_queue) && chan->state == CHANNEL_STATE_OPEN) { /* Pick the right write function for this cell type and save the result */ switch (q->type) { @@ -1728,7 +1728,7 @@ channel_write_cell_queue_entry(channel_t *chan, cell_queue_entry_t *q) * used the stack. */ tmp = cell_queue_entry_dup(q); - SIMPLEQ_INSERT_TAIL(&chan->outgoing_queue, tmp, next); + TOR_SIMPLEQ_INSERT_TAIL(&chan->outgoing_queue, tmp, next); /* Try to process the queue? */ if (chan->state == CHANNEL_STATE_OPEN) channel_flush_cells(chan); } @@ -1914,15 +1914,15 @@ channel_change_state(channel_t *chan, channel_state_t to_state) channel_do_open_actions(chan); /* Check for queued cells to process */ - if (! SIMPLEQ_EMPTY(&chan->incoming_queue)) + if (! TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)) channel_process_cells(chan); - if (! SIMPLEQ_EMPTY(&chan->outgoing_queue)) + if (! TOR_SIMPLEQ_EMPTY(&chan->outgoing_queue)) channel_flush_cells(chan); } else if (to_state == CHANNEL_STATE_CLOSED || to_state == CHANNEL_STATE_ERROR) { /* Assert that all queues are empty */ - tor_assert(SIMPLEQ_EMPTY(&chan->incoming_queue)); - tor_assert(SIMPLEQ_EMPTY(&chan->outgoing_queue)); + tor_assert(TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)); + tor_assert(TOR_SIMPLEQ_EMPTY(&chan->outgoing_queue)); } } @@ -2096,7 +2096,7 @@ channel_flush_some_cells_from_outgoing_queue(channel_t *chan, /* If we aren't in CHANNEL_STATE_OPEN, nothing goes through */ if (chan->state == CHANNEL_STATE_OPEN) { while ((unlimited || num_cells > flushed) && - NULL != (q = SIMPLEQ_FIRST(&chan->outgoing_queue))) { + NULL != (q = TOR_SIMPLEQ_FIRST(&chan->outgoing_queue))) { if (1) { /* @@ -2185,7 +2185,7 @@ channel_flush_some_cells_from_outgoing_queue(channel_t *chan, } /* if q got NULLed out, we used it and should remove the queue entry */ - if (!q) SIMPLEQ_REMOVE_HEAD(&chan->outgoing_queue, next); + if (!q) TOR_SIMPLEQ_REMOVE_HEAD(&chan->outgoing_queue, next); /* No cell removed from list, so we can't go on any further */ else break; } @@ -2193,7 +2193,7 @@ channel_flush_some_cells_from_outgoing_queue(channel_t *chan, } /* Did we drain the queue? */ - if (SIMPLEQ_EMPTY(&chan->outgoing_queue)) { + if (TOR_SIMPLEQ_EMPTY(&chan->outgoing_queue)) { channel_timestamp_drained(chan); } @@ -2227,7 +2227,7 @@ channel_more_to_flush(channel_t *chan) tor_assert(chan); /* Check if we have any queued */ - if (! SIMPLEQ_EMPTY(&chan->incoming_queue)) + if (! TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)) return 1; /* Check if any circuits would like to queue some */ @@ -2435,13 +2435,13 @@ channel_process_cells(channel_t *chan) if (!(chan->cell_handler || chan->var_cell_handler)) return; /* Nothing we can do if we have no cells */ - if (SIMPLEQ_EMPTY(&chan->incoming_queue)) return; + if (TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)) return; /* * Process cells until we're done or find one we have no current handler * for. */ - while (NULL != (q = SIMPLEQ_FIRST(&chan->incoming_queue))) { + while (NULL != (q = TOR_SIMPLEQ_FIRST(&chan->incoming_queue))) { tor_assert(q); tor_assert(q->type == CELL_QUEUE_FIXED || q->type == CELL_QUEUE_VAR); @@ -2449,7 +2449,7 @@ channel_process_cells(channel_t *chan) if (q->type == CELL_QUEUE_FIXED && chan->cell_handler) { /* Handle a fixed-length cell */ - SIMPLEQ_REMOVE_HEAD(&chan->incoming_queue, next); + TOR_SIMPLEQ_REMOVE_HEAD(&chan->incoming_queue, next); tor_assert(q->u.fixed.cell); log_debug(LD_CHANNEL, "Processing incoming cell_t %p for channel %p (global ID " @@ -2461,7 +2461,7 @@ channel_process_cells(channel_t *chan) } else if (q->type == CELL_QUEUE_VAR && chan->var_cell_handler) { /* Handle a variable-length cell */ - SIMPLEQ_REMOVE_HEAD(&chan->incoming_queue, next); + TOR_SIMPLEQ_REMOVE_HEAD(&chan->incoming_queue, next); tor_assert(q->u.var.var_cell); log_debug(LD_CHANNEL, "Processing incoming var_cell_t %p for channel %p (global ID " @@ -2496,7 +2496,7 @@ channel_queue_cell(channel_t *chan, cell_t *cell) /* Do we need to queue it, or can we just call the handler right away? */ if (!(chan->cell_handler)) need_to_queue = 1; - if (! SIMPLEQ_EMPTY(&chan->incoming_queue)) + if (! TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)) need_to_queue = 1; /* Timestamp for receiving */ @@ -2522,7 +2522,7 @@ channel_queue_cell(channel_t *chan, cell_t *cell) "(global ID " U64_FORMAT ")", cell, chan, U64_PRINTF_ARG(chan->global_identifier)); - SIMPLEQ_INSERT_TAIL(&chan->incoming_queue, q, next); + TOR_SIMPLEQ_INSERT_TAIL(&chan->incoming_queue, q, next); if (chan->cell_handler || chan->var_cell_handler) { channel_process_cells(chan); @@ -2549,7 +2549,7 @@ channel_queue_var_cell(channel_t *chan, var_cell_t *var_cell) /* Do we need to queue it, or can we just call the handler right away? */ if (!(chan->var_cell_handler)) need_to_queue = 1; - if (! SIMPLEQ_EMPTY(&chan->incoming_queue)) + if (! TOR_SIMPLEQ_EMPTY(&chan->incoming_queue)) need_to_queue = 1; /* Timestamp for receiving */ @@ -2575,7 +2575,7 @@ channel_queue_var_cell(channel_t *chan, var_cell_t *var_cell) "(global ID " U64_FORMAT ")", var_cell, chan, U64_PRINTF_ARG(chan->global_identifier)); - SIMPLEQ_INSERT_TAIL(&chan->incoming_queue, q, next); + TOR_SIMPLEQ_INSERT_TAIL(&chan->incoming_queue, q, next); if (chan->cell_handler || chan->var_cell_handler) { channel_process_cells(chan); @@ -2636,10 +2636,10 @@ void channel_dumpstats(int severity) { if (all_channels && smartlist_len(all_channels) > 0) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Dumping statistics about %d channels:", smartlist_len(all_channels)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "%d are active, and %d are done and waiting for cleanup", (active_channels != NULL) ? smartlist_len(active_channels) : 0, @@ -2649,10 +2649,10 @@ channel_dumpstats(int severity) SMARTLIST_FOREACH(all_channels, channel_t *, chan, channel_dump_statistics(chan, severity)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Done spamming about channels now"); } else { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "No channels to dump"); } } @@ -2668,10 +2668,10 @@ void channel_listener_dumpstats(int severity) { if (all_listeners && smartlist_len(all_listeners) > 0) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Dumping statistics about %d channel listeners:", smartlist_len(all_listeners)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "%d are active and %d are done and waiting for cleanup", (active_listeners != NULL) ? smartlist_len(active_listeners) : 0, @@ -2681,10 +2681,10 @@ channel_listener_dumpstats(int severity) SMARTLIST_FOREACH(all_listeners, channel_listener_t *, chan_l, channel_listener_dump_statistics(chan_l, severity)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Done spamming about channel listeners now"); } else { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "No channel listeners to dump"); } } @@ -3115,7 +3115,7 @@ chan_cell_queue_len(const chan_cell_queue_t *queue) { int r = 0; cell_queue_entry_t *cell; - SIMPLEQ_FOREACH(cell, queue, next) + TOR_SIMPLEQ_FOREACH(cell, queue, next) ++r; return r; } @@ -3139,13 +3139,13 @@ channel_dump_statistics(channel_t *chan, int severity) age = (double)(now - chan->timestamp_created); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Channel " U64_FORMAT " (at %p) with transport %s is in state " "%s (%d)", U64_PRINTF_ARG(chan->global_identifier), chan, channel_describe_transport(chan), channel_state_to_string(chan->state), chan->state); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " was created at " U64_FORMAT " (" U64_FORMAT " seconds ago) " "and last active at " U64_FORMAT " (" U64_FORMAT " seconds ago)", @@ -3158,14 +3158,14 @@ channel_dump_statistics(channel_t *chan, int severity) /* Handle digest and nickname */ if (!tor_digest_is_zero(chan->identity_digest)) { if (chan->nickname) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " says it is connected " "to an OR with digest %s and nickname %s", U64_PRINTF_ARG(chan->global_identifier), hex_str(chan->identity_digest, DIGEST_LEN), chan->nickname); } else { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " says it is connected " "to an OR with digest %s and no known nickname", U64_PRINTF_ARG(chan->global_identifier), @@ -3173,13 +3173,13 @@ channel_dump_statistics(channel_t *chan, int severity) } } else { if (chan->nickname) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " does not know the digest" " of the OR it is connected to, but reports its nickname is %s", U64_PRINTF_ARG(chan->global_identifier), chan->nickname); } else { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " does not know the digest" " or the nickname of the OR it is connected to", U64_PRINTF_ARG(chan->global_identifier)); @@ -3191,7 +3191,7 @@ channel_dump_statistics(channel_t *chan, int severity) if (have_remote_addr) { char *actual = tor_strdup(channel_get_actual_remote_descr(chan)); remote_addr_str = tor_dup_addr(&remote_addr); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " says its remote address" " is %s, and gives a canonical description of \"%s\" and an " "actual description of \"%s\"", @@ -3203,7 +3203,7 @@ channel_dump_statistics(channel_t *chan, int severity) tor_free(actual); } else { char *actual = tor_strdup(channel_get_actual_remote_descr(chan)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " does not know its remote " "address, but gives a canonical description of \"%s\" and an " "actual description of \"%s\"", @@ -3214,7 +3214,7 @@ channel_dump_statistics(channel_t *chan, int severity) } /* Handle marks */ - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has these marks: %s %s %s " "%s %s %s", U64_PRINTF_ARG(chan->global_identifier), @@ -3233,7 +3233,7 @@ channel_dump_statistics(channel_t *chan, int severity) "incoming" : "outgoing"); /* Describe queues */ - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has %d queued incoming cells" " and %d queued outgoing cells", U64_PRINTF_ARG(chan->global_identifier), @@ -3241,7 +3241,7 @@ channel_dump_statistics(channel_t *chan, int severity) chan_cell_queue_len(&chan->outgoing_queue)); /* Describe circuits */ - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has %d active circuits out of" " %d in total", U64_PRINTF_ARG(chan->global_identifier), @@ -3251,25 +3251,25 @@ channel_dump_statistics(channel_t *chan, int severity) circuitmux_num_circuits(chan->cmux) : 0); /* Describe timestamps */ - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " was last used by a " "client at " U64_FORMAT " (" U64_FORMAT " seconds ago)", U64_PRINTF_ARG(chan->global_identifier), U64_PRINTF_ARG(chan->timestamp_client), U64_PRINTF_ARG(now - chan->timestamp_client)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " was last drained at " U64_FORMAT " (" U64_FORMAT " seconds ago)", U64_PRINTF_ARG(chan->global_identifier), U64_PRINTF_ARG(chan->timestamp_drained), U64_PRINTF_ARG(now - chan->timestamp_drained)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " last received a cell " "at " U64_FORMAT " (" U64_FORMAT " seconds ago)", U64_PRINTF_ARG(chan->global_identifier), U64_PRINTF_ARG(chan->timestamp_recv), U64_PRINTF_ARG(now - chan->timestamp_recv)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " last trasmitted a cell " "at " U64_FORMAT " (" U64_FORMAT " seconds ago)", U64_PRINTF_ARG(chan->global_identifier), @@ -3277,7 +3277,7 @@ channel_dump_statistics(channel_t *chan, int severity) U64_PRINTF_ARG(now - chan->timestamp_xmit)); /* Describe counters and rates */ - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has received " U64_FORMAT " cells and transmitted " U64_FORMAT, U64_PRINTF_ARG(chan->global_identifier), @@ -3288,13 +3288,13 @@ channel_dump_statistics(channel_t *chan, int severity) if (chan->n_cells_recved > 0) { avg = (double)(chan->n_cells_recved) / age; if (avg >= 1.0) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has averaged %f " "cells received per second", U64_PRINTF_ARG(chan->global_identifier), avg); } else if (avg >= 0.0) { interval = 1.0 / avg; - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has averaged %f " "seconds between received cells", U64_PRINTF_ARG(chan->global_identifier), interval); @@ -3303,13 +3303,13 @@ channel_dump_statistics(channel_t *chan, int severity) if (chan->n_cells_xmitted > 0) { avg = (double)(chan->n_cells_xmitted) / age; if (avg >= 1.0) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has averaged %f " "cells transmitted per second", U64_PRINTF_ARG(chan->global_identifier), avg); } else if (avg >= 0.0) { interval = 1.0 / avg; - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel " U64_FORMAT " has averaged %f " "seconds between transmitted cells", U64_PRINTF_ARG(chan->global_identifier), interval); @@ -3337,13 +3337,13 @@ channel_listener_dump_statistics(channel_listener_t *chan_l, int severity) age = (double)(now - chan_l->timestamp_created); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, "Channel listener " U64_FORMAT " (at %p) with transport %s is in " "state %s (%d)", U64_PRINTF_ARG(chan_l->global_identifier), chan_l, channel_listener_describe_transport(chan_l), channel_listener_state_to_string(chan_l->state), chan_l->state); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel listener " U64_FORMAT " was created at " U64_FORMAT " (" U64_FORMAT " seconds ago) " "and last active at " U64_FORMAT " (" U64_FORMAT " seconds ago)", @@ -3353,7 +3353,7 @@ channel_listener_dump_statistics(channel_listener_t *chan_l, int severity) U64_PRINTF_ARG(chan_l->timestamp_active), U64_PRINTF_ARG(now - chan_l->timestamp_active)); - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel listener " U64_FORMAT " last accepted an incoming " "channel at " U64_FORMAT " (" U64_FORMAT " seconds ago) " "and has accepted " U64_FORMAT " channels in total", @@ -3371,13 +3371,13 @@ channel_listener_dump_statistics(channel_listener_t *chan_l, int severity) chan_l->n_accepted > 0) { avg = (double)(chan_l->n_accepted) / age; if (avg >= 1.0) { - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel listener " U64_FORMAT " has averaged %f incoming " "channels per second", U64_PRINTF_ARG(chan_l->global_identifier), avg); } else if (avg >= 0.0) { interval = 1.0 / avg; - log(severity, LD_GENERAL, + tor_log(severity, LD_GENERAL, " * Channel listener " U64_FORMAT " has averaged %f seconds " "between incoming channels", U64_PRINTF_ARG(chan_l->global_identifier), interval); @@ -3504,7 +3504,7 @@ channel_has_queued_writes(channel_t *chan) tor_assert(chan); tor_assert(chan->has_queued_writes); - if (! SIMPLEQ_EMPTY(&chan->outgoing_queue)) { + if (! TOR_SIMPLEQ_EMPTY(&chan->outgoing_queue)) { has_writes = 1; } else { /* Check with the lower layer */ |