[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Merge branch 'maint-0.2.9' into maint-0.3.3



commit cbe04d455016233f4759fe281c07dd7db6096c2a
Merge: aebe8a82c 8569166c7
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Nov 15 16:54:16 2018 -0500

    Merge branch 'maint-0.2.9' into maint-0.3.3

 changes/bug24104            |   4 ++
 src/or/rephist.c            |   7 ++-
 src/or/rephist.h            |   5 +-
 src/or/router.c             |  25 +++++++--
 src/test/log_test_helpers.c |  23 +++++++-
 src/test/log_test_helpers.h |   8 ++-
 src/test/test_router.c      | 124 +++++++++++++++++++++++++++++++++++++++++++-
 7 files changed, 179 insertions(+), 17 deletions(-)

diff --cc src/or/rephist.c
index 43494692c,2844c4d74..67e4d3150
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@@ -3205,4 -3292,4 +3205,3 @@@ rep_hist_free_all(void
    tor_assert_nonfatal(rephist_total_alloc == 0);
    tor_assert_nonfatal_once(rephist_total_num == 0);
  }
--
diff --cc src/or/rephist.h
index 507272159,6d35ac67f..3e64a3de4
--- a/src/or/rephist.h
+++ b/src/or/rephist.h
@@@ -111,30 -119,5 +111,29 @@@ extern int onion_handshakes_requested[M
  extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1];
  #endif
  
 -#endif
 -
 +/**
 + * Represents the type of a cell for padding accounting
 + */
 +typedef enum padding_type_t {
 +    /** A RELAY_DROP cell */
 +    PADDING_TYPE_DROP,
 +    /** A CELL_PADDING cell */
 +    PADDING_TYPE_CELL,
 +    /** Total counts of padding and non-padding together */
 +    PADDING_TYPE_TOTAL,
 +    /** Total cell counts for all padding-enabled channels */
 +    PADDING_TYPE_ENABLED_TOTAL,
 +    /** CELL_PADDING counts for all padding-enabled channels */
 +    PADDING_TYPE_ENABLED_CELL
 +} padding_type_t;
 +
 +/** The amount of time over which the padding cell counts were counted */
 +#define REPHIST_CELL_PADDING_COUNTS_INTERVAL (24*60*60)
 +void rep_hist_padding_count_read(padding_type_t type);
 +void rep_hist_padding_count_write(padding_type_t type);
 +char *rep_hist_get_padding_count_lines(void);
 +void rep_hist_reset_padding_counts(void);
 +void rep_hist_prep_published_padding_counts(time_t now);
 +void rep_hist_padding_count_timers(uint64_t num_timers);
 +
 +#endif /* !defined(TOR_REPHIST_H) */
- 
diff --cc src/test/log_test_helpers.c
index d5a39cfee,c5368b6cb..1ad01afc8
--- a/src/test/log_test_helpers.c
+++ b/src/test/log_test_helpers.c
@@@ -238,4 -258,4 +258,3 @@@ mock_dump_saved_logs(void
             escaped(m->generated_msg));
    } SMARTLIST_FOREACH_END(m);
  }
--
diff --cc src/test/log_test_helpers.h
index 70c584eb3,a087b913f..f74028a8a
--- a/src/test/log_test_helpers.h
+++ b/src/test/log_test_helpers.h
@@@ -101,5 -106,5 +106,4 @@@ void mock_dump_saved_logs(void)
    assert_log_predicate(!mock_saved_log_has_entry(), \
                  "expected log to not contain entries");
  
 -#endif
 -
 +#endif /* !defined(TOR_LOG_TEST_HELPERS_H) */
- 
diff --cc src/test/test_router.c
index 4e96e2453,51055a336..84473822a
--- a/src/test/test_router.c
+++ b/src/test/test_router.c
@@@ -8,105 -7,136 +8,227 @@@
   **/
  
  #include "or.h"
 +#include "config.h"
 +#include "crypto_curve25519.h"
 +#include "crypto_ed25519.h"
+ #include "hibernate.h"
 -#include "log_test_helpers.h"
