[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Restore semantics of advertise vs serve on directory cacheing



commit 0c8e042c30946faa564f03251bb3663e6204df9a
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Nov 11 13:34:05 2015 -0500

    Restore semantics of advertise vs serve on directory cacheing
    
    When we are low on accounted bandwidth, we stop advertising that
    we're a directory, but we will continue to answer directory
    requests, just as before.
---
 src/or/router.c |   30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/or/router.c b/src/or/router.c
index 5c680ce..c1d970d 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1099,11 +1099,26 @@ check_whether_dirport_reachable(void)
          can_reach_dir_port;
 }
 
-/** The lower threshold of remaining bandwidth required to advertise directory
- * services */
+/** The lower threshold of remaining bandwidth required to advertise (or
+ * automatically provide) directory services */
 /* XXX Should this be increased? */
 #define MIN_BW_TO_ADVERTISE_DIRSERVER 51200
 
+/** Return true iff we have enough configured bandwidth to cache directory
+ * information. */
+static int
+router_has_bandwidth_to_be_dirserver(const or_options_t *options)
+{
+  if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
+    return 0;
+  }
+  if (options->RelayBandwidthRate > 0 &&
+      options->RelayBandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
+    return 0;
+  }
+  return 1;
+}
+
 /** Helper: Return 1 if we have sufficient resources for serving directory
  * requests, return 0 otherwise.
  * dir_port is either 0 or the configured DirPort number.
@@ -1144,9 +1159,7 @@ router_should_be_directory_server(const or_options_t *options, int dir_port)
       new_choice = 0;
       reason = "AccountingMax enabled";
     }
-  } else if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER ||
-             (options->RelayBandwidthRate > 0 &&
-              options->RelayBandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER)) {
+  } else if (! router_has_bandwidth_to_be_dirserver(options)) {
     /* if we're advertising a small amount */
     new_choice = 0;
     reason = "BandwidthRate under 50KB";
@@ -1178,8 +1191,8 @@ dir_server_mode(const or_options_t *options)
 {
   if (!options->DirCache)
     return 0;
-  return (server_mode(options) || options->DirPort_set) &&
-          router_should_be_directory_server(options, 0);
+  return options->DirPort_set ||
+    (server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
 }
 
 /** Look at a variety of factors, and return 0 if we don't want to
@@ -1899,7 +1912,8 @@ router_build_fresh_descriptor(routerinfo_t **r, extrainfo_t **e)
   ri->addr = addr;
   ri->or_port = router_get_advertised_or_port(options);
   ri->dir_port = router_get_advertised_dir_port(options, 0);
-  ri->supports_tunnelled_dir_requests = dir_server_mode(options);
+  ri->supports_tunnelled_dir_requests = dir_server_mode(options) &&
+    router_should_be_directory_server(options, ri->dir_port);
   ri->cache_info.published_on = time(NULL);
   ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from
                                                         * main thread */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits