[or-cvs] r9269: more progress and cleanups (in tor/trunk: doc src/common src/or)

arma at seul.org arma at seul.org
Fri Jan 5 06:03:11 UTC 2007


Author: arma
Date: 2007-01-05 01:03:10 -0500 (Fri, 05 Jan 2007)
New Revision: 9269

Modified:
   tor/trunk/doc/TODO
   tor/trunk/doc/dir-spec.txt
   tor/trunk/src/common/tortls.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirserv.c
Log:
more progress and cleanups


Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/doc/TODO	2007-01-05 06:03:10 UTC (rev 9269)
@@ -82,9 +82,11 @@
         D Delay when we get a lot of 503s, rather than punting onto the
           servers that have given us 503s?
         o Add a 'BadDirectory' flag to statuses.
-      - authorities should *never* 503 a cache, and should never 503
-        network status requests. They can 503 client descriptor requests
-        when they feel like it.
+      o authorities should *never* 503 a cache, and should never 503
+        network status requests.
+      D They can 503 client descriptor requests when they feel like it.
+        How can they distinguish? Not implemented for now, maybe
+        should abandon.
       - update dir-spec with what we decided for each of these
 
   o Have a mode that doesn't write to disk much, so we can run Tor on
@@ -131,7 +133,7 @@
       and to give dir conns lower priority.
     . Write limiting; separate token bucket for write
       o preemptively give a 503 to some v1 dir requests
-R     - preemptively give a 503 to some v2 dir requests
+      o preemptively give a 503 to some v2 dir requests
         o Write function to estimate bytes needed for N descriptors
           statuses
       D per-conn write buckets
@@ -258,6 +260,8 @@
   - Add an option (related to AvoidDiskWrites) to disable directory caching.
 
 Minor items for 0.1.2.x as time permits:
+  - a way to generate the website diagrams from source, so we can
+    translate them as utf-8 text rather than with gimp.
 R - add d64 and fp64 along-side d and fp so people can paste status
     entries into a url. since + is a valid base64 char, only allow one
     at a time. spec and then do.

Modified: tor/trunk/doc/dir-spec.txt
===================================================================
--- tor/trunk/doc/dir-spec.txt	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/doc/dir-spec.txt	2007-01-05 06:03:10 UTC (rev 9269)
@@ -379,9 +379,9 @@
              (because its ISP censors it, because it is behind a restrictive
              proxy, or for some similar reason).
           "BadDirectory" if the router is believed to be useless as a
-             directory cache (because its directory port isn't working;
-             because its bandwidth is always throttled, or for some
-             similar reason).
+             directory cache (because its directory port isn't working,
+             its bandwidth is always throttled, or for some similar
+             reason).
           "Exit" if the router is useful for building general-purpose exit
              circuits.
           "Fast" if the router is suitable for high-bandwidth circuits.

Modified: tor/trunk/src/common/tortls.c
===================================================================
--- tor/trunk/src/common/tortls.c	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/src/common/tortls.c	2007-01-05 06:03:10 UTC (rev 9269)
@@ -875,6 +875,8 @@
    * we wrapped around by more than ULONG_MAX since the last time we called
    * this function.
    */
+  tor_assert(r >= tls->last_read_count);
+  tor_assert(w >= tls->last_write_count);
   *n_read = (size_t)(r - tls->last_read_count);
   *n_written = (size_t)(w - tls->last_write_count);
   tls->last_read_count = r;

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/src/or/connection.c	2007-01-05 06:03:10 UTC (rev 9269)
@@ -1175,9 +1175,12 @@
 int
 global_write_bucket_low(size_t attempt, int priority)
 {
-  if (global_write_bucket < (int)attempt) /* not enough space no matter what */
-    return 1;
+  if (authdir_mode(get_options()) && priority>1)
+    return 0; /* there's always room to answer v2 if we're an auth dir */
 
+  if (global_write_bucket < (int)attempt)
+    return 1; /* not enough space no matter the priority */
+
   if (priority == 1) { /* old-style v1 query */
     if (global_write_bucket-attempt < 2*get_options()->BandwidthRate)
       return 1;
@@ -1533,7 +1536,7 @@
    * have reached 0 on a different conn, and this guy needs to
    * know to stop reading. */
   connection_consider_empty_read_buckets(conn);
-  if (n_written > 0)
+  if (n_written > 0 && connection_is_writing(conn))
     connection_consider_empty_write_buckets(conn);
 
   return 0;
@@ -1714,7 +1717,7 @@
     }
     if (n_read > 0) {
       rep_hist_note_bytes_read(n_read, now);
-      global_read_bucket -= n_read;
+      connection_read_bucket_decrement(conn, n_read);
     }
   }
 
