Quellcode durchsuchen

clean up and refactor some more

svn:r3798
Roger Dingledine vor 20 Jahren
Ursprung
Commit
f1ba4296c1
5 geänderte Dateien mit 24 neuen und 19 gelöschten Zeilen
  1. 20 3
      src/or/circuitbuild.c
  2. 1 1
      src/or/circuitlist.c
  3. 1 7
      src/or/circuituse.c
  4. 1 0
      src/or/or.h
  5. 1 8
      src/or/rendclient.c

+ 20 - 3
src/or/circuitbuild.c

@@ -246,7 +246,7 @@ again:
   return 0; /* if r == 1 */
   return 0; /* if r == 1 */
 }
 }
 
 
-/** Create and return new circuit. Initialize its purpose and
+/** Create and return a new circuit. Initialize its purpose and
  * build-state based on our arguments. */
  * build-state based on our arguments. */
 circuit_t *
 circuit_t *
 circuit_init(uint8_t purpose, int need_uptime, int need_capacity, int internal) {
 circuit_init(uint8_t purpose, int need_uptime, int need_capacity, int internal) {
@@ -1168,8 +1168,9 @@ onion_pick_cpath_exit(circuit_t *circ, routerinfo_t *exit) {
   return 0;
   return 0;
 }
 }
 
 
-/** Take the open circ originating here, give it a new exit destination
+/** Give <b>circ</b> a new exit destination to <b>exit</b>, and add a
- * to <b>exit</b>, and get it to send the next extend cell.
+ * hop to the cpath reflecting this. Don't send the next extend cell --
+ * the caller will do this if it wants to.
  */
  */
 int
 int
 circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit) {
 circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit) {
@@ -1183,6 +1184,22 @@ circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit) {
   return 0;
   return 0;
 }
 }
 
 
+/** Take the open circ originating here, give it a new exit destination
+ * to <b>exit</b>, and get it to send the next extend cell. If you can't
+ * send the extend cell, mark the circuit for close and return -1, else
+ * return 0. */
+int circuit_extend_to_new_exit(circuit_t *circ, routerinfo_t *exit) {
+  circuit_append_new_exit(circ, exit);
+  circ->state = CIRCUIT_STATE_BUILDING;
+  if (circuit_send_next_onion_skin(circ)<0) {
+    log_fn(LOG_WARN, "Couldn't extend circuit to new point '%s'.",
+           circ->build_state->chosen_exit_name);
+    circuit_mark_for_close(circ);
+    return -1;
+  }
+  return 0;
+}
+
 /** Return the number of routers in <b>routers</b> that are currently up
 /** Return the number of routers in <b>routers</b> that are currently up
  * and available for building circuits through.
  * and available for building circuits through.
  */
  */

+ 1 - 1
src/or/circuitlist.c

@@ -77,7 +77,7 @@ void circuit_close_all_marked(void)
 circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) {
 circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn) {
   circuit_t *circ;
   circuit_t *circ;
   static uint32_t n_circuits_allocated = 1;
   static uint32_t n_circuits_allocated = 1;
-    /* never zero, since a global ID of 0 treated specially by the controller */
+    /* never zero, since a global ID of 0 is treated specially by the controller */
 
 
   circ = tor_malloc_zero(sizeof(circuit_t));
   circ = tor_malloc_zero(sizeof(circuit_t));
   circ->magic = CIRCUIT_MAGIC;
   circ->magic = CIRCUIT_MAGIC;

+ 1 - 7
src/or/circuituse.c

@@ -722,14 +722,8 @@ circuit_launch_by_router(uint8_t purpose, routerinfo_t *exit,
         case CIRCUIT_PURPOSE_S_CONNECT_REND:
         case CIRCUIT_PURPOSE_S_CONNECT_REND:
           /* need to add a new hop */
           /* need to add a new hop */
           tor_assert(exit);
           tor_assert(exit);
-          circuit_append_new_exit(circ, exit);
+          if (circuit_extend_to_new_exit(circ, exit) < 0)
-          circ->state = CIRCUIT_STATE_BUILDING;
-          if (circuit_send_next_onion_skin(circ)<0) {
-            log_fn(LOG_WARN, "Couldn't extend circuit to new point '%s'.",
-                   circ->build_state->chosen_exit_name);
-            circuit_mark_for_close(circ);
             return NULL;
             return NULL;
-          }
           break;
           break;
         default:
         default:
           log_fn(LOG_WARN,"Bug: unexpected purpose %d when cannibalizing a general circ.",
           log_fn(LOG_WARN,"Bug: unexpected purpose %d when cannibalizing a general circ.",

+ 1 - 0
src/or/or.h

@@ -1137,6 +1137,7 @@ int circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
                                         int *need_capacity);
                                         int *need_capacity);
 
 
 int circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit);
 int circuit_append_new_exit(circuit_t *circ, routerinfo_t *exit);
+int circuit_extend_to_new_exit(circuit_t *circ, routerinfo_t *exit);
 void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop);
 void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop);
 
 
 /********************************* circuitlist.c ***********************/
 /********************************* circuitlist.c ***********************/

+ 1 - 8
src/or/rendclient.c

@@ -226,14 +226,7 @@ rend_client_introduction_acked(circuit_t *circ,
       log_fn(LOG_INFO, "Chose new intro point %s for %s (circ %d)",
       log_fn(LOG_INFO, "Chose new intro point %s for %s (circ %d)",
              nickname, circ->rend_query, circ->n_circ_id);
              nickname, circ->rend_query, circ->n_circ_id);
       tor_free(nickname);
       tor_free(nickname);
-      circuit_append_new_exit(circ, r);
+      return circuit_extend_to_new_exit(circ, r);
-      circ->state = CIRCUIT_STATE_BUILDING;
-      if (circuit_send_next_onion_skin(circ)<0) {
-        log_fn(LOG_WARN, "Couldn't extend circuit to new point '%s'.",
-               circ->build_state->chosen_exit_name);
-        circuit_mark_for_close(circ);
-        return -1;
-      }
     }
     }
   }
   }
   return 0;
   return 0;