+ #include "main.h"
+ #include "rephist.h"
  #include "router.h"
 +#include "routerlist.h"
 +
 +/* Test suite stuff */
  #include "test.h"
++#include "log_test_helpers.h"
 +
 +NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
 +
 +static routerinfo_t* mock_routerinfo;
 +
 +static const routerinfo_t*
 +NS(router_get_my_routerinfo)(void)
 +{
 +  crypto_pk_t* ident_key;
 +  crypto_pk_t* tap_key;
 +  time_t now;
 +
 +  if (!mock_routerinfo) {
 +    /* Mock the published timestamp, otherwise router_dump_router_to_string()
 +     * will poop its pants. */
 +    time(&now);
 +
 +    /* We'll need keys, or router_dump_router_to_string() would return NULL. */
 +    ident_key = pk_generate(0);
 +    tap_key = pk_generate(0);
 +
 +    tor_assert(ident_key != NULL);
 +    tor_assert(tap_key != NULL);
 +
 +    mock_routerinfo = tor_malloc_zero(sizeof(routerinfo_t));
 +    mock_routerinfo->nickname = tor_strdup("ConlonNancarrow");
 +    mock_routerinfo->addr = 123456789;
 +    mock_routerinfo->or_port = 443;
 +    mock_routerinfo->platform = tor_strdup("unittest");
 +    mock_routerinfo->cache_info.published_on = now;
 +    mock_routerinfo->identity_pkey = crypto_pk_dup_key(ident_key);
 +    mock_routerinfo->onion_pkey = crypto_pk_dup_key(tap_key);
 +    mock_routerinfo->bandwidthrate = 9001;
 +    mock_routerinfo->bandwidthburst = 9002;
 +  }
 +
 +  return mock_routerinfo;
 +}
 +
 +/* If no distribution option was set, then check_bridge_distribution_setting()
 + * should have set it to "any". */
 +static void
 +test_router_dump_router_to_string_no_bridge_distribution_method(void *arg)
 +{
 +  const char* needle = "bridge-distribution-request any";
 +  or_options_t* options = get_options_mutable();
 +  routerinfo_t* router = NULL;
 +  curve25519_keypair_t ntor_keypair;
 +  ed25519_keypair_t signing_keypair;
 +  char* desc = NULL;
 +  char* found = NULL;
 +  (void)arg;
 +
 +  NS_MOCK(router_get_my_routerinfo);
 +
 +  options->ORPort_set = 1;
 +  options->BridgeRelay = 1;
 +
 +  /* Generate keys which router_dump_router_to_string() expects to exist. */
 +  tt_int_op(0, ==, curve25519_keypair_generate(&ntor_keypair, 0));
 +  tt_int_op(0, ==, ed25519_keypair_generate(&signing_keypair, 0));
 +
 +  /* Set up part of our routerinfo_t so that we don't trigger any other
 +   * assertions in router_dump_router_to_string(). */
 +  router = (routerinfo_t*)router_get_my_routerinfo();
 +  tt_ptr_op(router, !=, NULL);
 +
 +  router->onion_curve25519_pkey = &ntor_keypair.pubkey;
 +
 +  /* Generate our server descriptor and ensure that the substring
 +   * "bridge-distribution-request any" occurs somewhere within it. */
 +  desc = router_dump_router_to_string(router,
 +                                      router->identity_pkey,
 +                                      router->onion_pkey,
 +                                      &ntor_keypair,
 +                                      &signing_keypair);
 +  tt_ptr_op(desc, !=, NULL);
 +  found = strstr(desc, needle);
 +  tt_ptr_op(found, !=, NULL);
 +
 + done:
 +  NS_UNMOCK(router_get_my_routerinfo);
 +
 +  tor_free(desc);
 +}
  
