[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r6933: Identify some likely target fields for lowering; lower globa (in tor/trunk: . src/or)



Author: nickm
Date: 2006-07-28 11:11:11 -0400 (Fri, 28 Jul 2006)
New Revision: 6933

Modified:
   tor/trunk/
   tor/trunk/src/or/circuitlist.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/or.h
Log:
 r6948@Kushana:  nickm | 2006-07-28 10:10:35 -0400
 Identify some likely target fields for lowering; lower global_identifier (since we only use it for AP streams and origin circs).



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6922
   + c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6948

Modified: tor/trunk/src/or/circuitlist.c
===================================================================
--- tor/trunk/src/or/circuitlist.c	2006-07-28 13:52:36 UTC (rev 6932)
+++ tor/trunk/src/or/circuitlist.c	2006-07-28 15:11:11 UTC (rev 6933)
@@ -248,14 +248,10 @@
 static void
 init_circuit_base(circuit_t *circ)
 {
-  static uint32_t n_circuits_allocated = 1;
-  /* never zero, since a global ID of 0 is treated specially by the
-   * controller */
   circ->timestamp_created = time(NULL);
 
   circ->package_window = CIRCWINDOW_START;
   circ->deliver_window = CIRCWINDOW_START;
-  circ->global_identifier = n_circuits_allocated++;
 
   circuit_add(circ);
 }
@@ -267,11 +263,15 @@
 origin_circuit_new(void)
 {
   origin_circuit_t *circ;
+  /* never zero, since a global ID of 0 is treated specially by the
+   * controller */
+  static uint32_t n_circuits_allocated = 1;
 
   circ = tor_malloc_zero(sizeof(origin_circuit_t));
   circ->_base.magic = ORIGIN_CIRCUIT_MAGIC;
 
   circ->next_stream_id = crypto_rand_int(1<<16);
+  circ->global_identifier = n_circuits_allocated++;
 
   init_circuit_base(TO_CIRCUIT(circ));
 
@@ -491,16 +491,17 @@
 
 /** Return the circuit whose global ID is <b>id</b>, or NULL if no
  * such circuit exists. */
-circuit_t *
+origin_circuit_t *
 circuit_get_by_global_id(uint32_t id)
 {
   circuit_t *circ;
   for (circ=global_circuitlist;circ;circ = circ->next) {
-    if (circ->global_identifier == id) {
+    if (CIRCUIT_IS_ORIGIN(circ) &&
+        TO_ORIGIN_CIRCUIT(circ)->global_identifier == id) {
       if (circ->marked_for_close)
         return NULL;
       else
-        return circ;
+        return TO_ORIGIN_CIRCUIT(circ);
     }
   }
   return NULL;

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2006-07-28 13:52:36 UTC (rev 6932)
+++ tor/trunk/src/or/connection.c	2006-07-28 15:11:11 UTC (rev 6933)
@@ -158,7 +158,7 @@
 connection_t *
 connection_new(int type)
 {
-  static uint32_t n_connections_allocated = 0;
+  static uint32_t n_connections_allocated = 1;
   connection_t *conn;
   time_t now = time(NULL);
   size_t length;
@@ -192,7 +192,6 @@
   conn->magic = magic;
   conn->s = -1; /* give it a default of 'not used' */
   conn->conn_array_index = -1; /* also default to 'not used' */
-  conn->global_identifier = n_connections_allocated++;
 
   conn->type = type;
   if (!connection_is_listener(conn)) { /* listeners never use their buf */
@@ -203,6 +202,9 @@
     TO_EDGE_CONN(conn)->socks_request =
       tor_malloc_zero(sizeof(socks_request_t));
   }
+  if (CONN_IS_EDGE(conn)) {
+    TO_EDGE_CONN(conn)->global_identifier = n_connections_allocated++;
+  }
   if (type == CONN_TYPE_OR)
     TO_OR_CONN(conn)->next_circ_id = crypto_rand_int(1<<15);
 
@@ -1756,7 +1758,7 @@
 /** Return the connection with id <b>id</b> if it is not already marked for
  * close.
  */
-connection_t *
+edge_connection_t *
 connection_get_by_global_id(uint32_t id)
 {
   int i, n;
@@ -1766,9 +1768,9 @@
   get_connection_array(&carray,&n);
   for (i=0;i<n;i++) {
     conn = carray[i];
-    if (conn->global_identifier == id) {
+    if (CONN_IS_EDGE(conn) && TO_EDGE_CONN(conn)->global_identifier == id) {
       if (!conn->marked_for_close)
-        return conn;
+        return TO_EDGE_CONN(conn);
       else
         return NULL;
     }

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2006-07-28 13:52:36 UTC (rev 6932)
+++ tor/trunk/src/or/control.c	2006-07-28 15:11:11 UTC (rev 6933)
@@ -639,7 +639,7 @@
 }
 
 /** Given a text circuit <b>id</b>, return the corresponding circuit. */
-static circuit_t *
+static origin_circuit_t *
 get_circ(const char *id)
 {
   unsigned long n_id;
@@ -651,17 +651,17 @@
 }
 
 /** Given a text stream <b>id</b>, return the corresponding AP connection. */
-static connection_t *
+static edge_connection_t *
 get_stream(const char *id)
 {
   unsigned long n_id;
   int ok;
-  connection_t *conn;
+  edge_connection_t *conn;
   n_id = tor_parse_ulong(id, 10, 0, ULONG_MAX, &ok, NULL);
   if (!ok)
     return NULL;
   conn = connection_get_by_global_id(n_id);
-  if (!conn || conn->type != CONN_TYPE_AP)
+  if (!conn || conn->_base.type != CONN_TYPE_AP)
     return NULL;
   return conn;
 }
@@ -1400,7 +1400,7 @@
       slen = strlen(path)+strlen(state)+20;
       s = tor_malloc(slen+1);
       tor_snprintf(s, slen, "%lu %s %s",
-                   (unsigned long)circ->global_identifier,
+                   (unsigned long)TO_ORIGIN_CIRCUIT(circ)->global_identifier,
                    state, path);
       smartlist_add(status, s);
       tor_free(path);
@@ -1420,6 +1420,7 @@
       char *s;
       size_t slen;
       circuit_t *circ;
+      origin_circuit_t *origin_circ = NULL;
       if (conns[i]->type != CONN_TYPE_AP ||
           conns[i]->marked_for_close ||
           conns[i]->state == AP_CONN_STATE_SOCKS_WAIT)
@@ -1448,12 +1449,15 @@
           continue;
         }
       circ = circuit_get_by_edge_conn(conn);
+      if (CIRCUIT_IS_ORIGIN(circ))
+        origin_circ = TO_ORIGIN_CIRCUIT(circ);
       write_stream_target_to_buf(conn, buf, sizeof(buf));
       slen = strlen(buf)+strlen(state)+32;
       s = tor_malloc(slen+1);
       tor_snprintf(s, slen, "%lu %s %lu %s",
-                   (unsigned long) conn->_base.global_identifier,state,
-                   circ?(unsigned long)circ->global_identifier : 0ul,
+                   (unsigned long) conn->global_identifier,state,
+                   origin_circ?
+                         (unsigned long)origin_circ->global_identifier : 0ul,
                    buf);
       smartlist_add(status, s);
     }
@@ -1688,7 +1692,7 @@
 {
   smartlist_t *router_nicknames=NULL, *routers=NULL;
   uint32_t circ_id;
-  circuit_t *circ = NULL;
+  origin_circuit_t *circ = NULL;
   int zero_circ, v0;
   char reply[4];
   uint8_t intended_purpose = CIRCUIT_PURPOSE_C_GENERAL;
@@ -1749,15 +1753,6 @@
     }
   }
 
-  if (circ && ! CIRCUIT_IS_ORIGIN(circ)) {
-    if (v0)
-      send_control0_error(conn, ERR_NO_CIRC,"Circuit does not originate here");
-    else
-      connection_printf_to_buf(conn,
-                               "555 Circuit does not originate here\r\n");
-    goto done;
-  }
-
   routers = smartlist_create();
   SMARTLIST_FOREACH(router_nicknames, const char *, n,
   {
@@ -1781,21 +1776,21 @@
 
   if (zero_circ) {
     /* start a new circuit */
-    circ = TO_CIRCUIT( origin_circuit_init(intended_purpose, 0, 0, 0) );
+    circ = origin_circuit_init(intended_purpose, 0, 0, 0);
   }
 
   /* now circ refers to something that is ready to be extended */
   SMARTLIST_FOREACH(routers, routerinfo_t *, r,
   {
     extend_info_t *info = extend_info_from_router(r);
-    circuit_append_new_exit(TO_ORIGIN_CIRCUIT(circ), info);
+    circuit_append_new_exit(circ, info);
     extend_info_free(info);
   });
 
   /* now that we've populated the cpath, start extending */
   if (zero_circ) {
-    if (circuit_handle_first_hop(TO_ORIGIN_CIRCUIT(circ)) < 0) {
-      circuit_mark_for_close(circ, END_CIRC_AT_ORIGIN);
+    if (circuit_handle_first_hop(circ) < 0) {
+      circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_AT_ORIGIN);
       if (v0)
         send_control0_error(conn, ERR_INTERNAL, "couldn't start circuit");
       else
@@ -1803,12 +1798,12 @@
       goto done;
     }
   } else {
-    if (circ->state == CIRCUIT_STATE_OPEN) {
-      circuit_set_state(circ, CIRCUIT_STATE_BUILDING);
-      if (circuit_send_next_onion_skin(TO_ORIGIN_CIRCUIT(circ)) < 0) {
+    if (circ->_base.state == CIRCUIT_STATE_OPEN) {
+      circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_BUILDING);
+      if (circuit_send_next_onion_skin(circ) < 0) {
         log_info(LD_CONTROL,
                  "send_next_onion_skin failed; circuit marked for closing.");
-        circuit_mark_for_close(circ, END_CIRC_AT_ORIGIN);
+        circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_AT_ORIGIN);
         if (v0)
           send_control0_error(conn, ERR_INTERNAL, "couldn't send onion skin");
         else
@@ -1840,7 +1835,7 @@
 handle_control_setpurpose(control_connection_t *conn, int for_circuits,
                           uint32_t len, const char *body)
 {
-  circuit_t *circ = NULL;
+  origin_circuit_t *circ = NULL;
   routerinfo_t *ri = NULL;
   uint8_t new_purpose;
   smartlist_t *args = smartlist_create();
@@ -1875,7 +1870,7 @@
   }
 
   if (for_circuits)
-    circ->purpose = new_purpose;
+    circ->_base.purpose = new_purpose;
   else
     ri->purpose = new_purpose;
   connection_write_str_to_buf("250 OK\r\n", conn);
@@ -1892,10 +1887,9 @@
 handle_control_attachstream(control_connection_t *conn, uint32_t len,
                             const char *body)
 {
-  connection_t *ap_conn = NULL;
-  circuit_t *circ = NULL;
+  edge_connection_t *ap_conn = NULL;
+  origin_circuit_t *circ = NULL;
   int zero_circ;
-  edge_connection_t *edge_conn;
 
   if (STATE_IS_V0(conn->_base.state)) {
     uint32_t conn_id;
@@ -1946,9 +1940,9 @@
       return 0;
   }
 
-  if (ap_conn->state != AP_CONN_STATE_CONTROLLER_WAIT &&
-      ap_conn->state != AP_CONN_STATE_CONNECT_WAIT &&
-      ap_conn->state != AP_CONN_STATE_RESOLVE_WAIT) {
+  if (ap_conn->_base.state != AP_CONN_STATE_CONTROLLER_WAIT &&
+      ap_conn->_base.state != AP_CONN_STATE_CONNECT_WAIT &&
+      ap_conn->_base.state != AP_CONN_STATE_RESOLVE_WAIT) {
     if (STATE_IS_V0(conn->_base.state)) {
       send_control0_error(conn, ERR_NO_STREAM,
                           "Connection is not managed by controller.");
@@ -1960,22 +1954,19 @@
     return 0;
   }
 
-  edge_conn = TO_EDGE_CONN(ap_conn);
-
   /* Do we need to detach it first? */
-  if (ap_conn->state != AP_CONN_STATE_CONTROLLER_WAIT) {
-    circuit_t *tmpcirc = circuit_get_by_edge_conn(edge_conn);
-    connection_edge_end(edge_conn, END_STREAM_REASON_TIMEOUT,
-                        edge_conn->cpath_layer);
+  if (ap_conn->_base.state != AP_CONN_STATE_CONTROLLER_WAIT) {
+    circuit_t *tmpcirc = circuit_get_by_edge_conn(ap_conn);
+    connection_edge_end(ap_conn, END_STREAM_REASON_TIMEOUT,
+                        ap_conn->cpath_layer);
     /* Un-mark it as ending, since we're going to reuse it. */
-    ap_conn->edge_has_sent_end = 0;
+    ap_conn->_base.edge_has_sent_end = 0;
     if (tmpcirc)
-      circuit_detach_stream(tmpcirc,edge_conn);
-    ap_conn->state = AP_CONN_STATE_CONTROLLER_WAIT;
+      circuit_detach_stream(tmpcirc,ap_conn);
+    ap_conn->_base.state = AP_CONN_STATE_CONTROLLER_WAIT;
   }
 
-  if (circ &&
-      (circ->state != CIRCUIT_STATE_OPEN || ! CIRCUIT_IS_ORIGIN(circ))) {
+  if (circ && (circ->_base.state != CIRCUIT_STATE_OPEN)) {
     if (STATE_IS_V0(conn->_base.state))
       send_control0_error(conn, ERR_INTERNAL,
                           "Refuse to attach stream to non-open, origin circ.");
@@ -1985,8 +1976,7 @@
                      conn);
     return 0;
   }
-  if (connection_ap_handshake_rewrite_and_attach(edge_conn,
-                               circ ? TO_ORIGIN_CIRCUIT(circ) : NULL) < 0) {
+  if (connection_ap_handshake_rewrite_and_attach(ap_conn, circ) < 0) {
     if (STATE_IS_V0(conn->_base.state))
       send_control0_error(conn, ERR_INTERNAL, "Unable to attach stream.");
     else
@@ -2062,7 +2052,7 @@
 handle_control_redirectstream(control_connection_t *conn, uint32_t len,
                               const char *body)
 {
-  connection_t *ap_conn = NULL;
+  edge_connection_t *ap_conn = NULL;
   uint32_t conn_id;
   char *new_addr = NULL;
   uint16_t new_port = 0;
@@ -2075,8 +2065,8 @@
     conn_id = ntohl(get_uint32(body));
 
     if (!(ap_conn = connection_get_by_global_id(conn_id))
-        || ap_conn->state != CONN_TYPE_AP
-        || !TO_EDGE_CONN(ap_conn)->socks_request) {
+        || ap_conn->_base.state != CONN_TYPE_AP
+        || ap_conn->socks_request) {
       send_control0_error(conn, ERR_NO_STREAM,
                           "No AP connection found with given ID");
       return 0;
@@ -2091,7 +2081,7 @@
       connection_printf_to_buf(conn,
                                "512 Missing argument to REDIRECTSTREAM\r\n");
     else if (!(ap_conn = get_stream(smartlist_get(args, 0)))
-             || !TO_EDGE_CONN(ap_conn)->socks_request) {
+             || !ap_conn->socks_request) {
       connection_printf_to_buf(conn, "552 Unknown stream \"%s\"\r\n",
                                (char*)smartlist_get(args, 0));
     } else {
@@ -2114,16 +2104,13 @@
       return 0;
   }
 
-  {
-    edge_connection_t *ap = TO_EDGE_CONN(ap_conn);
-    strlcpy(ap->socks_request->address, new_addr,
-            sizeof(ap->socks_request->address));
-    if (new_port)
-      ap->socks_request->port = new_port;
-    tor_free(new_addr);
-    send_control_done(conn);
-    return 0;
-  }
+  strlcpy(ap_conn->socks_request->address, new_addr,
+          sizeof(ap_conn->socks_request->address));
+  if (new_port)
+    ap_conn->socks_request->port = new_port;
+  tor_free(new_addr);
+  send_control_done(conn);
+  return 0;
 }
 
 /** Called when we get a CLOSESTREAM command; try to close the named stream
@@ -2132,7 +2119,7 @@
 handle_control_closestream(control_connection_t *conn, uint32_t len,
                            const char *body)
 {
-  connection_t *ap_conn=NULL;
+  edge_connection_t *ap_conn=NULL;
   uint8_t reason=0;
 
   if (STATE_IS_V0(conn->_base.state)) {
@@ -2146,8 +2133,8 @@
     reason = *(uint8_t*)(body+4);
 
     if (!(ap_conn = connection_get_by_global_id(conn_id))
-        || ap_conn->state != CONN_TYPE_AP
-        || !TO_EDGE_CONN(ap_conn)->socks_request) {
+        || ap_conn->_base.state != CONN_TYPE_AP
+        || ap_conn->socks_request) {
       send_control0_error(conn, ERR_NO_STREAM,
                           "No AP connection found with given ID");
       return 0;
@@ -2179,7 +2166,7 @@
       return 0;
   }
 
-  connection_mark_unattached_ap(TO_EDGE_CONN(ap_conn), reason);
+  connection_mark_unattached_ap(ap_conn, reason);
   send_control_done(conn);
   return 0;
 }
@@ -2190,7 +2177,7 @@
 handle_control_closecircuit(control_connection_t *conn, uint32_t len,
                             const char *body)
 {
-  circuit_t *circ = NULL;
+  origin_circuit_t *circ = NULL;
   int safe = 0;
 
   if (STATE_IS_V0(conn->_base.state)) {
@@ -2234,9 +2221,8 @@
       return 0;
   }
 
-  if (!safe || !CIRCUIT_IS_ORIGIN(circ) ||
-      !TO_ORIGIN_CIRCUIT(circ)->p_streams) {
-    circuit_mark_for_close(circ, END_CIRC_REASON_NONE);
+  if (!safe || !circ->p_streams) {
+    circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NONE);
   }
 
   send_control_done(conn);
@@ -2635,7 +2621,7 @@
     size_t path_len = strlen(path);
     msg = tor_malloc(1+4+path_len+1); /* event, circid, path, NUL. */
     msg[0] = (uint8_t) tp;
-    set_uint32(msg+1, htonl(circ->_base.global_identifier));
+    set_uint32(msg+1, htonl(circ->global_identifier));
     strlcpy(msg+5,path,path_len+1);
 
     send_control0_event(EVENT_CIRCUIT_STATUS, (uint32_t)(path_len+6), msg);
@@ -2656,7 +2642,7 @@
       }
     send_control1_event(EVENT_CIRCUIT_STATUS,
                         "650 CIRC %lu %s %s\r\n",
-                        (unsigned long)circ->_base.global_identifier,
+                        (unsigned long)circ->global_identifier,
                         status, path);
   }
   tor_free(path);
@@ -2703,7 +2689,7 @@
     len = strlen(buf);
     msg = tor_malloc(5+len+1);
     msg[0] = (uint8_t) tp;
-    set_uint32(msg+1, htonl(conn->_base.global_identifier));
+    set_uint32(msg+1, htonl(conn->global_identifier));
     strlcpy(msg+5, buf, len+1);
 
     send_control0_event(EVENT_STREAM_STATUS, (uint32_t)(5+len+1), msg);
@@ -2712,6 +2698,7 @@
   if (EVENT_IS_INTERESTING1(EVENT_STREAM_STATUS)) {
     const char *status;
     circuit_t *circ;
+    origin_circuit_t *origin_circ = NULL;
     switch (tp)
       {
       case STREAM_EVENT_SENT_CONNECT: status = "SENTCONNECT"; break;
@@ -2727,10 +2714,13 @@
         return 0;
       }
     circ = circuit_get_by_edge_conn(conn);
+    if (circ && CIRCUIT_IS_ORIGIN(circ))
+      origin_circ = TO_ORIGIN_CIRCUIT(circ);
     send_control1_event(EVENT_STREAM_STATUS,
                         "650 STREAM %lu %s %lu %s\r\n",
-                        (unsigned long)conn->_base.global_identifier, status,
-                        circ?(unsigned long)circ->global_identifier : 0ul,
+                        (unsigned long)conn->global_identifier, status,
+                        origin_circ?
+                            (unsigned long)origin_circ->global_identifier : 0ul,
                         buf);
     /* XXX need to specify its intended exit, etc? */
   }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2006-07-28 13:52:36 UTC (rev 6932)
+++ tor/trunk/src/or/or.h	2006-07-28 15:11:11 UTC (rev 6933)
@@ -606,7 +606,7 @@
 
   uint8_t type; /**< What kind of connection is this? */
   uint8_t state; /**< Current state of this connection. */
-  uint8_t purpose; /**< Only used for DIR and EXIT types currently. */
+  uint8_t purpose; /**< Only used for DIR and EXIT types currently. !!! */
   unsigned wants_to_read:1; /**< Boolean: should we start reading again once
                             * the bandwidth throttler allows it? */
   unsigned wants_to_write:1; /**< Boolean: should we start writing again once
@@ -619,12 +619,12 @@
                          * connections.  Set once we've set the stream end,
                          * and check in circuit_about_to_close_connection(). */
   /** For control connections only. If set, we send extended info with control
-   * events as appropriate. */
+   * events as appropriate. !!!! */
   unsigned int control_events_are_extended:1;
-  /** Used for OR conns that shouldn't get any new circs attached to them. */
+  /** Used for OR conns that shouldn't get any new circs attached to them. !!*/
   unsigned int or_is_obsolete:1;
   /** For AP connections only. If 1, and we fail to reach the chosen exit,
-   * stop requiring it. */
+   * stop requiring it. !!! */
   unsigned int chosen_exit_optional:1;
 
   int s; /**< Our socket; -1 if this connection is closed. */
@@ -632,18 +632,22 @@
   struct event *read_event; /**< Libevent event structure. */
   struct event *write_event; /**< Libevent event structure. */
   buf_t *inbuf; /**< Buffer holding data read over this connection. */
-  int inbuf_reached_eof; /**< Boolean: did read() return 0 on this conn? */
-  time_t timestamp_lastread; /**< When was the last time poll() said we could
+  int inbuf_reached_eof; /**< Boolean: did read() return 0 on this conn?
+                          * (!!!bitfield?)
+                          */
+  time_t timestamp_lastread; /**< When was the last time libevent said we could
                               * read? */
 
   buf_t *outbuf; /**< Buffer holding data to write over this connection. */
   size_t outbuf_flushlen; /**< How much data should we try to flush from the
                            * outbuf? */
-  time_t timestamp_lastwritten; /**< When was the last time poll() said we
+  time_t timestamp_lastwritten; /**< When was the last time libevent said we
                                  * could write? */
 
   time_t timestamp_created; /**< When was this connection_t created? */
-  time_t timestamp_lastempty; /**< When was the outbuf last completely empty?*/
+  time_t timestamp_lastempty; /**< When was the outbuf last completely empty?
+                               * !!!!
+                               */
 
   uint32_t addr; /**< IP of the other side of the connection; used to identify
                   * routers, along with port. */
@@ -658,9 +662,6 @@
   char *address; /**< FQDN (or IP) of the guy on the other end.
                   * strdup into this, because free_connection frees it. */
 
-  /** Quasi-global identifier for this connection; used for control.c */
-  /* XXXX NM This can get re-used after 2**32 circuits. */
-  uint32_t global_identifier;
 } connection_t;
 
 /** Subtype of connection_t for an "OR connection" -- that is, one that speaks
@@ -724,6 +725,10 @@
   uint16_t stream_id; /**< The stream ID used for this edge connection on its
                        * circuit */
 
+  /** Quasi-global identifier for this connection; used for control.c */
+  /* XXXX NM This can get re-used after 2**32 streams */
+  uint32_t global_identifier;
+
   char rend_query[REND_SERVICE_ID_LEN+1]; /**< What rendezvous service are we
                                            * querying for? (AP only) */
 } edge_connection_t;
@@ -1186,10 +1191,6 @@
   const char *marked_for_close_file; /**< For debugging: in which file was this
                                       * circuit marked for close? */
 
-  /** Quasi-global identifier for this circuit; used for control.c */
-  /* XXXX NM This can get re-used after 2**32 circuits. */
-  uint32_t global_identifier;
-
   struct circuit_t *next; /**< Next circuit in linked list. */
 } circuit_t;
 
@@ -1234,6 +1235,10 @@
    * construct a new AP stream originating at this circuit. */
   uint16_t next_stream_id;
 
+  /** Quasi-global identifier for this circuit; used for control.c */
+  /* XXXX NM This can get re-used after 2**32 circuits. */
+  uint32_t global_identifier;
+
 } origin_circuit_t;
 
 /** An or_circuit_t holds information needed to implement a circuit at an
@@ -1694,7 +1699,7 @@
 int circuit_id_used_on_conn(uint16_t circ_id, or_connection_t *conn);
 circuit_t *circuit_get_by_edge_conn(edge_connection_t *conn);
 void circuit_unlink_all_from_or_conn(or_connection_t *conn, int reason);
-circuit_t *circuit_get_by_global_id(uint32_t id);
+origin_circuit_t *circuit_get_by_global_id(uint32_t id);
 origin_circuit_t *circuit_get_by_rend_query_and_purpose(const char *rend_query,
                                                         uint8_t purpose);
 origin_circuit_t *circuit_get_next_by_pk_and_purpose(origin_circuit_t *start,
@@ -1830,7 +1835,7 @@
 
 or_connection_t *connection_or_exact_get_by_addr_port(uint32_t addr,
                                                    uint16_t port);
-connection_t *connection_get_by_global_id(uint32_t id);
+edge_connection_t *connection_get_by_global_id(uint32_t id);
 
 connection_t *connection_get_by_type(int type);
 connection_t *connection_get_by_type_purpose(int type, int purpose);