Переглянути джерело

if we fail to build a circuit to an intended enclave, and it's
not mandatory that we use that enclave, stop wanting it.


svn:r8559

Roger Dingledine 17 роки тому
батько
коміт
4096e577c5
4 змінених файлів з 44 додано та 3 видалено
  1. 5 0
      src/or/circuituse.c
  2. 35 0
      src/or/connection_edge.c
  3. 1 0
      src/or/or.h
  4. 3 3
      src/or/relay.c

+ 5 - 0
src/or/circuituse.c

@@ -748,6 +748,11 @@ circuit_build_failed(origin_circuit_t *circ)
     case CIRCUIT_PURPOSE_C_GENERAL:
       /* If we never built the circuit, note it as a failure. */
       circuit_increment_failure_count();
+      if (failed_at_last_hop) {
+        /* Make sure any streams that demand our last hop as their exit
+         * know that it's unlikely to happen. */
+        circuit_discard_optional_exit_enclaves(circ->cpath->prev->extend_info);
+      }
       break;
     case CIRCUIT_PURPOSE_TESTING:
       circuit_testing_failed(circ, failed_at_last_hop);

+ 35 - 0
src/or/connection_edge.c

@@ -453,6 +453,41 @@ connection_ap_attach_pending(void)
   }
 }
 
+/** A circuit failed to finish on its last hop <b>info</b>. If there
+ * are any streams waiting with this exit node in mind, but they
+ * don't absolutely require it, make them give up on it.
+ */
+void
+circuit_discard_optional_exit_enclaves(extend_info_t *info)
+{
+  connection_t **carray;
+  connection_t *conn;
+  edge_connection_t *edge_conn;
+  routerinfo_t *r1, *r2;
+  int n, i;
+
+  get_connection_array(&carray, &n);
+
+  for (i = 0; i < n; ++i) {
+    conn = carray[i];
+    if (conn->marked_for_close ||
+        conn->type != CONN_TYPE_AP ||
+        !conn->chosen_exit_optional)
+      continue;
+    edge_conn = TO_EDGE_CONN(conn);
+    r1 = router_get_by_nickname(edge_conn->chosen_exit_name, 0);
+    r2 = router_get_by_nickname(info->nickname, 0);
+    if (r1 && r2 && r1==r2) {
+      tor_assert(edge_conn->socks_request);
+      log_info(LD_APP, "Giving up on enclave exit '%s' for destination %s.",
+               safe_str(edge_conn->chosen_exit_name),
+               escaped_safe_str(edge_conn->socks_request->address));
+      conn->chosen_exit_optional = 0;
+      tor_free(edge_conn->chosen_exit_name); /* clears it */
+    }
+  }
+}
+
 /** The AP connection <b>conn</b> has just failed while attaching or
  * sending a BEGIN or resolving on <b>circ</b>, but another circuit
  * might work.  Detach the circuit, and either reattach it, launch a

+ 1 - 0
src/or/or.h

@@ -1936,6 +1936,7 @@ int connection_edge_is_rendezvous_stream(edge_connection_t *conn);
 int connection_ap_can_use_exit(edge_connection_t *conn, routerinfo_t *exit);
 void connection_ap_expire_beginning(void);
 void connection_ap_attach_pending(void);
+void circuit_discard_optional_exit_enclaves(extend_info_t *info);
 int connection_ap_detach_retriable(edge_connection_t *conn,
                                    origin_circuit_t *circ);
 

+ 3 - 3
src/or/relay.c

@@ -721,7 +721,7 @@ connection_edge_process_end_not_open(
         if (conn->_base.chosen_exit_optional) {
           /* stop wanting a specific exit */
           conn->_base.chosen_exit_optional = 0;
-          tor_free(conn->chosen_exit_name);
+          tor_free(conn->chosen_exit_name); /* clears it */
         }
         if (connection_ap_detach_retriable(conn, circ) >= 0)
           return 0;
@@ -745,7 +745,7 @@ connection_edge_process_end_not_open(
           if (conn->_base.chosen_exit_optional) {
             /* stop wanting a specific exit */
             conn->_base.chosen_exit_optional = 0;
-            tor_free(conn->chosen_exit_name);
+            tor_free(conn->chosen_exit_name); /* clears it */
           }
           if (connection_ap_detach_retriable(conn, circ) >= 0)
             return 0;
@@ -770,7 +770,7 @@ connection_edge_process_end_not_open(
         if (conn->_base.chosen_exit_optional) {
           /* stop wanting a specific exit */
           conn->_base.chosen_exit_optional = 0;
-          tor_free(conn->chosen_exit_name);
+          tor_free(conn->chosen_exit_name); /* clears it */
         }
         if (connection_ap_detach_retriable(conn, circ) >= 0)
           return 0;