]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add an OptimisticData option to control client-side optimistic data
authorNick Mathewson <nickm@torproject.org>
Wed, 20 Jul 2011 14:38:00 +0000 (10:38 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 20 Jul 2011 18:14:21 +0000 (14:14 -0400)
changes/optimistic-client
doc/tor.1.txt
src/or/circuituse.c
src/or/config.c
src/or/or.h

index 88afb9ad56c3b5123d10b2ecdf8f4eb821988f6f..9a21a41604591b68e57c19fbc3835a261304ddcf 100644 (file)
@@ -3,5 +3,7 @@
       clients can now "optimistically" send data on a stream before
       the exit node reports that the stream has opened. This can save
       a round trip when starting connections with protocols where the
-      client speaks first.  Implements proposal 181; code by Ian
-      Goldberg.
+      client speaks first. This behavior is controlled by a (currently
+      disabled) networkstatus consensus parameter. To turn it on or
+      off manually, use the "OptimisticData" torrc option.  Implements
+      proposal 181; code by Ian Goldberg.
index 821098b56ec0b0c2a35fd65a3d5f82c57bf121a3..6dc3b28bdad0d75d0e067da6042d1787a9f18f33 100644 (file)
@@ -930,6 +930,16 @@ The following options are useful only for clients (that is, if
     that have the **AllowSingleHopExits** option turned on to build
     one-hop Tor connections.  (Default: 0)
 
+**OptimisticData** **0**|**1**|**auto**::
+    When this option is set, and Tor is using an exit node that supports
+    the feature, it will try optimistically to send data to the exit node
+    without waiting for the exit node to report whether the connection
+    succeeded.  This can save a round-trip time for protocols like HTTP
+    where the client talks first.  If OptimisticData is set to **auto**,
+    Tor will look at the UseOptimisticData parameter in the networkstatus.
+    (Default: auto)
+
+
 SERVER OPTIONS
 --------------
 
index 1bc518b7d45bc66aefa033279f8929acd9e57cf9..9fbe5fed655f53751a1998da1cbd5c66ae243381 100644 (file)
@@ -18,6 +18,7 @@
 #include "connection_edge.h"
 #include "control.h"
 #include "nodelist.h"
+#include "networkstatus.h"
 #include "policies.h"
 #include "rendclient.h"
 #include "rendcommon.h"
@@ -1541,6 +1542,19 @@ cpath_is_on_circuit(origin_circuit_t *circ, crypt_path_t *crypt_path)
   return 0;
 }
 
+/** Return true iff client-side optimistic data is supported. */
+static int
+optimistic_data_enabled(void)
+{
+  const or_options_t *options = get_options();
+  if (options->OptimisticData < 0) {
+    const int32_t enabled =
+      networkstatus_get_param(NULL, "UseOptimisticData", 0, 0, 1);
+    return (int)enabled;
+  }
+  return options->OptimisticData;
+}
+
 /** Attach the AP stream <b>apconn</b> to circ's linked list of
  * p_streams. Also set apconn's cpath_layer to <b>cpath</b>, or to the last
  * hop in circ's cpath if <b>cpath</b> is NULL.
@@ -1580,7 +1594,8 @@ link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ,
                      apconn->cpath_layer->extend_info->identity_digest)) &&
       exitnode->rs) {
     /* Okay; we know what exit node this is. */
-    if (circ->_base.purpose == CIRCUIT_PURPOSE_C_GENERAL &&
+    if (optimistic_data_enabled() &&
+        circ->_base.purpose == CIRCUIT_PURPOSE_C_GENERAL &&
         exitnode->rs->version_supports_optimistic_data)
       apconn->exit_allows_optimistic_data = 1;
     else
index 96d50954babccd8116714986b51cb9401e7f7b43..088617bb499596ed94e1a115e914228eb889013f 100644 (file)
@@ -337,6 +337,7 @@ static config_var_t _option_vars[] = {
   V(PerConnBWRate,               MEMUNIT,  "0"),
   V(PidFile,                     STRING,   NULL),
   V(TestingTorNetwork,           BOOL,     "0"),
+  V(OptimisticData,              AUTOBOOL, "auto"),
   V(PortForwarding,              BOOL,     "0"),
   V(PortForwardingHelper,        FILENAME, "tor-fw-helper"),
   V(PreferTunneledDirConns,      BOOL,     "1"),
index 16c792771ef3bed049b93a918310ebf7a0e8855e..c518b4cd8f30bdd3f63c3677c948e0821153dab3 100644 (file)
@@ -3271,6 +3271,10 @@ typedef struct {
    * once. */
   int MaxClientCircuitsPending;
 
+  /** If 1, we always send optimistic data when it's supported.  If 0, we
+   * never use it.  If -1, we do what the consensus says. */
+  int OptimisticData;
+
 } or_options_t;
 
 /** Persistent state for an onion router, as saved to disk. */