@@ -1737,7 +1740,7 @@
    * have reached 0 on a different conn, and this guy needs to
    * know to stop writing. */
   connection_consider_empty_write_buckets(conn);
-  if (n_read > 0)
+  if (n_read > 0 && connection_is_reading(conn))
     connection_consider_empty_read_buckets(conn);
 
   return 0;

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/src/or/directory.c	2007-01-05 06:03:10 UTC (rev 9269)
@@ -1325,8 +1325,8 @@
   }
 
   if (buf_datalen(conn->_base.inbuf) > MAX_DIRECTORY_OBJECT_SIZE) {
-    log_warn(LD_HTTP, "Too much data received from directory connection; "
-             "DOS attempt or protocol shift.");
+    log_warn(LD_HTTP, "Too much data received from directory connection: "
+             "denial of service attempt, or you need to upgrade?");
     connection_mark_for_close(TO_CONN(conn));
     return -1;
   }
@@ -1639,6 +1639,16 @@
       smartlist_free(dir_fps);
       return 0;
     }
+    dlen = dirserv_estimate_data_size(conn->fingerprint_stack,
+                                      0, deflated);
+    if (global_write_bucket_low(dlen, 2)) {
+      log_info(LD_DIRSERV,
+               "Client asked for server descriptors, but we've been "
+               "writing too many bytes lately. Sending 503 Dir busy.");
+      write_http_status_line(conn, 503, "Directory busy, try again later");
+      return 0;
+    }
+
     // note_request(request_type,dlen);
     (void) request_type;
     write_http_response_header(conn, -1,
@@ -1696,6 +1706,15 @@
     if (res < 0)
       write_http_status_line(conn, 404, msg);
     else {
+      dlen = dirserv_estimate_data_size(conn->fingerprint_stack,
+                                        1, deflated);
+      if (global_write_bucket_low(dlen, 2)) {
+        log_info(LD_DIRSERV,
+                 "Client asked for server descriptors, but we've been "
+                 "writing too many bytes lately. Sending 503 Dir busy.");
+        write_http_status_line(conn, 503, "Directory busy, try again later");
+        return 0;
+      }
       write_http_response_header(conn, -1,
                      deflated?"application/octet_stream":"text/plain",
                      deflated?"deflate":NULL, cache_lifetime);

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-01-05 04:19:06 UTC (rev 9268)
+++ tor/trunk/src/or/dirserv.c	2007-01-05 06:03:10 UTC (rev 9269)
@@ -1687,7 +1687,7 @@
   SMARTLIST_FOREACH(fingerprints, const char *, fp,
     {
       if (router_digest_is_me(fp) && should_generate_v2_networkstatus())
-          generate_v2_networkstatus();
+        generate_v2_networkstatus();
       cached = digestmap_get(cached_v2_networkstatus, fp);
       if (cached) {
         smartlist_add(result, cached);
@@ -1839,8 +1839,9 @@
 
   SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
     if (!strcasecmp(address, ri->address) && or_port == ri->or_port &&
+        as_advertised &&
         !memcmp(ri->cache_info.identity_digest, digest_rcvd, DIGEST_LEN) &&
-        as_advertised) {
+        !strcasecmp(nickname_rcvd, ri->nickname)) {
       /* correct nickname and digest. mark this router reachable! */
       log_info(LD_DIRSERV, "Found router %s to be reachable. Yay.",
                ri->nickname);
@@ -1886,10 +1887,11 @@
     ctr = (ctr + 1) % 128;
 }
 
-/** Return an approximate estimate of the number of bytes that will be needed
- * to transmit the server descriptors (if is_serverdescs) or networkstatus
- * objects (if !is_serverdescs) listed in <b>fps</b>.  If <b>compressed</b> is
- * set, we guess how large the data will be after compression.
+/** Return an approximate estimate of the number of bytes that will
+ * be needed to transmit the server descriptors (if is_serverdescs --
+ * they can be either d/ or fp/ queries) or networkstatus objects (if
+ * !is_serverdescs) listed in <b>fps</b>.  If <b>compressed</b> is set,
+ * we guess how large the data will be after compression.
  *
  * The return value is an estimate; it might be larger or smaller.
  **/



More information about the tor-commits mailing list