[tor-commits] [tor/master] prop264: sometimes check client _and_ server versions.

nickm at torproject.org nickm at torproject.org
Mon Sep 26 18:03:40 UTC 2016


commit 0a3da5ce79768c15da3897097f0cc7ba727a7d35
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Sep 13 11:02:44 2016 -0400

    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 0fc22c9..3299a2c 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 <b>c</b>. 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 <b>options</b> 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 <b>is_client</b> 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 <b>c</b>. 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
  * <b>consensus</b>.  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 da175ec..71f36b6 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);





More information about the tor-commits mailing list