Ver código fonte

r6902@Kushana: nickm | 2006-07-25 17:30:27 -0400
Move rend_query to origin_circuit_t where it belongs; save another 17 bytes per OR circuit.


svn:r6903

Nick Mathewson 18 anos atrás
pai
commit
a88ec48a39
6 arquivos alterados com 38 adições e 36 exclusões
  1. 7 5
      src/or/circuitlist.c
  2. 5 4
      src/or/circuituse.c
  3. 1 1
      src/or/connection_edge.c
  4. 9 9
      src/or/or.h
  5. 11 11
      src/or/rendclient.c
  6. 5 6
      src/or/rendservice.c

+ 7 - 5
src/or/circuitlist.c

@@ -632,16 +632,18 @@ circuit_unlink_all_from_or_conn(connection_t *conn, int reason)
  *
  * Return NULL if no such circuit exists.
  */
-circuit_t *
+origin_circuit_t *
 circuit_get_by_rend_query_and_purpose(const char *rend_query, uint8_t purpose)
 {
   circuit_t *circ;
 
+  tor_assert(CIRCUIT_PURPOSE_IS_ORIGIN(purpose));
+
   for (circ = global_circuitlist; circ; circ = circ->next) {
     if (!circ->marked_for_close &&
         circ->purpose == purpose &&
-        !rend_cmp_service_ids(rend_query, circ->rend_query))
-      return circ;
+        !rend_cmp_service_ids(rend_query, TO_ORIGIN_CIRCUIT(circ)->rend_query))
+      return TO_ORIGIN_CIRCUIT(circ);
   }
   return NULL;
 }
@@ -854,10 +856,10 @@ _circuit_mark_for_close(circuit_t *circ, int reason, int line,
     /* treat this like getting a nack from it */
     log_info(LD_REND, "Failed intro circ %s to %s (awaiting ack). "
              "Removing from descriptor.",
-             safe_str(circ->rend_query),
+             safe_str(ocirc->rend_query),
              safe_str(build_state_get_exit_nickname(ocirc->build_state)));
     rend_client_remove_intro_point(ocirc->build_state->chosen_exit,
-                                   circ->rend_query);
+                                   ocirc->rend_query);
   }
   if (circ->n_conn)
     connection_or_send_destroy(circ->n_circ_id, circ->n_conn, reason);

+ 5 - 4
src/or/circuituse.c

