From 0a3da5ce79768c15da3897097f0cc7ba727a7d35 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 13 Sep 2016 11:02:44 -0400 Subject: [PATCH] prop264: sometimes check client _and_ server versions. As before, we check server protocols whenever server_mode(options) is true and we check client protocols whenever server_mode(options) is false. Additionally, we now _also_ check client protocols whenever any client port is set. --- src/or/networkstatus.c | 52 +++++++++++++++++++++++++++++++++++++++++++------- src/or/networkstatus.h | 3 --- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 0fc22c9aa3..3299a2c048 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -125,6 +125,9 @@ static void routerstatus_list_update_named_server_map(void); static void update_consensus_bootstrap_multiple_downloads( time_t now, const or_options_t *options); +static int networkstatus_check_required_protocols(const networkstatus_t *ns, + int client_mode, + char **warning_out); /** Forget that we've warned about anything networkstatus-related, so we will * give fresh warnings if the same behavior happens again. */ @@ -1553,17 +1556,35 @@ networkstatus_set_current_consensus_from_ns(networkstatus_t *c, } #endif //TOR_UNIT_TESTS -/** Called when we have received a networkstatus c. If there are - * any _required_ protocols we are missing, log an error and exit - * immediately. If there are any _recommended_ protocols we are missing, - * warn. */ +/** + * Return true if any option is set in options to make us behave + * as a client. + * + * XXXX If we need this elsewhere at any point, we should make it nonstatic + * XXXX and move it into another file. + */ +static int +any_client_port_set(const or_options_t *options) +{ + return (options->SocksPort_set || + options->TransPort_set || + options->NATDPort_set || + options->ControlPort_set || + options->DNSPort_set); +} + +/** + * Helper for handle_missing_protocol_warning: handles either the + * client case (if is_client is set) or the server case otherwise. + */ static void -handle_missing_protocol_warning(const networkstatus_t *c, - const or_options_t *options) +handle_missing_protocol_warning_impl(const networkstatus_t *c, + int is_client) { char *protocol_warning = NULL; + int should_exit = networkstatus_check_required_protocols(c, - !server_mode(options), + is_client, &protocol_warning); if (protocol_warning) { tor_log(should_exit ? LOG_ERR : LOG_WARN, @@ -1578,6 +1599,23 @@ handle_missing_protocol_warning(const networkstatus_t *c, exit(1); } +/** Called when we have received a networkstatus c. If there are + * any _required_ protocols we are missing, log an error and exit + * immediately. If there are any _recommended_ protocols we are missing, + * warn. */ +static void +handle_missing_protocol_warning(const networkstatus_t *c, + const or_options_t *options) +{ + const int is_server = server_mode(options); + const int is_client = any_client_port_set(options) || !is_server; + + if (is_server) + handle_missing_protocol_warning_impl(c, 0); + if (is_client) + handle_missing_protocol_warning_impl(c, 1); +} + /** Try to replace the current cached v3 networkstatus with the one in * consensus. If we don't have enough certificates to validate it, * store it in consensus_waiting_for_certs and launch a certificate fetch. diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h index da175ecca9..71f36b69ed 100644 --- a/src/or/networkstatus.h +++ b/src/or/networkstatus.h @@ -122,9 +122,6 @@ void document_signature_free(document_signature_t *sig); document_signature_t *document_signature_dup(const document_signature_t *sig); void networkstatus_free_all(void); int networkstatus_get_weight_scale_param(networkstatus_t *ns); -int networkstatus_check_required_protocols(const networkstatus_t *ns, - int client_mode, - char **warning_out); #ifdef NETWORKSTATUS_PRIVATE STATIC void vote_routerstatus_free(vote_routerstatus_t *rs); -- 2.11.4.GIT