Tweak #6752 patch based on comments by nickm.

This commit is contained in:
Karsten Loesing 2013-05-24 09:48:15 +02:00
parent 1293835440
commit b0d4ca4990
4 changed files with 50 additions and 114 deletions

View File

@ -243,8 +243,8 @@ smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
return 1; return 1;
} }
/** Return true iff the two lists contain the same ints in the same order, /** Return true iff the two lists contain the same int pointer values in
* or if they are both NULL. */ * the same order, or if they are both NULL. */
int int
smartlist_ints_eq(const smartlist_t *sl1, const smartlist_t *sl2) smartlist_ints_eq(const smartlist_t *sl1, const smartlist_t *sl2)
{ {

View File

@ -2315,8 +2315,9 @@ compute_publishserverdescriptor(or_options_t *options)
* */ * */
#define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT (10) #define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT (10)
/** Return 0 if every setting in <b>options</b> is reasonable, and a /** Return 0 if every setting in <b>options</b> is reasonable, does not
* permissible transition from <b>old_options</b>. Else return -1. * differ from <b>default_options</b> unless in testing Tor networks, and
* is a permissible transition from <b>old_options</b>. Else return -1.
* Should have no side effects, except for normalizing the contents of * Should have no side effects, except for normalizing the contents of
* <b>options</b>. * <b>options</b>.
* *
@ -3211,33 +3212,43 @@ options_validate(or_options_t *old_options, or_options_t *options,
"ignore you."); "ignore you.");
} }
if (default_options->TestingV3AuthInitialVotingInterval != #define CHECK_DEFAULT(arg) \
options->TestingV3AuthInitialVotingInterval && STMT_BEGIN if (default_options->arg != options->arg && \
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) { !options->TestingTorNetwork && \
REJECT("TestingV3AuthInitialVotingInterval may only be changed in testing " !options->UsingTestNetworkDefaults_) { \
"Tor networks!"); REJECT("Testing* options may only be changed in testing Tor " \
} else if (options->TestingV3AuthInitialVotingInterval < MIN_VOTE_INTERVAL) { "networks!"); \
} STMT_END
CHECK_DEFAULT(TestingV3AuthInitialVotingInterval);
CHECK_DEFAULT(TestingV3AuthInitialVoteDelay);
CHECK_DEFAULT(TestingV3AuthInitialDistDelay);
CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability);
CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime);
CHECK_DEFAULT(TestingServerDownloadSchedule);
CHECK_DEFAULT(TestingClientDownloadSchedule);
CHECK_DEFAULT(TestingServerConsensusDownloadSchedule);
CHECK_DEFAULT(TestingClientConsensusDownloadSchedule);
CHECK_DEFAULT(TestingBridgeDownloadSchedule);
CHECK_DEFAULT(TestingClientMaxIntervalWithoutRequest);
CHECK_DEFAULT(TestingDirConnectionMaxStall);
CHECK_DEFAULT(TestingConsensusMaxDownloadTries);
CHECK_DEFAULT(TestingDescriptorMaxDownloadTries);
CHECK_DEFAULT(TestingMicrodescMaxDownloadTries);
CHECK_DEFAULT(TestingCertMaxDownloadTries);
#undef CHECK_DEFAULT
if (options->TestingV3AuthInitialVotingInterval < MIN_VOTE_INTERVAL) {
REJECT("TestingV3AuthInitialVotingInterval is insanely low."); REJECT("TestingV3AuthInitialVotingInterval is insanely low.");
} else if (((30*60) % options->TestingV3AuthInitialVotingInterval) != 0) { } else if (((30*60) % options->TestingV3AuthInitialVotingInterval) != 0) {
REJECT("TestingV3AuthInitialVotingInterval does not divide evenly into " REJECT("TestingV3AuthInitialVotingInterval does not divide evenly into "
"30 minutes."); "30 minutes.");
} }
if (default_options->TestingV3AuthInitialVoteDelay != if (options->TestingV3AuthInitialVoteDelay < MIN_VOTE_SECONDS) {
options->TestingV3AuthInitialVoteDelay &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingV3AuthInitialVoteDelay may only be changed in testing "
"Tor networks!");
} else if (options->TestingV3AuthInitialVoteDelay < MIN_VOTE_SECONDS) {
REJECT("TestingV3AuthInitialVoteDelay is way too low."); REJECT("TestingV3AuthInitialVoteDelay is way too low.");
} }
if (default_options->TestingV3AuthInitialDistDelay != if (options->TestingV3AuthInitialDistDelay < MIN_DIST_SECONDS) {
options->TestingV3AuthInitialDistDelay &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingV3AuthInitialDistDelay may only be changed in testing "
"Tor networks!");
} else if (options->TestingV3AuthInitialDistDelay < MIN_DIST_SECONDS) {
REJECT("TestingV3AuthInitialDistDelay is way too low."); REJECT("TestingV3AuthInitialDistDelay is way too low.");
} }
@ -3248,124 +3259,49 @@ options_validate(or_options_t *old_options, or_options_t *options,
"must be less than half TestingV3AuthInitialVotingInterval"); "must be less than half TestingV3AuthInitialVotingInterval");
} }
if (default_options->TestingAuthDirTimeToLearnReachability != if (options->TestingAuthDirTimeToLearnReachability < 0) {
options->TestingAuthDirTimeToLearnReachability &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingAuthDirTimeToLearnReachability may only be changed in "
"testing Tor networks!");
} else if (options->TestingAuthDirTimeToLearnReachability < 0) {
REJECT("TestingAuthDirTimeToLearnReachability must be non-negative."); REJECT("TestingAuthDirTimeToLearnReachability must be non-negative.");
} else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) { } else if (options->TestingAuthDirTimeToLearnReachability > 2*60*60) {
COMPLAIN("TestingAuthDirTimeToLearnReachability is insanely high."); COMPLAIN("TestingAuthDirTimeToLearnReachability is insanely high.");
} }
if (default_options->TestingEstimatedDescriptorPropagationTime != if (options->TestingEstimatedDescriptorPropagationTime < 0) {
options->TestingEstimatedDescriptorPropagationTime &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingEstimatedDescriptorPropagationTime may only be changed in "
"testing Tor networks!");
} else if (options->TestingEstimatedDescriptorPropagationTime < 0) {
REJECT("TestingEstimatedDescriptorPropagationTime must be non-negative."); REJECT("TestingEstimatedDescriptorPropagationTime must be non-negative.");
} else if (options->TestingEstimatedDescriptorPropagationTime > 60*60) { } else if (options->TestingEstimatedDescriptorPropagationTime > 60*60) {
COMPLAIN("TestingEstimatedDescriptorPropagationTime is insanely high."); COMPLAIN("TestingEstimatedDescriptorPropagationTime is insanely high.");
} }
if (!smartlist_ints_eq(options->TestingServerDownloadSchedule, if (options->TestingClientMaxIntervalWithoutRequest < 1) {
default_options->TestingServerDownloadSchedule) &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingServerDownloadSchedule may only be changed in testing "
"Tor networks!");
}
if (!smartlist_ints_eq(options->TestingClientDownloadSchedule,
default_options->TestingClientDownloadSchedule) &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingClientDownloadSchedule may only be changed in testing "
"Tor networks!");
}
if (!smartlist_ints_eq(options->TestingServerConsensusDownloadSchedule,
default_options->TestingServerConsensusDownloadSchedule) &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingServerConsensusDownloadSchedule may only be changed "
"in testing Tor networks!");
}
if (!smartlist_ints_eq(options->TestingClientConsensusDownloadSchedule,
default_options->TestingClientConsensusDownloadSchedule) &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingClientConsensusDownloadSchedule may only be changed "
"in testing Tor networks!");
}
if (!smartlist_ints_eq(options->TestingBridgeDownloadSchedule,
default_options->TestingBridgeDownloadSchedule) &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingBridgeDownloadSchedule may only be changed in testing "
"Tor networks!");
}
if (default_options->TestingClientMaxIntervalWithoutRequest !=
options->TestingClientMaxIntervalWithoutRequest &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingClientMaxIntervalWithoutRequest may only be changed "
"in testing Tor networks!");
} else if (options->TestingClientMaxIntervalWithoutRequest < 1) {
REJECT("TestingClientMaxIntervalWithoutRequest is way too low."); REJECT("TestingClientMaxIntervalWithoutRequest is way too low.");
} else if (options->TestingClientMaxIntervalWithoutRequest > 3600) { } else if (options->TestingClientMaxIntervalWithoutRequest > 3600) {
COMPLAIN("TestingClientMaxIntervalWithoutRequest is insanely high."); COMPLAIN("TestingClientMaxIntervalWithoutRequest is insanely high.");
} }
if (default_options->TestingDirConnectionMaxStall != if (options->TestingDirConnectionMaxStall < 5) {
options->TestingDirConnectionMaxStall &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingDirConnectionMaxStall may only be changed in testing "
"Tor networks!");
} else if (options->TestingDirConnectionMaxStall < 5) {
REJECT("TestingDirConnectionMaxStall is way too low."); REJECT("TestingDirConnectionMaxStall is way too low.");
} else if (options->TestingDirConnectionMaxStall > 3600) { } else if (options->TestingDirConnectionMaxStall > 3600) {
COMPLAIN("TestingDirConnectionMaxStall is insanely high."); COMPLAIN("TestingDirConnectionMaxStall is insanely high.");
} }
if (default_options->TestingConsensusMaxDownloadTries != if (options->TestingConsensusMaxDownloadTries < 2) {
options->TestingConsensusMaxDownloadTries &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingConsensusMaxDownloadTries may only be changed in "
"testing Tor networks!");
} else if (options->TestingConsensusMaxDownloadTries < 2) {
REJECT("TestingConsensusMaxDownloadTries must be greater than 1."); REJECT("TestingConsensusMaxDownloadTries must be greater than 1.");
} else if (options->TestingConsensusMaxDownloadTries > 800) { } else if (options->TestingConsensusMaxDownloadTries > 800) {
COMPLAIN("TestingConsensusMaxDownloadTries is insanely high."); COMPLAIN("TestingConsensusMaxDownloadTries is insanely high.");
} }
if (default_options->TestingDescriptorMaxDownloadTries != if (options->TestingDescriptorMaxDownloadTries < 2) {
options->TestingDescriptorMaxDownloadTries &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingDescriptorMaxDownloadTries may only be changed in "
"testing Tor networks!");
} else if (options->TestingDescriptorMaxDownloadTries < 2) {
REJECT("TestingDescriptorMaxDownloadTries must be greater than 1."); REJECT("TestingDescriptorMaxDownloadTries must be greater than 1.");
} else if (options->TestingDescriptorMaxDownloadTries > 800) { } else if (options->TestingDescriptorMaxDownloadTries > 800) {
COMPLAIN("TestingDescriptorMaxDownloadTries is insanely high."); COMPLAIN("TestingDescriptorMaxDownloadTries is insanely high.");
} }
if (default_options->TestingMicrodescMaxDownloadTries != if (options->TestingMicrodescMaxDownloadTries < 2) {
options->TestingMicrodescMaxDownloadTries &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingMicrodescMaxDownloadTries may only be changed in "
"testing Tor networks!");
} else if (options->TestingMicrodescMaxDownloadTries < 2) {
REJECT("TestingMicrodescMaxDownloadTries must be greater than 1."); REJECT("TestingMicrodescMaxDownloadTries must be greater than 1.");
} else if (options->TestingMicrodescMaxDownloadTries > 800) { } else if (options->TestingMicrodescMaxDownloadTries > 800) {
COMPLAIN("TestingMicrodescMaxDownloadTries is insanely high."); COMPLAIN("TestingMicrodescMaxDownloadTries is insanely high.");
} }
if (default_options->TestingCertMaxDownloadTries != if (options->TestingCertMaxDownloadTries < 2) {
options->TestingCertMaxDownloadTries &&
!options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) {
REJECT("TestingCertMaxDownloadTries may only be changed in testing "
"Tor networks!");
} else if (options->TestingCertMaxDownloadTries < 2) {
REJECT("TestingCertMaxDownloadTries must be greater than 1."); REJECT("TestingCertMaxDownloadTries must be greater than 1.");
} else if (options->TestingCertMaxDownloadTries > 800) { } else if (options->TestingCertMaxDownloadTries > 800) {
COMPLAIN("TestingCertMaxDownloadTries is insanely high."); COMPLAIN("TestingCertMaxDownloadTries is insanely high.");

View File

@ -588,7 +588,6 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
const void *value; const void *value;
config_line_t *result; config_line_t *result;
smartlist_t *csv_str; smartlist_t *csv_str;
char *s;
tor_assert(options && key); tor_assert(options && key);
CONFIG_CHECK(fmt, options); CONFIG_CHECK(fmt, options);
@ -676,8 +675,7 @@ config_get_assigned_option(const config_format_t *fmt, const void *options,
csv_str = smartlist_new(); csv_str = smartlist_new();
SMARTLIST_FOREACH_BEGIN(*(smartlist_t**)value, int *, i) SMARTLIST_FOREACH_BEGIN(*(smartlist_t**)value, int *, i)
{ {
tor_asprintf(&s, "%d", *i); smartlist_add_asprintf(csv_str, "%d", *i);
smartlist_add(csv_str, s);
} }
SMARTLIST_FOREACH_END(i); SMARTLIST_FOREACH_END(i);
result->value = smartlist_join_strings(csv_str, ",", 0, NULL); result->value = smartlist_join_strings(csv_str, ",", 0, NULL);

View File

@ -3723,10 +3723,12 @@ dir_networkstatus_download_failed(smartlist_t *failed, int status_code)
} SMARTLIST_FOREACH_END(fp); } SMARTLIST_FOREACH_END(fp);
} }
/** Decide which download schedule we want to use, and then return a /** Decide which download schedule we want to use based on descriptor type
* pointer to it along with a pointer to its length. Helper function for * in <b>dls</b> and whether we are acting as directory <b>server</b>, and
* download_status_increment_failure() and download_status_reset(). */ * then return a list of int pointers defining download delays in seconds.
static smartlist_t * * Helper function for download_status_increment_failure() and
* download_status_reset(). */
static const smartlist_t *
find_dl_schedule_and_len(download_status_t *dls, int server) find_dl_schedule_and_len(download_status_t *dls, int server)
{ {
switch (dls->schedule) { switch (dls->schedule) {
@ -3755,7 +3757,7 @@ time_t
download_status_increment_failure(download_status_t *dls, int status_code, download_status_increment_failure(download_status_t *dls, int status_code,
const char *item, int server, time_t now) const char *item, int server, time_t now)
{ {
smartlist_t *schedule; const smartlist_t *schedule;
int increment; int increment;
tor_assert(dls); tor_assert(dls);
if (status_code != 503 || server) { if (status_code != 503 || server) {
@ -3803,7 +3805,7 @@ download_status_increment_failure(download_status_t *dls, int status_code,
void void
download_status_reset(download_status_t *dls) download_status_reset(download_status_t *dls)
{ {
smartlist_t *schedule = find_dl_schedule_and_len( const smartlist_t *schedule = find_dl_schedule_and_len(
dls, get_options()->DirPort_set); dls, get_options()->DirPort_set);
dls->n_download_failures = 0; dls->n_download_failures = 0;