From d7fcaca3fcbc46c2aebe556c6649ce1eddb833dd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 26 Feb 2015 15:21:31 -0500 Subject: [PATCH 01/17] Have zero_length_keys.sh use an empty torrc file. Fixes 15033; bugfix on 0.2.6.3-alpha. --- changes/bug15033 | 4 ++++ src/test/zero_length_keys.sh | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changes/bug15033 diff --git a/changes/bug15033 b/changes/bug15033 new file mode 100644 index 000000000..953e6c3d5 --- /dev/null +++ b/changes/bug15033 @@ -0,0 +1,4 @@ + o Minor bugfixes (tests): + - When running the zero-length-keys check, do not use the default + torrc file. Fixes bug 15033; bugfix on 0.2.6.3-alpha. Reported + by "reezer". diff --git a/src/test/zero_length_keys.sh b/src/test/zero_length_keys.sh index 4dea283fd..2fd11d38b 100755 --- a/src/test/zero_length_keys.sh +++ b/src/test/zero_length_keys.sh @@ -36,9 +36,11 @@ if [ ! -d "$DATA_DIR" ]; then fi trap "rm -rf '$DATA_DIR'" 0 +touch "$DATA_DIR"/empty_torrc + # DisableNetwork means that the ORPort won't actually be opened. # 'ExitRelay 0' suppresses a warning. -TOR="./src/or/tor --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0" +TOR="./src/or/tor --hush --DisableNetwork 1 --ShutdownWaitLength 0 --ORPort 12345 --ExitRelay 0 -f $DATA_DIR/empty_torrc" if [ -s "$DATA_DIR"/keys/secret_id_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key ] && [ -s "$DATA_DIR"/keys/secret_onion_key_ntor ]; then From 334f74f6f123411c74cfd4c8614e40110c34690a Mon Sep 17 00:00:00 2001 From: cypherpunks Date: Thu, 26 Feb 2015 10:38:09 +0100 Subject: [PATCH 02/17] Use configured Python binary in test-stem. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 67c9cc9d2..b1f92f5b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -73,7 +73,7 @@ test-network: all test-stem: $(TESTING_TOR_BINARY) @if test -d "$$STEM_SOURCE_DIR"; then \ - "$$STEM_SOURCE_DIR"/run_tests.py --tor $(TESTING_TOR_BINARY) --all --log notice --target RUN_ALL; \ + $(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor $(TESTING_TOR_BINARY) --all --log notice --target RUN_ALL; \ else \ echo '$$STEM_SOURCE_DIR was not set.'; echo; \ echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \ From 0f2f8fd68a54707bb256b446cff524f0e1ef1658 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 26 Feb 2015 15:24:43 -0500 Subject: [PATCH 03/17] changes file for 15037 --- changes/bug15037 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changes/bug15037 diff --git a/changes/bug15037 b/changes/bug15037 new file mode 100644 index 000000000..587d63186 --- /dev/null +++ b/changes/bug15037 @@ -0,0 +1,4 @@ + o Minor bugfixes (testing): + - When running the new 'make test-stem' target, use the configured + python binary. Fixes bug 15037; bugfix on 0.2.6.3-alpha. Patch + from "cypherpunks". From 79c69d18b76e8836593e1beb3d239a5ff5e63a7b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 27 Feb 2015 11:28:30 -0500 Subject: [PATCH 04/17] Include a HOST item in BOOTSTRAP problem messages Closes ticket 15006. --- changes/feature15006 | 4 ++++ src/or/control.c | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 changes/feature15006 diff --git a/changes/feature15006 b/changes/feature15006 new file mode 100644 index 000000000..168a440ba --- /dev/null +++ b/changes/feature15006 @@ -0,0 +1,4 @@ + o Minor features (controller): + - Messages about problems in the bootstrap process now include + information about the server we were trying to connect to when we + noticed the problem. Closes ticket 15006. diff --git a/src/or/control.c b/src/or/control.c index a2b986768..dc3e5fc6a 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -5049,6 +5049,7 @@ MOCK_IMPL(void, char buf[BOOTSTRAP_MSG_LEN]; const char *recommendation = "ignore"; int severity; + char host[128]; /* bootstrap_percent must not be in "undefined" state here. */ tor_assert(status >= 0); @@ -5078,6 +5079,8 @@ MOCK_IMPL(void, if (we_are_hibernating()) recommendation = "ignore"; + orconn_target_get_name(host, sizeof(host), or_conn); + while (status>=0 && bootstrap_status_to_string(status, &tag, &summary) < 0) status--; /* find a recognized status string based on current progress */ status = bootstrap_percent; /* set status back to the actual number */ @@ -5086,19 +5089,19 @@ MOCK_IMPL(void, log_fn(severity, LD_CONTROL, "Problem bootstrapping. Stuck at %d%%: %s. (%s; %s; " - "count %d; recommendation %s)", + "count %d; recommendation %s; host %s)", status, summary, warn, orconn_end_reason_to_control_string(reason), - bootstrap_problems, recommendation); + bootstrap_problems, recommendation, host); connection_or_report_broken_states(severity, LD_HANDSHAKE); tor_snprintf(buf, sizeof(buf), "BOOTSTRAP PROGRESS=%d TAG=%s SUMMARY=\"%s\" WARNING=\"%s\" REASON=%s " - "COUNT=%d RECOMMENDATION=%s", + "COUNT=%d RECOMMENDATION=%s HOST=\"%s\"", bootstrap_percent, tag, summary, warn, orconn_end_reason_to_control_string(reason), bootstrap_problems, - recommendation); + recommendation, host); tor_snprintf(last_sent_bootstrap_message, sizeof(last_sent_bootstrap_message), "WARN %s", buf); From 71ee53fe9bdf3f64eef9b38de55960185e8be1b5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 3 Mar 2015 22:20:17 +0100 Subject: [PATCH 05/17] Do not leave empty, invalid chunks in buffers during buf_pullup This fixes an assertion failure bug in 15083; bugfix on 0.2.0.10-alpha. Patch from 'cypherpunks' --- changes/bug15083 | 6 ++++++ src/or/buffers.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changes/bug15083 diff --git a/changes/bug15083 b/changes/bug15083 new file mode 100644 index 000000000..98d1d0e53 --- /dev/null +++ b/changes/bug15083 @@ -0,0 +1,6 @@ + o Major bugfixes (relay, stability): + - Fix a bug that could lead to a relay crashing with an assertion + failure if a buffer of exactly the wrong layout was passed + to buf_pullup() at exactly the wrong time. Fixes bug 15083; + bugfix on 0.2.0.10-alpha. Patch from 'cypherpunks'. + diff --git a/src/or/buffers.c b/src/or/buffers.c index 9be0476f6..797643279 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -426,7 +426,7 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate) size_t n = bytes - dest->datalen; src = dest->next; tor_assert(src); - if (n > src->datalen) { + if (n >= src->datalen) { memcpy(CHUNK_WRITE_PTR(dest), src->data, src->datalen); dest->datalen += src->datalen; dest->next = src->next; From 81a994ce77038721df3aa2f77b783db9a52da79e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 3 Mar 2015 22:25:26 +0100 Subject: [PATCH 06/17] Make the assert related to 15083 a tiny bit more tolerant --- changes/bug15083 | 6 +++++- src/or/buffers.c | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/changes/bug15083 b/changes/bug15083 index 98d1d0e53..2bd0715df 100644 --- a/changes/bug15083 +++ b/changes/bug15083 @@ -3,4 +3,8 @@ failure if a buffer of exactly the wrong layout was passed to buf_pullup() at exactly the wrong time. Fixes bug 15083; bugfix on 0.2.0.10-alpha. Patch from 'cypherpunks'. - + + - Do not assert if the 'data' pointer on a buffer is advanced to the very + end of the buffer; log a BUG message instead. Only assert if it is + past that point. Fixes bug 15083; bugfix on 0.2.0.10-alpha. + diff --git a/src/or/buffers.c b/src/or/buffers.c index 797643279..9dfed007d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -2483,7 +2483,14 @@ assert_buf_ok(buf_t *buf) total += ch->datalen; tor_assert(ch->datalen <= ch->memlen); tor_assert(ch->data >= &ch->mem[0]); - tor_assert(ch->data < &ch->mem[0]+ch->memlen); + tor_assert(ch->data <= &ch->mem[0]+ch->memlen); + if (ch->data == &ch->mem[0]+ch->memlen) { + static int warned = 0; + if (! warned) { + log_warn(LD_BUG, "Invariant violation in buf.c related to #15083"); + warned = 1; + } + } tor_assert(ch->data+ch->datalen <= &ch->mem[0] + ch->memlen); if (!ch->next) tor_assert(ch == buf->tail); From 930ab95e1fb0dfd5af35e7d84ca58ff21b65a605 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 12:09:33 +0100 Subject: [PATCH 07/17] Missing dependencies; fixes 15127. --- changes/bug15127 | 3 +++ src/common/include.am | 1 + src/or/include.am | 1 + 3 files changed, 5 insertions(+) create mode 100644 changes/bug15127 diff --git a/changes/bug15127 b/changes/bug15127 new file mode 100644 index 000000000..642dc02bc --- /dev/null +++ b/changes/bug15127 @@ -0,0 +1,3 @@ + o Minor bugfixes (compilation): + - Add missing dependencies to fix compilation on BSD. Patch from + Peter Palfrader. Fixes bug 15127; bugfix on 0.2.5.1-alpha. diff --git a/src/common/include.am b/src/common/include.am index 68e0110c2..06d94f987 100644 --- a/src/common/include.am +++ b/src/common/include.am @@ -139,4 +139,5 @@ src/common/common_sha1.i: $(libor_SOURCES) $(libor_crypto_a_SOURCES) $(COMMONHEA fi src/common/util_codedigest.o: src/common/common_sha1.i +src/common/src_common_libor_testing_a-util_codedigest.o: src/common/common_sha1.i diff --git a/src/or/include.am b/src/or/include.am index 47bdd0990..2e46f8a43 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -191,6 +191,7 @@ ORHEADERS = \ noinst_HEADERS+= $(ORHEADERS) micro-revision.i src/or/config_codedigest.o: src/or/or_sha1.i +src/or/src_or_libtor_testing_a-config_codedigest.o: src/or/or_sha1.i micro-revision.i: FORCE @rm -f micro-revision.tmp; \ From 2d926d0147af8c632fe389e770c5832009f2ddc0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 12:12:41 +0100 Subject: [PATCH 08/17] only declare rv when it is used in destination_from_socket. Fixes 15151 --- changes/bug15151 | 3 +++ src/or/connection_edge.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changes/bug15151 diff --git a/changes/bug15151 b/changes/bug15151 new file mode 100644 index 000000000..b9c306155 --- /dev/null +++ b/changes/bug15151 @@ -0,0 +1,3 @@ + o Minor bugfixes (compilation): + - Fix a compilation warning on FreeBSD. Fixes bug 15151; bugfix on + 0.2.6.2-alpha. diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 3c817decf..e6dfc634e 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1598,7 +1598,6 @@ destination_from_socket(entry_connection_t *conn, socks_request_t *req) struct sockaddr_storage orig_dst; socklen_t orig_dst_len = sizeof(orig_dst); tor_addr_t addr; - int rv; #ifdef TRANS_TRPOXY if (options->TransProxyType_parsed == TPT_TPROXY) { @@ -1613,6 +1612,7 @@ destination_from_socket(entry_connection_t *conn, socks_request_t *req) #endif #ifdef TRANS_NETFILTER + int rv = -1; switch (ENTRY_TO_CONN(conn)->socket_family) { #ifdef TRANS_NETFILTER_IPV4 case AF_INET: From d5b2cbea106e020436d577e42672d281400558dd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 12:18:10 +0100 Subject: [PATCH 09/17] Add wait4 to the seccomp2 sandbox allowable syscall list fixes bug 15088. patch from sanic. --- changes/bug15088 | 4 ++++ src/common/sandbox.c | 1 + 2 files changed, 5 insertions(+) create mode 100644 changes/bug15088 diff --git a/changes/bug15088 b/changes/bug15088 new file mode 100644 index 000000000..95878bdb3 --- /dev/null +++ b/changes/bug15088 @@ -0,0 +1,4 @@ + o Minor bugfixes (Linux seccomp2 sandbox): + - Upon receiving sighup, do not crash during attempts to call + wait4. Fixes bug 15088; bugfix on 0.2.5.1-alpha. Patch from + "sanic". diff --git a/src/common/sandbox.c b/src/common/sandbox.c index dbbaa59d7..e43b64b91 100644 --- a/src/common/sandbox.c +++ b/src/common/sandbox.c @@ -164,6 +164,7 @@ static int filter_nopar_gen[] = { #endif SCMP_SYS(stat), SCMP_SYS(uname), + SCMP_SYS(wait4), SCMP_SYS(write), SCMP_SYS(writev), SCMP_SYS(exit_group), From 681802817deb6fb93b95f8284856fd42f3556600 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 12:24:51 +0100 Subject: [PATCH 10/17] Make TransProxyType ipfw work correctly Fixes bug 15064; bugfix on 0.2.5.4-alpha. --- changes/bug15064 | 4 ++++ src/or/connection_edge.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changes/bug15064 diff --git a/changes/bug15064 b/changes/bug15064 new file mode 100644 index 000000000..e6bd747b1 --- /dev/null +++ b/changes/bug15064 @@ -0,0 +1,4 @@ + o Major bugfixes (FreeBSD IPFW transparent proxy): + - Fix address detection with FreeBSD transparent proxies, + when "TransProxyType ipfw" is in use. + Fixes bug 15064; bugfix on 0.2.5.4-alpha. diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 49f9ba497..1eeb22fce 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1531,7 +1531,8 @@ connection_ap_get_original_destination(entry_connection_t *conn, if (options->TransProxyType_parsed == TPT_PF_DIVERT) return destination_from_socket(conn, req); - if (options->TransProxyType_parsed == TPT_DEFAULT) + if (options->TransProxyType_parsed == TPT_DEFAULT || + options->TransProxyType_parsed == TPT_IPFW) return destination_from_pf(conn, req); (void)conn; From 98822df3dcdf7cd0456aee7898507dd3059f930b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 14:23:59 +0100 Subject: [PATCH 11/17] Make boostrap events include hostname ANDaddr AND digest --- src/or/control.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/or/control.c b/src/or/control.c index dc3e5fc6a..e25c3b295 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -5049,7 +5049,6 @@ MOCK_IMPL(void, char buf[BOOTSTRAP_MSG_LEN]; const char *recommendation = "ignore"; int severity; - char host[128]; /* bootstrap_percent must not be in "undefined" state here. */ tor_assert(status >= 0); @@ -5079,8 +5078,6 @@ MOCK_IMPL(void, if (we_are_hibernating()) recommendation = "ignore"; - orconn_target_get_name(host, sizeof(host), or_conn); - while (status>=0 && bootstrap_status_to_string(status, &tag, &summary) < 0) status--; /* find a recognized status string based on current progress */ status = bootstrap_percent; /* set status back to the actual number */ @@ -5089,19 +5086,26 @@ MOCK_IMPL(void, log_fn(severity, LD_CONTROL, "Problem bootstrapping. Stuck at %d%%: %s. (%s; %s; " - "count %d; recommendation %s; host %s)", + "count %d; recommendation %s; host %s at %s:%d)", status, summary, warn, orconn_end_reason_to_control_string(reason), - bootstrap_problems, recommendation, host); + bootstrap_problems, recommendation, + hex_str(or_conn->identity_digest, DIGEST_LEN), + or_conn->base_.address, + or_conn->base_.port); connection_or_report_broken_states(severity, LD_HANDSHAKE); tor_snprintf(buf, sizeof(buf), "BOOTSTRAP PROGRESS=%d TAG=%s SUMMARY=\"%s\" WARNING=\"%s\" REASON=%s " - "COUNT=%d RECOMMENDATION=%s HOST=\"%s\"", + "COUNT=%d RECOMMENDATION=%s HOSTID=\"%s\" HOSTADDR=\"%s:%d\"", bootstrap_percent, tag, summary, warn, orconn_end_reason_to_control_string(reason), bootstrap_problems, - recommendation, host); + recommendation, + hex_str(or_conn->identity_digest, DIGEST_LEN), + or_conn->base_.address, + (int)or_conn->base_.port); + tor_snprintf(last_sent_bootstrap_message, sizeof(last_sent_bootstrap_message), "WARN %s", buf); From de2c5ad8150a9c111dd8f1dcfed1ceea132578f9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 4 Mar 2015 15:18:33 +0100 Subject: [PATCH 12/17] Revert "Missing dependencies; fixes 15127." This reverts commit 930ab95e1fb0dfd5af35e7d84ca58ff21b65a605. --- changes/bug15127 | 3 --- src/common/include.am | 1 - src/or/include.am | 1 - 3 files changed, 5 deletions(-) delete mode 100644 changes/bug15127 diff --git a/changes/bug15127 b/changes/bug15127 deleted file mode 100644 index 642dc02bc..000000000 --- a/changes/bug15127 +++ /dev/null @@ -1,3 +0,0 @@ - o Minor bugfixes (compilation): - - Add missing dependencies to fix compilation on BSD. Patch from - Peter Palfrader. Fixes bug 15127; bugfix on 0.2.5.1-alpha. diff --git a/src/common/include.am b/src/common/include.am index a642f7a79..5b6339254 100644 --- a/src/common/include.am +++ b/src/common/include.am @@ -146,5 +146,4 @@ src/common/common_sha1.i: $(libor_SOURCES) $(libor_crypto_a_SOURCES) $(COMMONHEA fi src/common/util_codedigest.o: src/common/common_sha1.i -src/common/src_common_libor_testing_a-util_codedigest.o: src/common/common_sha1.i diff --git a/src/or/include.am b/src/or/include.am index e257ceb8c..b44e1099d 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -190,7 +190,6 @@ ORHEADERS = \ noinst_HEADERS+= $(ORHEADERS) micro-revision.i src/or/config_codedigest.o: src/or/or_sha1.i -src/or/src_or_libtor_testing_a-config_codedigest.o: src/or/or_sha1.i micro-revision.i: FORCE @rm -f micro-revision.tmp; \ From addffcc14ddf40b3cd1bff3fa86a82354e981a03 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 9 Mar 2015 11:07:50 -0400 Subject: [PATCH 13/17] Adjust changes header --- changes/bug15083 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/bug15083 b/changes/bug15083 index 2bd0715df..5cc79b5ba 100644 --- a/changes/bug15083 +++ b/changes/bug15083 @@ -1,4 +1,4 @@ - o Major bugfixes (relay, stability): + o Major bugfixes (relay, stability, possible security): - Fix a bug that could lead to a relay crashing with an assertion failure if a buffer of exactly the wrong layout was passed to buf_pullup() at exactly the wrong time. Fixes bug 15083; From d39ede7f202b931506c1126b63665eaed4676abf Mon Sep 17 00:00:00 2001 From: Tom van der Woerdt Date: Sun, 8 Mar 2015 19:20:56 +0100 Subject: [PATCH 14/17] testing_common.c: avoid side-effects of tor_assert --- src/test/testing_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/testing_common.c b/src/test/testing_common.c index d7d6dacee..403c83bdd 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -165,18 +165,21 @@ static crypto_pk_t *pregen_keys[5] = {NULL, NULL, NULL, NULL, NULL}; crypto_pk_t * pk_generate(int idx) { + int res; #ifdef CACHE_GENERATED_KEYS tor_assert(idx < N_PREGEN_KEYS); if (! pregen_keys[idx]) { pregen_keys[idx] = crypto_pk_new(); - tor_assert(!crypto_pk_generate_key(pregen_keys[idx])); + res = crypto_pk_generate_key(pregen_keys[idx]); + tor_assert(!res); } return crypto_pk_dup_key(pregen_keys[idx]); #else crypto_pk_t *result; (void) idx; result = crypto_pk_new(); - tor_assert(!crypto_pk_generate_key(result)); + res = crypto_pk_generate_key(result); + tor_assert(!res); return result; #endif } From 42d877f0847f5541108328c52fb671740b888a18 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 9 Mar 2015 11:13:57 -0400 Subject: [PATCH 15/17] Changes file for 15188 --- changes/15188 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changes/15188 diff --git a/changes/15188 b/changes/15188 new file mode 100644 index 000000000..2065b3974 --- /dev/null +++ b/changes/15188 @@ -0,0 +1,3 @@ + o Minor bugfixes (testing): + - Avoid a side-effect in a tor_assert() in the unit tests. Fixes bug + 15188; bugfix on 0.1.2.3-alpha. Patch from Tom van der Woerdt. From 62631904cb403ee9f27080a1cf096e8ddd8a3048 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 7 Jan 2015 11:37:23 -0500 Subject: [PATCH 16/17] GETINFO bw-event-cache to get information on recent BW events Closes 14128; useful to regain functionality lost because of 13988. --- changes/ticket14128 | 5 +++++ src/or/control.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/or/control.h | 1 + 3 files changed, 56 insertions(+) create mode 100644 changes/ticket14128 diff --git a/changes/ticket14128 b/changes/ticket14128 new file mode 100644 index 000000000..38b25fa7d --- /dev/null +++ b/changes/ticket14128 @@ -0,0 +1,5 @@ + o Minor features (controller): + - New "GETINFO bw-event-cache" to get information about recent bandwidth + events. Closes ticket 14128. Useful for controllers to get recent + bandwidth history after the fix for 13988. + diff --git a/src/or/control.c b/src/or/control.c index 9378f38f4..fbd648de9 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1424,6 +1424,8 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, (void) conn; if (!strcmp(question, "version")) { *answer = tor_strdup(get_version()); + } else if (!strcmp(question, "bw-event-cache")) { + *answer = get_bw_samples(); } else if (!strcmp(question, "config-file")) { *answer = tor_strdup(get_torrc_fname(0)); } else if (!strcmp(question, "config-defaults-file")) { @@ -2099,6 +2101,7 @@ typedef struct getinfo_item_t { * to answer them. */ static const getinfo_item_t getinfo_items[] = { ITEM("version", misc, "The current version of Tor."), + ITEM("bw-event-cache", misc, "Cached BW events for a short interval."), ITEM("config-file", misc, "Current location of the \"torrc\" file."), ITEM("config-defaults-file", misc, "Current location of the defaults file."), ITEM("config-text", misc, @@ -4133,11 +4136,29 @@ control_event_tb_empty(const char *bucket, uint32_t read_empty_time, return 0; } +/* about 5 minutes worth. */ +#define N_BW_EVENTS_TO_CACHE 300 +/* Index into cached_bw_events to next write. */ +static int next_measurement_idx = 0; +/* number of entries set in n_measurements */ +static int n_measurements = 0; +static struct cached_bw_event_s { + uint32_t n_read; + uint32_t n_written; +} cached_bw_events[N_BW_EVENTS_TO_CACHE]; + /** A second or more has elapsed: tell any interested control * connections how much bandwidth we used. */ int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written) { + cached_bw_events[next_measurement_idx].n_read = n_read; + cached_bw_events[next_measurement_idx].n_written = n_written; + if (++next_measurement_idx == N_BW_EVENTS_TO_CACHE) + next_measurement_idx = 0; + if (n_measurements < N_BW_EVENTS_TO_CACHE) + ++n_measurements; + if (EVENT_IS_INTERESTING(EVENT_BANDWIDTH_USED)) { send_control_event(EVENT_BANDWIDTH_USED, ALL_FORMATS, "650 BW %lu %lu\r\n", @@ -4148,6 +4169,35 @@ control_event_bandwidth_used(uint32_t n_read, uint32_t n_written) return 0; } +STATIC char * +get_bw_samples(void) +{ + int i; + int idx = (next_measurement_idx + N_BW_EVENTS_TO_CACHE - n_measurements) + % N_BW_EVENTS_TO_CACHE; + tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE); + + smartlist_t *elements = smartlist_new(); + + for (i = 0; i < n_measurements; ++i) { + tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE); + const struct cached_bw_event_s *bwe = &cached_bw_events[idx]; + + smartlist_add_asprintf(elements, "%u,%u", + (unsigned)bwe->n_read, + (unsigned)bwe->n_written); + + idx = (idx + 1) % N_BW_EVENTS_TO_CACHE; + } + + char *result = smartlist_join_strings(elements, " ", 0, NULL); + + SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp)); + smartlist_free(elements); + + return result; +} + /** Called when we are sending a log message to the controllers: suspend * sending further log messages to the controllers until we're done. Used by * CONN_LOG_PROTECT. */ diff --git a/src/or/control.h b/src/or/control.h index 494f04b3b..869726217 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -201,6 +201,7 @@ void append_cell_stats_by_command(smartlist_t *event_parts, const uint64_t *number_to_include); void format_cell_stats(char **event_string, circuit_t *circ, cell_stats_t *cell_stats); +STATIC char *get_bw_samples(void); #endif #endif From 64bfc2930ac0be3af669636c16f6f0bba715056f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 9 Mar 2015 13:22:58 -0400 Subject: [PATCH 17/17] Restore c89 in 0.2.5 --- src/or/control.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/or/control.c b/src/or/control.c index fbd648de9..2ff1cc844 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -4175,12 +4175,12 @@ get_bw_samples(void) int i; int idx = (next_measurement_idx + N_BW_EVENTS_TO_CACHE - n_measurements) % N_BW_EVENTS_TO_CACHE; - tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE); - smartlist_t *elements = smartlist_new(); + tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE); for (i = 0; i < n_measurements; ++i) { tor_assert(0 <= idx && idx < N_BW_EVENTS_TO_CACHE); + { const struct cached_bw_event_s *bwe = &cached_bw_events[idx]; smartlist_add_asprintf(elements, "%u,%u", @@ -4188,14 +4188,17 @@ get_bw_samples(void) (unsigned)bwe->n_written); idx = (idx + 1) % N_BW_EVENTS_TO_CACHE; + } } + { char *result = smartlist_join_strings(elements, " ", 0, NULL); SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp)); smartlist_free(elements); return result; + } } /** Called when we are sending a log message to the controllers: suspend