From 29bf271ba2deb9714f515e03a9674ac43b9d7156 Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Thu, 14 May 2009 05:20:27 -0700 Subject: [PATCH 1/2] Fix misreporting of stream bandwidths. --- ChangeLog | 1 + src/or/connection.c | 1 + src/or/connection_edge.c | 1 + src/or/control.c | 22 ++++++++++++++++++++++ src/or/or.h | 1 + 5 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4918dd2b71..b898ff8f64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ Changes in version 0.2.1.15??? - ????-??-?? directory authority. Fixes part of bug 932. - When we change to or from being a bridge, reset our counts of client usage by country. Fixes bug 932. + - Fix a bug that made stream bandwidth get misreported to the controller. Changes in version 0.2.1.14-rc - 2009-04-12 diff --git a/src/or/connection.c b/src/or/connection.c index 3a01c28652..15a7110428 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -618,6 +618,7 @@ connection_about_to_close_connection(connection_t *conn) conn->marked_for_close_file, conn->marked_for_close); dnsserv_reject_request(edge_conn); } + control_event_stream_bandwidth(edge_conn); control_event_stream_status(edge_conn, STREAM_EVENT_CLOSED, edge_conn->end_reason); circ = circuit_get_by_edge_conn(edge_conn); diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index b350c08d29..f7b4e3579c 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -160,6 +160,7 @@ connection_edge_destroy(circid_t circ_id, edge_connection_t *conn) "CircID %d: At an edge. Marking connection for close.", circ_id); if (conn->_base.type == CONN_TYPE_AP) { connection_mark_unattached_ap(conn, END_STREAM_REASON_DESTROY); + control_event_stream_bandwidth(conn); control_event_stream_status(conn, STREAM_EVENT_CLOSED, END_STREAM_REASON_DESTROY); conn->end_reason |= END_STREAM_REASON_FLAG_ALREADY_SENT_CLOSED; diff --git a/src/or/control.c b/src/or/control.c index 26758de71c..3e0fb84c81 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -3275,6 +3275,28 @@ control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t tp, return 0; } +/** + * Print out STREAM_BW event for a single conn + */ +int +control_event_stream_bandwidth(edge_connection_t *edge_conn) +{ + if (EVENT_IS_INTERESTING(EVENT_STREAM_BANDWIDTH_USED)) { + if (!edge_conn->n_read && !edge_conn->n_written) + return 0; + + send_control_event(EVENT_STREAM_BANDWIDTH_USED, ALL_NAMES, + "650 STREAM_BW "U64_FORMAT" %lu %lu\r\n", + U64_PRINTF_ARG(edge_conn->_base.global_identifier), + (unsigned long)edge_conn->n_read, + (unsigned long)edge_conn->n_written); + + edge_conn->n_written = edge_conn->n_read = 0; + } + + return 0; +} + /** A second or more has elapsed: tell any interested control * connections how much bandwidth streams have used. */ int diff --git a/src/or/or.h b/src/or/or.h index 731cf5e9a8..a20015e0f9 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3225,6 +3225,7 @@ int control_event_stream_status(edge_connection_t *conn, int control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t e, int reason); int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written); +int control_event_stream_bandwidth(edge_connection_t *edge_conn); int control_event_stream_bandwidth_used(void); void control_event_logmsg(int severity, unsigned int domain, const char *msg); int control_event_descriptors_changed(smartlist_t *routers); From 9f25a5529a2e7aa6226851d2b9e3ccc77abdb88a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 16 May 2009 23:57:30 -0400 Subject: [PATCH 2/2] Fix an assertion-failure in memarea_alloc() on 64-bit platforms. The trick is that we should assert that our next_mem pointer has not run off the end of the array _before_ we realign the pointer, since doing that could take us over the end... but only if we're on a system where malloc() gives us ram in increments smaller than sizeof(void*). --- ChangeLog | 7 ++++++- src/common/memarea.c | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b898ff8f64..65656f5dec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,7 +12,12 @@ Changes in version 0.2.1.15??? - ????-??-?? directory authority. Fixes part of bug 932. - When we change to or from being a bridge, reset our counts of client usage by country. Fixes bug 932. - - Fix a bug that made stream bandwidth get misreported to the controller. + - Fix a bug that made stream bandwidth get misreported to the + controller. + - Fix an assertion failure on 64-bit platforms when we allocated + memory right up to the end of a memarea, then realigned the + memory one step beyond the end. Fixes a possible cause of bug + 930. Changes in version 0.2.1.14-rc - 2009-04-12 diff --git a/src/common/memarea.c b/src/common/memarea.c index 7771f2c2ac..1c81e2fd78 100644 --- a/src/common/memarea.c +++ b/src/common/memarea.c @@ -182,6 +182,8 @@ memarea_alloc(memarea_t *area, size_t sz) memarea_chunk_t *chunk = area->first; char *result; tor_assert(chunk); + if (sz == 0) + sz = 1; if (chunk->next_mem+sz > chunk->u.mem+chunk->mem_size) { if (sz+CHUNK_HEADER_SIZE >= CHUNK_SIZE) { /* This allocation is too big. Stick it in a special chunk, and put @@ -198,10 +200,11 @@ memarea_alloc(memarea_t *area, size_t sz) tor_assert(chunk->mem_size >= sz); } result = chunk->next_mem; - chunk->next_mem = realign_pointer(chunk->next_mem + sz); + chunk->next_mem = chunk->next_mem + sz; // XXXX021 remove these once bug 930 is solved. tor_assert(chunk->next_mem >= chunk->u.mem); tor_assert(chunk->next_mem <= chunk->u.mem+chunk->mem_size); + chunk->next_mem = realign_pointer(chunk->next_mem); return result; } @@ -272,7 +275,8 @@ memarea_assert_ok(memarea_t *area) for (chunk = area->first; chunk; chunk = chunk->next_chunk) { tor_assert(chunk->next_mem >= chunk->u.mem); - tor_assert(chunk->next_mem <= chunk->u.mem+chunk->mem_size+MEMAREA_ALIGN); + tor_assert(chunk->next_mem <= + (char*) realign_pointer(chunk->u.mem+chunk->mem_size)); } }