diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2013-05-24 12:01:32 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2013-05-25 19:51:38 +0200 |
commit | 2f893624abb65a0df4f0f8ca6fbbe0c00fbf216a (patch) | |
tree | 6878bf260ef828ab871d6bb8a30f6d057dda6b9c /src | |
parent | a84fae789206db4e27486e693488328da7b3474a (diff) | |
download | tor-2f893624abb65a0df4f0f8ca6fbbe0c00fbf216a.tar tor-2f893624abb65a0df4f0f8ca6fbbe0c00fbf216a.tar.gz |
Tweak CONN_BW event based on comments by nickm.
- Rename read/write counters in connection_t to make it clear that these
are only used for CONN_BW events.
- Add TestingEnableConnBwEvent option.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 8 | ||||
-rw-r--r-- | src/or/connection.c | 24 | ||||
-rw-r--r-- | src/or/control.c | 12 | ||||
-rw-r--r-- | src/or/or.h | 13 |
4 files changed, 35 insertions, 22 deletions
diff --git a/src/or/config.c b/src/or/config.c index 8ca89b6a7..e7060a5dc 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -218,6 +218,7 @@ static config_var_t option_vars_[] = { VPORT(DNSPort, LINELIST, NULL), V(DNSListenAddress, LINELIST, NULL), V(DownloadExtraInfo, BOOL, "0"), + V(TestingEnableConnBwEvent, BOOL, "0"), V(EnforceDistinctSubnets, BOOL, "1"), V(EntryNodes, ROUTERSET, NULL), V(EntryStatistics, BOOL, "0"), @@ -461,6 +462,7 @@ static const config_var_t testing_tor_network_defaults[] = { V(TestingAuthDirTimeToLearnReachability, INTERVAL, "0 minutes"), V(TestingEstimatedDescriptorPropagationTime, INTERVAL, "0 minutes"), V(MinUptimeHidServDirectoryV2, INTERVAL, "0 minutes"), + V(TestingEnableConnBwEvent, BOOL, "1"), VAR("___UsingTestNetworkDefaults", BOOL, UsingTestNetworkDefaults_, "1"), { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL } @@ -3236,6 +3238,12 @@ options_validate(or_options_t *old_options, or_options_t *options, COMPLAIN("TestingEstimatedDescriptorPropagationTime is insanely high."); } + if (options->TestingEnableConnBwEvent && + !options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) { + REJECT("TestingEnableConnBwEvent may only be changed in testing " + "Tor networks!"); + } + if (options->TestingTorNetwork) { log_warn(LD_CONFIG, "TestingTorNetwork is set. This will make your node " "almost unusable in the public Tor network, and is " diff --git a/src/or/connection.c b/src/or/connection.c index a00351a77..f7f028b0b 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -3224,16 +3224,16 @@ connection_read_to_buf(connection_t *conn, ssize_t *max_to_read, } } - /* In TestingTorNetwork mode, update conn->n_read for OR/DIR/EXIT - * connections, checking for overflow. */ - if (get_options()->TestingTorNetwork && + /* If CONN_BW events are enabled, update conn->n_read_conn_bw for + * OR/DIR/EXIT connections, checking for overflow. */ + if (get_options()->TestingEnableConnBwEvent && (conn->type == CONN_TYPE_OR || conn->type == CONN_TYPE_DIR || conn->type == CONN_TYPE_EXIT)) { - if (PREDICT_LIKELY(UINT32_MAX - conn->n_read > n_read)) - conn->n_read += (int)n_read; + if (PREDICT_LIKELY(UINT32_MAX - conn->n_read_conn_bw > n_read)) + conn->n_read_conn_bw += (int)n_read; else - conn->n_read = UINT32_MAX; + conn->n_read_conn_bw = UINT32_MAX; } } @@ -3691,16 +3691,16 @@ connection_handle_write_impl(connection_t *conn, int force) } } - /* In TestingTorNetwork mode, update conn->n_written for OR/DIR/EXIT - * connections, checking for overflow. */ - if (n_written && get_options()->TestingTorNetwork && + /* If CONN_BW events are enabled, update conn->n_written_conn_bw for + * OR/DIR/EXIT connections, checking for overflow. */ + if (n_written && get_options()->TestingEnableConnBwEvent && (conn->type == CONN_TYPE_OR || conn->type == CONN_TYPE_DIR || conn->type == CONN_TYPE_EXIT)) { - if (PREDICT_LIKELY(UINT32_MAX - conn->n_written > n_written)) - conn->n_written += (int)n_written; + if (PREDICT_LIKELY(UINT32_MAX - conn->n_written_conn_bw > n_written)) + conn->n_written_conn_bw += (int)n_written; else - conn->n_written = UINT32_MAX; + conn->n_written_conn_bw = UINT32_MAX; } connection_buckets_decrement(conn, approx_time(), n_read, n_written); diff --git a/src/or/control.c b/src/or/control.c index 2accf7f4a..10f96b345 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -3967,10 +3967,10 @@ int control_event_conn_bandwidth(connection_t *conn) { const char *conn_type_str; - if (!get_options()->TestingTorNetwork || + if (!get_options()->TestingEnableConnBwEvent || !EVENT_IS_INTERESTING(EVENT_CONN_BW)) return 0; - if (!conn->n_read && !conn->n_written) + if (!conn->n_read_conn_bw && !conn->n_written_conn_bw) return 0; switch (conn->type) { case CONN_TYPE_OR: @@ -3990,9 +3990,9 @@ control_event_conn_bandwidth(connection_t *conn) "READ=%lu WRITTEN=%lu\r\n", U64_PRINTF_ARG(conn->global_identifier), conn_type_str, - (unsigned long)conn->n_read, - (unsigned long)conn->n_written); - conn->n_written = conn->n_read = 0; + (unsigned long)conn->n_read_conn_bw, + (unsigned long)conn->n_written_conn_bw); + conn->n_written_conn_bw = conn->n_read_conn_bw = 0; return 0; } @@ -4001,7 +4001,7 @@ control_event_conn_bandwidth(connection_t *conn) int control_event_conn_bandwidth_used(void) { - if (get_options()->TestingTorNetwork && + if (get_options()->TestingEnableConnBwEvent && EVENT_IS_INTERESTING(EVENT_CONN_BW)) { SMARTLIST_FOREACH(get_connection_array(), connection_t *, conn, control_event_conn_bandwidth(conn)); diff --git a/src/or/or.h b/src/or/or.h index d41034cb7..c807fb00c 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1249,11 +1249,13 @@ typedef struct connection_t { /** Unique identifier for this connection on this Tor instance. */ uint64_t global_identifier; - /** Bytes read since last call to control_event_conn_bandwidth_used() */ - uint32_t n_read; + /** Bytes read since last call to control_event_conn_bandwidth_used(). + * Only used if we're configured to emit CONN_BW events. */ + uint32_t n_read_conn_bw; - /** Bytes written since last call to control_event_conn_bandwidth_used() */ - uint32_t n_written; + /** Bytes written since last call to control_event_conn_bandwidth_used(). + * Only used if we're configured to emit CONN_BW events. */ + uint32_t n_written_conn_bw; } connection_t; /** Subtype of connection_t; used for a listener socket. */ @@ -3983,6 +3985,9 @@ typedef struct { /** Minimum value for the Fast flag threshold on testing networks. */ uint64_t TestingMinFastFlagThreshold; + /** Enable CONN_BW events. Only altered on testing networks. */ + int TestingEnableConnBwEvent; + /** If true, and we have GeoIP data, and we're a bridge, keep a per-country * count of how many client addresses have contacted us so that we can help * the bridge authority guess which countries have blocked access to us. */ |