From 3c12133038f5a9213b13beca50d91ddac2f9d7fb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 15 Nov 2016 08:28:41 -0500 Subject: Collect old guard algorithm parameters into one place --- src/or/networkstatus.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/or/networkstatus.h') diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h index 71f36b69ed..96f8347584 100644 --- a/src/or/networkstatus.h +++ b/src/or/networkstatus.h @@ -107,6 +107,10 @@ void signed_descs_update_status_from_consensus_networkstatus( char *networkstatus_getinfo_helper_single(const routerstatus_t *rs); char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now); void networkstatus_dump_bridge_status_to_file(time_t now); +int32_t networkstatus_get_param(const networkstatus_t *ns, + const char *param_name, + int32_t default_val, int32_t min_val, + int32_t max_val); int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, -- cgit v1.2.3-54-g00ecf From 6a02f9f35a824ced871de7bb80c8266b873a0710 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 15 Nov 2016 08:38:33 -0500 Subject: Add parameters for new (prop271) guard algorithm. These are taken from the proposal, and defined there. Some of them should turn into consensus parameters. Also, remove some dead code that was there to make compilation work, and use ATTR_UNUSED like a normal person. --- src/or/entrynodes.c | 34 ++++++++++++++++++++++++---------- src/or/networkstatus.h | 4 ---- 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src/or/networkstatus.h') diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c index 461d29f8e9..c6ed59ddce 100644 --- a/src/or/entrynodes.c +++ b/src/or/entrynodes.c @@ -151,6 +151,26 @@ should_apply_guardfraction(const networkstatus_t *ns) } /**@}*/ +/** + * @name Parameters for new (prop271) entry guard algorithm. + */ +/* XXXX prop271 some of these should be networkstatus parameters */ +#define MIN_SAMPLE_THRESHOLD 15 +#define MAX_SAMPLE_THRESHOLD 50 +#define GUARD_LIFETIME_DAYS 120 +#define REMOVE_UNLISTED_GUARDS_AFTER_DAYS 20 +#define MIN_FILTERED_SAMPLE_SIZE 20 +#define N_PRIMARY_GUARDS 3 +#define PRIMARY_GUARDS_RETRY_SCHEDULE /* XXX prop271 */ +#define OTHER_GUARDS_RETRY_SCHEDULE /* XXX prop271 */ +#define INTERNET_LIKELY_DOWN_INTERVAL (10*60) +#define NONPRIMARY_GUARD_CONNECT_TIMEOUT 15 +#define NONPRIMARY_GUARD_IDLE_TIMEOUT (10*60) +#define MEANINGFUL_RESTRICTION_FRAC 0.2 +#define EXTREME_RESTRICTION_FRAC 0.01 +#define GUARD_CONFIRMED_MIN_LIFETIME_DAYS 60 +/**}@*/ + /** Allocate a new guard_selection_t */ static guard_selection_t * @@ -254,12 +274,11 @@ randomize_time(time_t now, time_t max_backdate) /** * DOCDOC */ -STATIC void +ATTR_UNUSED STATIC void entry_guard_add_to_sample(guard_selection_t *gs, node_t *node) { - (void) entry_guard_add_to_sample; // XXXX prop271 remove -- unused - const int GUARD_LIFETIME = 90 * 86400; // xxxx prop271 + const int GUARD_LIFETIME = GUARD_LIFETIME_DAYS * 86400; tor_assert(gs); tor_assert(node); @@ -296,7 +315,7 @@ entry_guard_add_to_sample(guard_selection_t *gs, * Return a newly allocated string for encoding the persistent parts of * guard to the state file. */ -STATIC char * +ATTR_UNUSED STATIC char * entry_guard_encode_for_state(entry_guard_t *guard) { /* @@ -356,7 +375,7 @@ entry_guard_encode_for_state(entry_guard_t *guard) * (if possible) and return an entry_guard_t object for it. Return NULL * on complete failure. */ -STATIC entry_guard_t * +ATTR_UNUSED STATIC entry_guard_t * entry_guard_parse_from_state(const char *s) { /* Unrecognized entries get put in here. */ @@ -1776,9 +1795,6 @@ entry_guards_parse_state_for_guard_selection( const char *state_version = state->TorVersion; digestmap_t *added_by = digestmap_new(); - if (0) entry_guard_parse_from_state(NULL); // XXXX prop271 remove -- unused - if (0) entry_guard_add_to_sample(NULL, NULL); // XXXX prop271 remove - tor_assert(gs != NULL); *msg = NULL; @@ -2104,8 +2120,6 @@ entry_guards_update_state(or_state_t *state) config_line_t **next, *line; guard_selection_t *gs = get_guard_selection_info(); - if (0) entry_guard_encode_for_state(NULL); // XXXX prop271 remove -- unused - tor_assert(gs != NULL); tor_assert(gs->chosen_entry_guards != NULL); diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h index 96f8347584..71f36b69ed 100644 --- a/src/or/networkstatus.h +++ b/src/or/networkstatus.h @@ -107,10 +107,6 @@ void signed_descs_update_status_from_consensus_networkstatus( char *networkstatus_getinfo_helper_single(const routerstatus_t *rs); char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now); void networkstatus_dump_bridge_status_to_file(time_t now); -int32_t networkstatus_get_param(const networkstatus_t *ns, - const char *param_name, - int32_t default_val, int32_t min_val, - int32_t max_val); int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, -- cgit v1.2.3-54-g00ecf From 039bd01767d42961cb16ff4914481332b52cf8db Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 26 Nov 2016 09:22:04 -0500 Subject: Add a wrapper for a common networkstatus param pattern We frequently want to check a networkstatus parameter only when it isn't overridden from the torrc file. --- src/or/networkstatus.c | 19 +++++++++++++++++++ src/or/networkstatus.h | 5 +++++ src/test/test_dir.c | 9 +++++++++ 3 files changed, 33 insertions(+) (limited to 'src/or/networkstatus.h') diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index ec8f77fa42..ce23d67979 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -2303,6 +2303,25 @@ networkstatus_get_param(const networkstatus_t *ns, const char *param_name, default_val, min_val, max_val); } +/** + * As networkstatus_get_param(), but check torrc_value before checking the + * consensus. If torrc_value is in-range, then return it instead of the + * value from the consensus. + */ +int32_t +networkstatus_get_overridable_param(const networkstatus_t *ns, + int32_t torrc_value, + const char *param_name, + int32_t default_val, + int32_t min_val, int32_t max_val) +{ + if (torrc_value >= min_val && torrc_value <= max_val) + return torrc_value; + else + return networkstatus_get_param( + ns, param_name, default_val, min_val, max_val); +} + /** * Retrieve the consensus parameter that governs the * fixed-point precision of our network balancing 'bandwidth-weights' diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h index 71f36b69ed..4b3854db0c 100644 --- a/src/or/networkstatus.h +++ b/src/or/networkstatus.h @@ -111,6 +111,11 @@ int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val); +int32_t networkstatus_get_overridable_param(const networkstatus_t *ns, + int32_t torrc_value, + const char *param_name, + int32_t default_val, + int32_t min_val, int32_t max_val); int getinfo_helper_networkstatus(control_connection_t *conn, const char *question, char **answer, const char **errmsg); diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 4501d6b547..4ef421f8e3 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -1494,6 +1494,15 @@ test_dir_param_voting(void *arg) tt_int_op(-8,OP_EQ, networkstatus_get_param(&vote4, "ab", -12, -100, -8)); tt_int_op(0,OP_EQ, networkstatus_get_param(&vote4, "foobar", 0, -100, 8)); + tt_int_op(100,OP_EQ, networkstatus_get_overridable_param( + &vote4, -1, "x-yz", 50, 0, 300)); + tt_int_op(30,OP_EQ, networkstatus_get_overridable_param( + &vote4, 30, "x-yz", 50, 0, 300)); + tt_int_op(0,OP_EQ, networkstatus_get_overridable_param( + &vote4, -101, "foobar", 0, -100, 8)); + tt_int_op(-99,OP_EQ, networkstatus_get_overridable_param( + &vote4, -99, "foobar", 0, -100, 8)); + smartlist_add(votes, &vote1); /* Do the first tests without adding all the other votes, for -- cgit v1.2.3-54-g00ecf