From 8da24c99bdb90b04a05d5bccf5bcff1218174b75 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 15 Nov 2016 07:49:06 -0500 Subject: Split bridge functions into a new module. This patch is just: * Code movement * Adding headers here and there as needed * Adding a bridges_free_all() with a call to it. It breaks compilation, since the bridge code needed to make exactly 2 calls into entrynodes.c internals. I'll fix those in the next commit. --- src/or/networkstatus.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/or/networkstatus.c') diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 316ce48387..ec8f77fa42 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -38,6 +38,7 @@ #define NETWORKSTATUS_PRIVATE #include "or.h" +#include "bridges.h" #include "channel.h" #include "circuitmux.h" #include "circuitmux_ewma.h" -- 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.c') 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