@@ -91,7 +91,8 @@ circuit_is_acceptable(circuit_t *circ, connection_t *conn,
       return 0;
     }
   } else { /* not general */
-    if (rend_cmp_service_ids(conn->rend_query, circ->rend_query)) {
+    if (rend_cmp_service_ids(conn->rend_query,
+                             TO_ORIGIN_CIRCUIT(circ)->rend_query)) {
       /* this circ is not for this conn */
       return 0;
     }
@@ -236,7 +237,8 @@ circuit_expire_building(time_t now)
           /* c_rend_ready circs measure age since timestamp_dirty,
            * because that's set when they switch purposes
            */
-          if (!victim->rend_query[0] || victim->timestamp_dirty > cutoff)
+          if (TO_ORIGIN_CIRCUIT(victim)->rend_query[0] ||
+              victim->timestamp_dirty > cutoff)
             continue;
           break;
         case CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED:
@@ -1010,8 +1012,7 @@ circuit_get_open_circ_or_launch(connection_t *conn,
       rep_hist_note_used_internal(time(NULL), need_uptime, 1);
       if (circ) {
         /* write the service_id into circ */
-        strlcpy(circ->_base.rend_query, conn->rend_query,
-                sizeof(circ->_base.rend_query));
+        strlcpy(circ->rend_query, conn->rend_query, sizeof(circ->rend_query));
         if (circ->_base.purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND &&
             circ->_base.state == CIRCUIT_STATE_OPEN)
           rend_client_rendcirc_has_opened(circ);

+ 1 - 1
src/or/connection_edge.c

@@ -1637,7 +1637,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
     log_debug(LD_REND,"begin is for rendezvous. configuring stream.");
     n_stream->address = tor_strdup("(rendezvous)");
     n_stream->state = EXIT_CONN_STATE_CONNECTING;
-    strlcpy(n_stream->rend_query, circ->rend_query,
+    strlcpy(n_stream->rend_query, origin_circ->rend_query,
             sizeof(n_stream->rend_query));
     tor_assert(connection_edge_is_rendezvous_stream(n_stream));
     assert_circuit_ok(circ);

+ 9 - 9
src/or/or.h

@@ -1110,13 +1110,6 @@ typedef struct circuit_t {
   const char *marked_for_close_file; /**< For debugging: in which file was this
                                       * circuit marked for close? */
 
-  /**
-   * The rend_query field holds the y portion of y.onion (nul-terminated)
-   * if purpose is C_INTRODUCING or C_ESTABLISH_REND, or is a C_GENERAL
-   * for a hidden service, or is S_*.
-   */
-  char rend_query[REND_SERVICE_ID_LEN+1];
-
   /** The rend_pk_digest field holds a hash of location-hidden service's
    * PK if purpose is INTRO_POINT or S_ESTABLISH_INTRO or S_RENDEZVOUSING.
    */
@@ -1155,6 +1148,13 @@ typedef struct origin_circuit_t {
    */
   crypt_path_t *cpath;
 
+  /**
+   * The rend_query field holds the y portion of y.onion (nul-terminated)
+   * if purpose is C_INTRODUCING or C_ESTABLISH_REND, or is a C_GENERAL
+   * for a hidden service, or is S_*.
+   */
+  char rend_query[REND_SERVICE_ID_LEN+1];
+
 } origin_circuit_t;
 
 typedef struct or_circuit_t {
@@ -1592,8 +1592,8 @@ int circuit_id_used_on_conn(uint16_t circ_id, connection_t *conn);
 circuit_t *circuit_get_by_edge_conn(connection_t *conn);
 void circuit_unlink_all_from_or_conn(connection_t *conn, int reason);
 circuit_t *circuit_get_by_global_id(uint32_t id);
-circuit_t *circuit_get_by_rend_query_and_purpose(const char *rend_query,
-                                                 uint8_t purpose);
+origin_circuit_t *circuit_get_by_rend_query_and_purpose(const char *rend_query,
+                                                        uint8_t purpose);
 circuit_t *circuit_get_next_by_pk_and_purpose(circuit_t *start,
                                          const char *digest, uint8_t purpose);
 or_circuit_t *circuit_get_rendezvous(const char *cookie);

+ 11 - 11
src/or/rendclient.c

@@ -66,13 +66,13 @@ rend_client_send_introduction(origin_circuit_t *introcirc,
 
   tor_assert(introcirc->_base.purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
   tor_assert(rendcirc->_base.purpose == CIRCUIT_PURPOSE_C_REND_READY);
-  tor_assert(!rend_cmp_service_ids(introcirc->_base.rend_query,
-                                   rendcirc->_base.rend_query));
+  tor_assert(!rend_cmp_service_ids(introcirc->rend_query,
+                                   rendcirc->rend_query));
 
-  if (rend_cache_lookup_entry(introcirc->_base.rend_query, -1, &entry) < 1) {
+  if (rend_cache_lookup_entry(introcirc->rend_query, -1, &entry) < 1) {
     log_warn(LD_REND,
              "query %s didn't have valid rend desc in cache. Failing.",
-             escaped_safe_str(introcirc->_base.rend_query));
+             escaped_safe_str(introcirc->rend_query));
     goto err;
   }
 
@@ -183,7 +183,7 @@ int
 rend_client_introduction_acked(origin_circuit_t *circ,
                                const char *request, size_t request_len)
 {
-  circuit_t *rendcirc;
+  origin_circuit_t *rendcirc;
   (void) request; // XXXX Use this.
 
   if (circ->_base.purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
@@ -204,9 +204,9 @@ rend_client_introduction_acked(origin_circuit_t *circ,
      */
     log_info(LD_REND,"Received ack. Telling rend circ...");
     rendcirc = circuit_get_by_rend_query_and_purpose(
-               circ->_base.rend_query, CIRCUIT_PURPOSE_C_REND_READY);
+               circ->rend_query, CIRCUIT_PURPOSE_C_REND_READY);
     if (rendcirc) { /* remember the ack */
-      rendcirc->purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED;
+      rendcirc->_base.purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED;
     } else {
       log_info(LD_REND,"...Found no rend circ. Dropping on the floor.");
     }
@@ -221,22 +221,22 @@ rend_client_introduction_acked(origin_circuit_t *circ,
      * If none remain, refetch the service descriptor.
      */
     if (rend_client_remove_intro_point(circ->build_state->chosen_exit,
-                                       circ->_base.rend_query) > 0) {
+                                       circ->rend_query) > 0) {
       /* There are introduction points left. Re-extend the circuit to
        * another intro point and try again. */
       extend_info_t *extend_info;
       int result;
-      extend_info = rend_client_get_random_intro(circ->_base.rend_query);
+      extend_info = rend_client_get_random_intro(circ->rend_query);
       if (!extend_info) {
         log_warn(LD_REND, "No introduction points left for %s. Closing.",
-                 escaped_safe_str(circ->_base.rend_query));
+                 escaped_safe_str(circ->rend_query));
         circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_AT_ORIGIN);
         return -1;
       }
       log_info(LD_REND,
                "Got nack for %s from %s. Re-extending circ %d, "
                "this time to %s.",
-               escaped_safe_str(circ->_base.rend_query),
+               escaped_safe_str(circ->rend_query),
                circ->build_state->chosen_exit->nickname, circ->_base.n_circ_id,
                extend_info->nickname);
       result = circuit_extend_to_new_exit(circ, extend_info);

+ 5 - 6
src/or/rendservice.c

@@ -592,8 +592,8 @@ rend_service_introduce(origin_circuit_t *circuit, const char *request,
   memcpy(launched->_base.rend_pk_digest, circuit->_base.rend_pk_digest,
          DIGEST_LEN);
   memcpy(launched->_base.rend_cookie, r_cookie, REND_COOKIE_LEN);
-  strlcpy(launched->_base.rend_query, service->service_id,
-          sizeof(launched->_base.rend_query));
+  strlcpy(launched->rend_query, service->service_id,
+          sizeof(launched->rend_query));
   launched->build_state->pending_final_cpath = cpath =
     tor_malloc_zero(sizeof(crypt_path_t));
   cpath->magic = CRYPT_PATH_MAGIC;
@@ -663,8 +663,7 @@ rend_service_relaunch_rendezvous(origin_circuit_t *oldcirc)
   newstate->pending_final_cpath = oldstate->pending_final_cpath;
   oldstate->pending_final_cpath = NULL;
 
-  memcpy(newcirc->_base.rend_query, oldcirc->_base.rend_query,
-         REND_SERVICE_ID_LEN+1);
+  memcpy(newcirc->rend_query, oldcirc->rend_query, REND_SERVICE_ID_LEN+1);
   memcpy(newcirc->_base.rend_pk_digest, oldcirc->_base.rend_pk_digest,
          DIGEST_LEN);
   memcpy(newcirc->_base.rend_cookie, oldcirc->_base.rend_cookie,
@@ -695,8 +694,8 @@ rend_service_launch_establish_intro(rend_service_t *service,
              nickname);
     return -1;
   }
-  strlcpy(launched->_base.rend_query, service->service_id,
-          sizeof(launched->_base.rend_query));
+  strlcpy(launched->rend_query, service->service_id,
+          sizeof(launched->rend_query));
   memcpy(launched->_base.rend_pk_digest, service->pk_digest, DIGEST_LEN);
 
   if (launched->_base.state == CIRCUIT_STATE_OPEN)