Commit fd18d512 authored by teor's avatar teor
Browse files

dirauth: Refactor some code and tests

Minor simplification and refactoring.

Make the dirauth tests focus on testing the intention of the code,
rather than option processing order.

Part of 32213.
parent d6654580
Loading
Loading
Loading
Loading
+87 −74
Original line number Diff line number Diff line
@@ -61,7 +61,9 @@ options_validate_dirauth_mode(const or_options_t *old_options,
  if (BUG(!msg))
    return -1;

  if (options->AuthoritativeDir) {
  if (!authdir_mode(options))
    return 0;

  /* confirm that our address isn't broken, so we can complain now */
  uint32_t tmp;
  if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL) < 0)
@@ -121,10 +123,7 @@ options_validate_dirauth_mode(const or_options_t *old_options,

  if (options->ClientOnly)
    REJECT("Running as authoritative directory, but ClientOnly also set.");
  }

  /* 31851: the tests expect us to validate these options, even when we are
   * not in authority mode. */
  if (options->MinUptimeHidServDirectoryV2 < 0) {
    log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at "
             "least 0 seconds. Changing to 0.");
@@ -154,8 +153,9 @@ options_validate_dirauth_bandwidth(const or_options_t *old_options,
  if (BUG(!msg))
    return -1;

  /* 31851: the tests expect us to validate these options, even when we are
   * not in authority mode. */
  if (!authdir_mode(options))
    return 0;

  if (ensure_bandwidth_cap(&options->AuthDirFastGuarantee,
                           "AuthDirFastGuarantee", msg) < 0)
    return -1;
@@ -186,6 +186,9 @@ options_validate_dirauth_schedule(const or_options_t *old_options,
  if (BUG(!msg))
    return -1;

  if (!authdir_mode_v3(options))
    return 0;

  if (options->V3AuthVoteDelay + options->V3AuthDistDelay >=
      options->V3AuthVotingInterval/2) {
    REJECT("V3AuthVoteDelay plus V3AuthDistDelay must be less than half "
@@ -224,7 +227,8 @@ options_validate_dirauth_schedule(const or_options_t *old_options,
  if (options->V3AuthVotingInterval < MIN_VOTE_INTERVAL) {
    if (options->TestingTorNetwork) {
      if (options->V3AuthVotingInterval < MIN_VOTE_INTERVAL_TESTING) {
        REJECT("V3AuthVotingInterval is insanely low.");
        /* Unreachable, covered by earlier checks */
        REJECT("V3AuthVotingInterval is insanely low."); /* LCOV_EXCL_LINE */
      } else {
        COMPLAIN("V3AuthVotingInterval is very low. "
                 "This may lead to failure to synchronise for a consensus.");
@@ -261,6 +265,18 @@ options_validate_dirauth_testing(const or_options_t *old_options,
  if (BUG(!msg))
    return -1;

  if (!authdir_mode(options))
    return 0;

  if (options->TestingAuthDirTimeToLearnReachability < 0) {
    REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
  } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {
    COMPLAIN("TestingAuthDirTimeToLearnReachability is insanely high.");
  }

  if (!authdir_mode_v3(options))
    return 0;

  if (options->TestingV3AuthInitialVotingInterval
      < MIN_VOTE_INTERVAL_TESTING_INITIAL) {
    REJECT("TestingV3AuthInitialVotingInterval is insanely low.");
@@ -293,12 +309,6 @@ options_validate_dirauth_testing(const or_options_t *old_options,
    REJECT("TestingV3AuthVotingStartOffset must be non-negative.");
  }

  if (options->TestingAuthDirTimeToLearnReachability < 0) {
    REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
  } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {
    COMPLAIN("TestingAuthDirTimeToLearnReachability is insanely high.");
  }

  return 0;
}

@@ -317,6 +327,7 @@ options_transition_affects_dirauth_timing(const or_options_t *old_options,
    return 1;
  if (! authdir_mode_v3(new_options))
    return 0;

  YES_IF_CHANGED_INT(V3AuthVotingInterval);
  YES_IF_CHANGED_INT(V3AuthVoteDelay);
  YES_IF_CHANGED_INT(V3AuthDistDelay);
@@ -374,6 +385,9 @@ options_act_dirauth_mtbf(const or_options_t *old_options)
  const or_options_t *options = get_options();
  int running_tor = options->command == CMD_RUN_TOR;

  if (!authdir_mode(options))
    return 0;

  /* Load dirauth state */
  if (running_tor) {
    rep_hist_load_mtbf_data(time(NULL));
@@ -404,12 +418,11 @@ options_act_dirauth_stats(const or_options_t *old_options,

  const or_options_t *options = get_options();

  if (options->BridgeAuthoritativeDir) {
  if (authdir_mode_bridge(options)) {
    time_t now = time(NULL);
    int print_notice = 0;

    if ((!old_options || !old_options->BridgeAuthoritativeDir) &&
        options->BridgeAuthoritativeDir) {
    if (!old_options || !authdir_mode_bridge(old_options)) {
      rep_hist_desc_stats_init(now);
      print_notice = 1;
    }
@@ -419,8 +432,8 @@ options_act_dirauth_stats(const or_options_t *old_options,

  /* If we used to have statistics enabled but we just disabled them,
     stop gathering them.  */
  if (old_options && old_options->BridgeAuthoritativeDir &&
      !options->BridgeAuthoritativeDir)
  if (old_options && authdir_mode_bridge(old_options) &&
      !authdir_mode_bridge(options))
    rep_hist_desc_stats_term();

  return 0;
+0 −4
Original line number Diff line number Diff line
@@ -67,19 +67,15 @@ options_validate_dirauth_mode(const or_options_t *old_options,

#define options_validate_dirauth_bandwidth(old_options, options, msg) \
  (((void)(old_options)),((void)(options)),((void)(msg)),0)

#define options_validate_dirauth_schedule(old_options, options, msg) \
  (((void)(old_options)),((void)(options)),((void)(msg)),0)

#define options_validate_dirauth_testing(old_options, options, msg) \
  (((void)(old_options)),((void)(options)),((void)(msg)),0)

#define options_validate_dirauth_testing(old_options, options, msg) \
  (((void)(old_options)),((void)(options)),((void)(msg)),0)

#define options_act_dirauth(old_options) \
  (((void)(old_options)),0)

#define options_act_dirauth_mtbf(old_options) \
  (((void)(old_options)),0)

+314 −161

File changed.

Preview size limit exceeded, changes collapsed.