+ static routerinfo_t *mock_router_get_my_routerinfo_result = NULL;
+ 
+ static const routerinfo_t *
+ mock_router_get_my_routerinfo(void)
+ {
+   return mock_router_get_my_routerinfo_result;
+ }
+ 
+ static long
+ mock_get_uptime_3h(void)
+ {
+   return 3*60*60;
+ }
+ 
+ static long
+ mock_get_uptime_1d(void)
+ {
+   return 24*60*60;
+ }
+ 
+ static int
+ mock_rep_hist_bandwidth_assess(void)
+ {
+   return 20001;
+ }
+ 
+ static int
+ mock_we_are_not_hibernating(void)
+ {
+   return 0;
+ }
+ 
+ static int
+ mock_we_are_hibernating(void)
+ {
+   return 0;
+ }
+ 
+ static void
+ test_router_check_descriptor_bandwidth_changed(void *arg)
+ {
+   (void)arg;
+   routerinfo_t routerinfo;
+   memset(&routerinfo, 0, sizeof(routerinfo));
+   mock_router_get_my_routerinfo_result = NULL;
+ 
+   MOCK(we_are_hibernating, mock_we_are_not_hibernating);
+   MOCK(router_get_my_routerinfo, mock_router_get_my_routerinfo);
+   mock_router_get_my_routerinfo_result = &routerinfo;
+ 
+   /* When uptime is less than 24h, no previous bandwidth, no last_changed
+    * Uptime: 10800, last_changed: 0, Previous bw: 0, Current bw: 0 */
+   routerinfo.bandwidthcapacity = 0;
+   MOCK(get_uptime, mock_get_uptime_3h);
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL));
+   expect_log_msg_not_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   teardown_capture_of_logs();
+ 
+   /* When uptime is less than 24h, previous bandwidth,
+    * last_changed more than 3h ago
+    * Uptime: 10800, last_changed: 0, Previous bw: 10000, Current bw: 0 */
+   routerinfo.bandwidthcapacity = 10000;
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL));
+   expect_log_msg_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   teardown_capture_of_logs();
+ 
+   /* When uptime is less than 24h, previous bandwidth,
+    * last_changed more than 3h ago, and hibernating
+    * Uptime: 10800, last_changed: 0, Previous bw: 10000, Current bw: 0 */
+ 
+   UNMOCK(we_are_hibernating);
+   MOCK(we_are_hibernating, mock_we_are_hibernating);
+   routerinfo.bandwidthcapacity = 10000;
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL));
+   expect_log_msg_not_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   teardown_capture_of_logs();
+   UNMOCK(we_are_hibernating);
+   MOCK(we_are_hibernating, mock_we_are_not_hibernating);
+ 
+   /* When uptime is less than 24h, last_changed is not more than 3h ago
+    * Uptime: 10800, last_changed: x, Previous bw: 10000, Current bw: 0 */
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL));
+   expect_log_msg_not_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   teardown_capture_of_logs();
+ 
+   /* When uptime is less than 24h and bandwidthcapacity does not change
+    * Uptime: 10800, last_changed: x, Previous bw: 10000, Current bw: 20001 */
+   MOCK(rep_hist_bandwidth_assess, mock_rep_hist_bandwidth_assess);
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL) + 6*60*60 + 1);
+   expect_log_msg_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   UNMOCK(get_uptime);
+   UNMOCK(rep_hist_bandwidth_assess);
+   teardown_capture_of_logs();
+ 
+   /* When uptime is more than 24h */
+   MOCK(get_uptime, mock_get_uptime_1d);
+   setup_full_capture_of_logs(LOG_INFO);
+   check_descriptor_bandwidth_changed(time(NULL));
+   expect_log_msg_not_containing(
+      "Measured bandwidth has changed; rebuilding descriptor.");
+   teardown_capture_of_logs();
+ 
+  done:
+   UNMOCK(get_uptime);
+   UNMOCK(router_get_my_routerinfo);
+   UNMOCK(we_are_hibernating);
+ }
+ 
  #define ROUTER_TEST(name, flags)                          \
    { #name, test_router_ ## name, flags, NULL, NULL }
  
  struct testcase_t router_tests[] = {
 +  ROUTER_TEST(dump_router_to_string_no_bridge_distribution_method, TT_FORK),
+   ROUTER_TEST(check_descriptor_bandwidth_changed, TT_FORK),
    END_OF_TESTCASES
  };
--



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits