aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/tor.1.txt6
-rw-r--r--src/or/config.c8
-rw-r--r--src/or/connection.c24
-rw-r--r--src/or/control.c12
-rw-r--r--src/or/or.h13
5 files changed, 41 insertions, 22 deletions
diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index 0a6f8f524..209670a15 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -2005,6 +2005,7 @@ The following options are used for running a testing Tor network.
TestingV3AuthInitialDistDelay 20 seconds
TestingAuthDirTimeToLearnReachability 0 minutes
TestingEstimatedDescriptorPropagationTime 0 minutes
+ TestingEnableConnBwEvent 1
**TestingV3AuthInitialVotingInterval** __N__ **minutes**|**hours**::
Like V3AuthVotingInterval, but for initial voting interval before the first
@@ -2035,6 +2036,11 @@ The following options are used for running a testing Tor network.
Minimum value for the Fast flag. Overrides the ordinary minimum taken
from the consensus when TestingTorNetwork is set. (Default: 0.)
+**TestingEnableConnBwEvent** **0**|**1**::
+ If this option is set, then Tor controllers may register for CONN_BW
+ events. Changing this requires that **TestingTorNetwork** is set.
+ (Default: 0)
+
SIGNALS
-------
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. */