Commit 5227395a authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

r6922@Kushana: nickm | 2006-07-26 16:32:24 -0400

 Rename some fields, compress a bitfield, and document some structs and fields


svn:r6919
parent dd779d99
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -420,12 +420,12 @@ circuit_free_cpath_node(crypt_path_t *victim)
 * of information about circuit <b>circ</b>.
 */
static void
circuit_dump_details(int severity, circuit_t *circ, int poll_index,
circuit_dump_details(int severity, circuit_t *circ, int conn_array_index,
                     const char *type, int this_circid, int other_circid)
{
  log(severity, LD_CIRC, "Conn %d has %s circuit: circID %d (other side %d), "
      "state %d (%s), born %d:",
      poll_index, type, this_circid, other_circid, circ->state,
      conn_array_index, type, this_circid, other_circid, circ->state,
      circuit_state_to_string(circ->state), (int)circ->timestamp_created);
  if (CIRCUIT_IS_ORIGIN(circ)) { /* circ starts at this node */
    circuit_log_path(severity, LD_CIRC, TO_ORIGIN_CIRCUIT(circ));
@@ -451,26 +451,26 @@ circuit_dump_by_conn(connection_t *conn, int severity)

    if (! CIRCUIT_IS_ORIGIN(circ) && TO_OR_CIRCUIT(circ)->p_conn &&
        TO_CONN(TO_OR_CIRCUIT(circ)->p_conn) == conn)
      circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
      circuit_dump_details(severity, circ, conn->conn_array_index, "App-ward",
                           p_circ_id, n_circ_id);
    if (CIRCUIT_IS_ORIGIN(circ)) {
      for (tmpconn=TO_ORIGIN_CIRCUIT(circ)->p_streams; tmpconn;
           tmpconn=tmpconn->next_stream) {
        if (TO_CONN(tmpconn) == conn) {
          circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
                               p_circ_id, n_circ_id);
          circuit_dump_details(severity, circ, conn->conn_array_index,
                               "App-ward", p_circ_id, n_circ_id);
        }
      }
    }
    if (circ->n_conn && TO_CONN(circ->n_conn) == conn)
      circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
      circuit_dump_details(severity, circ, conn->conn_array_index, "Exit-ward",
                           n_circ_id, p_circ_id);
    if (! CIRCUIT_IS_ORIGIN(circ)) {
      for (tmpconn=TO_OR_CIRCUIT(circ)->n_streams; tmpconn;
           tmpconn=tmpconn->next_stream) {
        if (TO_CONN(tmpconn) == conn) {
          circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
                               n_circ_id, p_circ_id);
          circuit_dump_details(severity, circ, conn->conn_array_index,
                               "Exit-ward", n_circ_id, p_circ_id);
        }
      }
    }
@@ -480,7 +480,7 @@ circuit_dump_by_conn(connection_t *conn, int severity)
        conn->type == CONN_TYPE_OR &&
        !memcmp(TO_OR_CONN(conn)->identity_digest, circ->n_conn_id_digest,
                DIGEST_LEN)) {
      circuit_dump_details(severity, circ, conn->poll_index,
      circuit_dump_details(severity, circ, conn->conn_array_index,
                           (circ->state == CIRCUIT_STATE_OPEN &&
                            !CIRCUIT_IS_ORIGIN(circ)) ?
                             "Endpoint" : "Pending",
+5 −5
Original line number Diff line number Diff line
@@ -982,13 +982,13 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
    if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_GENERAL) {
      if (conn->chosen_exit_name) {
        routerinfo_t *r;
        int opt = conn->chosen_exit_optional;
        int opt = conn->_base.chosen_exit_optional;
        if (!(r = router_get_by_nickname(conn->chosen_exit_name, 1))) {
          log_fn(opt ? LOG_INFO : LOG_WARN, LD_APP,
                 "Requested exit point '%s' is not known. %s.",
                 conn->chosen_exit_name, opt ? "Trying others" : "Closing");
          if (opt) {
            conn->chosen_exit_optional = 0;
            conn->_base.chosen_exit_optional = 0;
            tor_free(conn->chosen_exit_name);
            return 0;
          }
@@ -1173,13 +1173,13 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)

    if (conn->chosen_exit_name) {
      routerinfo_t *router = router_get_by_nickname(conn->chosen_exit_name, 1);
      int opt = conn->chosen_exit_optional;
      int opt = conn->_base.chosen_exit_optional;
      if (!router) {
        log_fn(opt ? LOG_INFO : LOG_WARN, LD_APP,
               "Requested exit point '%s' is not known. %s.",
               conn->chosen_exit_name, opt ? "Trying others" : "Closing");
        if (opt) {
          conn->chosen_exit_optional = 0;
          conn->_base.chosen_exit_optional = 0;
          tor_free(conn->chosen_exit_name);
          return 0;
        }
@@ -1190,7 +1190,7 @@ connection_ap_handshake_attach_circuit(edge_connection_t *conn)
               "Requested exit point '%s' would refuse request. %s.",
               conn->chosen_exit_name, opt ? "Trying others" : "Closing");
        if (opt) {
          conn->chosen_exit_optional = 0;
          conn->_base.chosen_exit_optional = 0;
          tor_free(conn->chosen_exit_name);
          return 0;
        }
+3 −3
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ conn_state_to_string(int type, int state)
/** Allocate space for a new connection_t. This function just initializes
 * conn; you must call connection_add() to link it into the main array.
 *
 * Set conn-\>type to <b>type</b>. Set conn-\>s and conn-\>poll_index to
 * Set conn-\>type to <b>type</b>. Set conn-\>s and conn-\>conn_array_index to
 * -1 to signify they are not yet assigned.
 *
 * If conn is not a listener type, allocate buffers for it. If it's
@@ -191,7 +191,7 @@ connection_new(int type)
  conn = tor_malloc_zero(length);
  conn->magic = magic;
  conn->s = -1; /* give it a default of 'not used' */
  conn->poll_index = -1; /* also default to 'not used' */
  conn->conn_array_index = -1; /* also default to 'not used' */
  conn->global_identifier = n_connections_allocated++;

  conn->type = type;
@@ -2182,7 +2182,7 @@ assert_connection_ok(connection_t *conn, time_t now)
  if (conn->hold_open_until_flushed)
    tor_assert(conn->marked_for_close);

  /* XXX check: wants_to_read, wants_to_write, s, poll_index,
  /* XXX check: wants_to_read, wants_to_write, s, conn_array_index,
   * marked_for_close. */

  /* buffers */
+1 −1
Original line number Diff line number Diff line
@@ -1139,7 +1139,7 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn,
             routers with this nickname */
          conn->chosen_exit_name =
            tor_strdup(hex_str(r->cache_info.identity_digest, DIGEST_LEN));
          conn->chosen_exit_optional = 1;
          conn->_base.chosen_exit_optional = 1;
        }
      }

+29 −31
Original line number Diff line number Diff line
@@ -50,13 +50,12 @@ static time_t time_to_fetch_directory = 0;
/** When do we next download a running-routers summary? */
static time_t time_to_fetch_running_routers = 0;

/** Array of all open connections; each element corresponds to the element of
 * poll_array in the same position.  The first nfds elements are valid. */
/** Array of all open connections.  The first n_conns elements are valid. */
static connection_t *connection_array[MAXCONNECTIONS+1] =
        { NULL };
static smartlist_t *closeable_connection_lst = NULL;

static int nfds=0; /**< Number of connections currently active. */
static int n_conns=0; /**< Number of connections currently active. */

/** We set this to 1 when we've opened a circuit, so we can print a log
 * entry to inform the user that Tor is working. */
@@ -121,8 +120,7 @@ static char* nt_strerror(uint32_t errnum);
/****************************************************************************
*
* This section contains accessors and other methods on the connection_array
* and poll_array variables (which are global within this file and unavailable
* outside it).
* variables (which are global within this file and unavailable outside it).
*
****************************************************************************/

@@ -136,15 +134,15 @@ connection_add(connection_t *conn)
  tor_assert(conn);
  tor_assert(conn->s >= 0);

  if (nfds >= get_options()->_ConnLimit-1) {
  if (n_conns >= get_options()->_ConnLimit-1) {
    log_warn(LD_NET,"Failing because we have %d connections already. Please "
             "raise your ulimit -n.", nfds);
             "raise your ulimit -n.", n_conns);
    return -1;
  }

  tor_assert(conn->poll_index == -1); /* can only connection_add once */
  conn->poll_index = nfds;
  connection_array[nfds] = conn;
  tor_assert(conn->conn_array_index == -1); /* can only connection_add once */
  conn->conn_array_index = n_conns;
  connection_array[n_conns] = conn;

  conn->read_event = tor_malloc_zero(sizeof(struct event));
  conn->write_event = tor_malloc_zero(sizeof(struct event));
@@ -153,10 +151,10 @@ connection_add(connection_t *conn)
  event_set(conn->write_event, conn->s, EV_WRITE|EV_PERSIST,
            conn_write_callback, conn);

  nfds++;
  n_conns++;

  log_debug(LD_NET,"new conn type %s, socket %d, nfds %d.",
            conn_type_to_string(conn->type), conn->s, nfds);
  log_debug(LD_NET,"new conn type %s, socket %d, n_conns %d.",
            conn_type_to_string(conn->type), conn->s, n_conns);

  return 0;
}
@@ -171,24 +169,24 @@ connection_remove(connection_t *conn)
  int current_index;

  tor_assert(conn);
  tor_assert(nfds>0);
  tor_assert(n_conns>0);

  log_debug(LD_NET,"removing socket %d (type %s), nfds now %d",
            conn->s, conn_type_to_string(conn->type), nfds-1);
  log_debug(LD_NET,"removing socket %d (type %s), n_conns now %d",
            conn->s, conn_type_to_string(conn->type), n_conns-1);

  tor_assert(conn->poll_index >= 0);
  current_index = conn->poll_index;
  if (current_index == nfds-1) { /* this is the end */
    nfds--;
  tor_assert(conn->conn_array_index >= 0);
  current_index = conn->conn_array_index;
  if (current_index == n_conns-1) { /* this is the end */
    n_conns--;
    return 0;
  }

  connection_unregister(conn);

  /* replace this one with the one at the end */
  nfds--;
  connection_array[current_index] = connection_array[nfds];
  connection_array[current_index]->poll_index = current_index;
  n_conns--;
  connection_array[current_index] = connection_array[n_conns];
  connection_array[current_index]->conn_array_index = current_index;

  return 0;
}
@@ -243,7 +241,7 @@ int
connection_in_array(connection_t *conn)
{
  int i;
  for (i=0; i<nfds; ++i) {
  for (i=0; i<n_conns; ++i) {
    if (conn==connection_array[i])
      return 1;
  }
@@ -258,7 +256,7 @@ void
get_connection_array(connection_t ***array, int *n)
{
  *array = connection_array;
  *n = nfds;
  *n = n_conns;
}

/** Set the event mask on <b>conn</b> to <b>events</b>.  (The event
@@ -382,10 +380,10 @@ close_closeable_connections(void)
  int i;
  for (i = 0; i < smartlist_len(closeable_connection_lst); ) {
    connection_t *conn = smartlist_get(closeable_connection_lst, i);
    if (conn->poll_index < 0) {
    if (conn->conn_array_index < 0) {
      connection_unlink(conn, 0); /* blow it away right now */
    } else {
      if (!conn_close_if_marked(conn->poll_index))
      if (!conn_close_if_marked(conn->conn_array_index))
        ++i;
    }
  }
@@ -893,11 +891,11 @@ run_scheduled_events(time_t now)
    circuit_build_needed_circs(now);

  /** 5. We do housekeeping for each connection... */
  for (i=0;i<nfds;i++) {
  for (i=0;i<n_conns;i++) {
    run_connection_housekeeping(i, now);
  }
  if (time_to_shrink_buffers < now) {
    for (i=0;i<nfds;i++) {
    for (i=0;i<n_conns;i++) {
      connection_t *conn = connection_array[i];
      if (conn->outbuf)
        buf_shrink(conn->outbuf);
@@ -1306,7 +1304,7 @@ dumpmemusage(int severity)
  log(severity, LD_GENERAL,
      "In buffers: "U64_FORMAT" used/"U64_FORMAT" allocated (%d conns).",
      U64_PRINTF_ARG(buf_total_used), U64_PRINTF_ARG(buf_total_alloc),
      nfds);
      n_conns);
  log(severity, LD_GENERAL, "In rephist: "U64_FORMAT" used by %d Tors.",
      U64_PRINTF_ARG(rephist_total_alloc), rephist_total_num);
  dump_routerlist_mem_usage(severity);
@@ -1324,7 +1322,7 @@ dumpstats(int severity)

  log(severity, LD_GENERAL, "Dumping stats:");

  for (i=0;i<nfds;i++) {
  for (i=0;i<n_conns;i++) {
    conn = connection_array[i];
    log(severity, LD_GENERAL,
        "Conn %d (socket %d) type %d (%s), state %d (%s), created %d secs ago",
Loading