r11813@catbus: nickm | 2007-02-14 11:42:58 -0500

Tweak stream_bw patch: Remove a couple of redundant checks, save 8 bytes per edge connection, fix spelling in the changelog; expand spec.


svn:r9586
This commit is contained in:
Nick Mathewson 2007-02-14 16:46:55 +00:00
parent 4a74812c70
commit 6e35b11851
5 changed files with 48 additions and 31 deletions

View File

@ -45,7 +45,7 @@ Changes in version 0.1.2.8-alpha - 2007-??-??
control protocol. We're planning to remove support for it during
the next development series, so it's good to give people some
advance warning.
- Add STREAM_BW events to reprot per-entry-stream bandwidth use. (Patch
- Add STREAM_BW events to report per-entry-stream bandwidth use. (Patch
from Robert Hogan.)
o Minor features:

View File

@ -1271,16 +1271,20 @@ $Id$
[First added in 0.1.2.3-alpha]
4.1.13. Bandwidth used on a stream
4.1.13. Bandwidth used on an application stream
The syntax is:
"650" SP "STREAM_BW" SP StreamID SP BytesRead SP BytesWritten
BytesRead = 1*DIGIT
BytesWritten = 1*DIGIT
The number of bytes read and written since the last read or write event
on a stream.
BytesRead and BytesWritten are the number of bytes read and written since
the last STREAM_BW event on a stream. These events are generated about
once per second per stream; No event is generated for streams that have not
read or written.
These events apply only to streams entering Tor (such as on a SOCKSPort,
TransPort, or so on). They are not generated for exiting streams.
5. Implementation notes

View File

@ -1571,12 +1571,10 @@ connection_read_to_buf(connection_t *conn, int *max_to_read)
*max_to_read = at_most - n_read;
}
if (CONN_IS_EDGE(conn)) {
if (conn->type == CONN_TYPE_AP) {
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
edge_conn->n_read += n_read;
}
}
if (connection_is_rate_limited(conn)) {
/* For non-local IPs, remember if we flushed any bytes over the wire. */
@ -1774,12 +1772,10 @@ connection_handle_write(connection_t *conn, int force)
n_written = (size_t) result;
}
if (CONN_IS_EDGE(conn)) {
if (conn->type == CONN_TYPE_AP) {
edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
edge_conn->n_written += n_written;
}
}
if (connection_is_rate_limited(conn)) {
/* For non-local IPs, remember if we flushed any bytes over the wire. */

View File

@ -126,9 +126,10 @@ static const char * CONTROL0_COMMANDS[_CONTROL0_CMD_MAX_RECOGNIZED+1] = {
* has interest in without having to walk over the global connection
* list to find out.
**/
static uint32_t global_event_mask0 = 0;
static uint32_t global_event_mask1long = 0;
static uint32_t global_event_mask1short = 0;
typedef uint32_t event_mask_t;
static event_mask_t global_event_mask0 = 0;
static event_mask_t global_event_mask1long = 0;
static event_mask_t global_event_mask1short = 0;
/** True iff we have disabled log messages from being sent to the controller */
static int disable_log_messages = 0;
@ -276,6 +277,11 @@ control_update_global_event_mask(void)
{
connection_t **conns;
int n_conns, i;
event_mask_t old_mask, new_mask;
old_mask = global_event_mask0;
old_mask |= global_event_mask1short;
old_mask |= global_event_mask1long;
global_event_mask0 = 0;
global_event_mask1short = 0;
global_event_mask1long = 0;
@ -293,7 +299,25 @@ control_update_global_event_mask(void)
}
}
new_mask = global_event_mask0;
new_mask |= global_event_mask1short;
new_mask |= global_event_mask1long;
/* Handle the aftermath. Set up the log callback to tell us only what
* we want to hear...*/
control_adjust_event_log_severity();
/* ...then, if we've started logging stream bw, clear the appropriate
* fields. */
if (! (old_mask & EVENT_STREAM_BANDWIDTH_USED) &&
(new_mask & EVENT_STREAM_BANDWIDTH_USED)) {
for (i = 0; i < n_conns; ++i) {
if (conns[i]->type == CONN_TYPE_AP) {
edge_connection_t *conn = TO_EDGE_CONN(conns[i]);
conn->n_written = conn->n_read = 0;
}
}
}
}
/** Adjust the log severities that result in control_event_logmsg being called
@ -3416,12 +3440,11 @@ control_event_or_conn_status(or_connection_t *conn,or_conn_status_event_t tp,
/** A second or more has elapsed: tell any interested control
* connections how much bandwidth streams have used. */
int
control_event_stream_bandwidth_used()
control_event_stream_bandwidth_used(void)
{
connection_t **carray;
edge_connection_t *conn;
int n, i;
uint32_t justread, justwritten;
if (EVENT_IS_INTERESTING1(EVENT_STREAM_BANDWIDTH_USED)) {
@ -3431,20 +3454,16 @@ control_event_stream_bandwidth_used()
if (carray[i]->type != CONN_TYPE_AP)
continue;
conn = TO_EDGE_CONN(carray[i]);
if (conn->p_read == conn->n_read && conn->p_written == conn->n_written)
if (!conn->n_read && !conn->n_written)
continue;
justread = conn->n_read - conn->p_read;
conn->p_read = conn->n_read;
justwritten = conn->n_written - conn->p_written;
conn->p_written = conn->n_written;
send_control1_event(EVENT_STREAM_BANDWIDTH_USED, ALL_NAMES,
"650 STREAM_BW %lu %lu %lu\r\n",
(unsigned long)conn->global_identifier,
(unsigned long)justread,
(unsigned long)justwritten);
(unsigned long)conn->n_read,
(unsigned long)conn->n_written);
conn->n_written = conn->n_read = 0;
}
}

View File

@ -838,13 +838,11 @@ typedef struct edge_connection_t {
/* XXXX NM This can get re-used after 2**32 streams */
uint32_t global_identifier;
/** Bytes read */
/** Bytes read since last call to control_event_stream_bandwidth_used() */
uint32_t n_read;
uint32_t p_read;
/** Bytes written */
/** Bytes written since last call to control_event_stream_bandwidth_used() */
uint32_t n_written;
uint32_t p_written;
/** Exit only: a dirserv connection that is tunneled over this connection
* using a socketpair. */