Browse Source

never refuse directory requests from local addresses

svn:r9421
Roger Dingledine 19 years ago
parent
commit
99c1771432
4 changed files with 12 additions and 8 deletions
  1. 1 0
      ChangeLog
  2. 6 3
      src/or/connection.c
  3. 4 4
      src/or/directory.c
  4. 1 1
      src/or/or.h

+ 1 - 0
ChangeLog

@@ -3,6 +3,7 @@ Changes in version 0.1.2.7-alpha - 2007-01-26
     - Servers decline directory requests much more aggressively when
     - Servers decline directory requests much more aggressively when
       they're low on bandwidth. Otherwise they end up queueing more and
       they're low on bandwidth. Otherwise they end up queueing more and
       more directory responses, which can't be good for latency.
       more directory responses, which can't be good for latency.
+    - But never refuse directory requests from local addresses.
     - Be willing to read or write on local connections (e.g. controller
     - Be willing to read or write on local connections (e.g. controller
       connections) even when the global rate limiting buckets are empty.
       connections) even when the global rate limiting buckets are empty.
     - If our system clock jumps back in time, don't publish a negative
     - If our system clock jumps back in time, don't publish a negative

+ 6 - 3
src/or/connection.c

@@ -1175,8 +1175,8 @@ connection_bucket_write_limit(connection_t *conn)
 }
 }
 
 
 /** Return 1 if the global write bucket is low enough that we shouldn't
 /** Return 1 if the global write bucket is low enough that we shouldn't
- * send <b>attempt</b> bytes of low-priority directory stuff out.
- * Else return 0.
+ * send <b>attempt</b> bytes of low-priority directory stuff out to
+ * <b>conn</b>. Else return 0.
 
 
  * Priority is 1 for v1 requests (directories and running-routers),
  * Priority is 1 for v1 requests (directories and running-routers),
  * and 2 for v2 requests (statuses and descriptors). But see FFFF in
  * and 2 for v2 requests (statuses and descriptors). But see FFFF in
@@ -1194,11 +1194,14 @@ connection_bucket_write_limit(connection_t *conn)
  *   that's harder to quantify and harder to keep track of.
  *   that's harder to quantify and harder to keep track of.
  */
  */
 int
 int
-global_write_bucket_low(size_t attempt, int priority)
+global_write_bucket_low(connection_t *conn, size_t attempt, int priority)
 {
 {
   if (authdir_mode(get_options()) && priority>1)
   if (authdir_mode(get_options()) && priority>1)
     return 0; /* there's always room to answer v2 if we're an auth dir */
     return 0; /* there's always room to answer v2 if we're an auth dir */
 
 
+  if (is_internal_IP(conn->addr, 0))
+    return 0; /* local conns don't get limited */
+
   if (global_write_bucket < (int)attempt)
   if (global_write_bucket < (int)attempt)
     return 1; /* not enough space no matter the priority */
     return 1; /* not enough space no matter the priority */
 
 

+ 4 - 4
src/or/directory.c

@@ -1603,7 +1603,7 @@ directory_handle_command_get(dir_connection_t *conn, char *headers,
     }
     }
     dlen = deflated ? d->dir_z_len : d->dir_len;
     dlen = deflated ? d->dir_z_len : d->dir_len;
 
 
-    if (global_write_bucket_low(dlen, 1)) {
+    if (global_write_bucket_low(TO_CONN(conn), dlen, 1)) {
       log_info(LD_DIRSERV,
       log_info(LD_DIRSERV,
                "Client asked for the mirrored directory, but we've been "
                "Client asked for the mirrored directory, but we've been "
                "writing too many bytes lately. Sending 503 Dir busy.");
                "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1645,7 +1645,7 @@ directory_handle_command_get(dir_connection_t *conn, char *headers,
       tor_free(url);
       tor_free(url);
       return 0;
       return 0;
     }
     }
-    if (global_write_bucket_low(dlen, 1)) {
+    if (global_write_bucket_low(TO_CONN(conn), dlen, 1)) {
       log_info(LD_DIRSERV,
       log_info(LD_DIRSERV,
                "Client asked for running-routers, but we've been "
                "Client asked for running-routers, but we've been "
                "writing too many bytes lately. Sending 503 Dir busy.");
                "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1689,7 +1689,7 @@ directory_handle_command_get(dir_connection_t *conn, char *headers,
       return 0;
       return 0;
     }
     }
     dlen = dirserv_estimate_data_size(dir_fps, 0, deflated);
     dlen = dirserv_estimate_data_size(dir_fps, 0, deflated);
-    if (global_write_bucket_low(dlen, 2)) {
+    if (global_write_bucket_low(TO_CONN(conn), dlen, 2)) {
       log_info(LD_DIRSERV,
       log_info(LD_DIRSERV,
                "Client asked for network status lists, but we've been "
                "Client asked for network status lists, but we've been "
                "writing too many bytes lately. Sending 503 Dir busy.");
                "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1758,7 +1758,7 @@ directory_handle_command_get(dir_connection_t *conn, char *headers,
     else {
     else {
       dlen = dirserv_estimate_data_size(conn->fingerprint_stack,
       dlen = dirserv_estimate_data_size(conn->fingerprint_stack,
                                         1, deflated);
                                         1, deflated);
-      if (global_write_bucket_low(dlen, 2)) {
+      if (global_write_bucket_low(TO_CONN(conn), dlen, 2)) {
         log_info(LD_DIRSERV,
         log_info(LD_DIRSERV,
                  "Client asked for server descriptors, but we've been "
                  "Client asked for server descriptors, but we've been "
                  "writing too many bytes lately. Sending 503 Dir busy.");
                  "writing too many bytes lately. Sending 503 Dir busy.");

+ 1 - 1
src/or/or.h

@@ -2042,7 +2042,7 @@ int retry_all_listeners(int force, smartlist_t *replaced_conns,
                         smartlist_t *new_conns);
                         smartlist_t *new_conns);
 
 
 int connection_bucket_write_limit(connection_t *conn);
 int connection_bucket_write_limit(connection_t *conn);
-int global_write_bucket_low(size_t attempt, int priority);
+int global_write_bucket_low(connection_t *conn, size_t attempt, int priority);
 void connection_bucket_init(void);
 void connection_bucket_init(void);
 void connection_bucket_refill(int seconds_elapsed);
 void connection_bucket_refill(int seconds_elapsed);