Commit 115271f6 authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

Implement the common case of ATTACHSTREAM.


svn:r3751
parent d1f790e9
Loading
Loading
Loading
Loading
+6 −4
Changes for doc/TODO: 6 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -72,13 +72,15 @@ N . Implement pending controller features.
    - EXTENDCIRCUIT
R     - revised circ selection stuff.
      - Implement controller interface.
    - ATTACHSTREAM
      - Make streams have an 'unattached and not-automatically-attachable'
    . ATTACHSTREAM
      o Make streams have an 'unattached and not-automatically-attachable'
        state. ("Controller managed.")
      - Add support to put new streams into this state rather than try to
      o Add support to put new streams into this state rather than try to
        attach them automatically.  ("Hidden" config option.)
      o Implement 'attach stream X to circuit Y' logic.
      - Time out never-attached streams.
      - Implement 'attach stream X to circuit Y' logic.
      - If we never get a CONNECTED back, we should put the stream back in
        CONTROLLER_WAIT, not in CIRCUIT_WAIT.
    - Tests for new controller features
R . HTTPS proxy for OR CONNECT stuff. (For outgoing SSL connections to
    other ORs.)
+8 −1
Changes for doc/control-spec.txt: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@ the message.
               [The server didn't have enough of a given resource to
                fulfill a given request.]

        0x000A No such stream

        0x000B No such circuit.

  The rest of the body should be a human-readable description of the error.

  In general, new error codes should only be added when they don't fall under
@@ -182,7 +186,7 @@ the message.

                Status [1 octet]
                   (Sent connect=0,sent resolve=1,succeeded=2,failed=3,
                    closed=4, new=5)
                    closed=4, new connection=5, new resolve request=6)
                Stream ID [4 octets]
                   (Must be unique to Tor process/time)
                Target (NUL-terminated address-port string]
@@ -351,6 +355,9 @@ the message.
  associated with the specified circuit.  Each stream may be associated with
  at most one circuit, and multiple streams may share the same circuit.

  If the circuit ID is 0, responsibility for attaching the given stream is
  returned to Tor.

3.16 POSTDESCRIPTOR (Type 0x000F)

  [Proposal; not finalized]
+16 −0
Changes for src/or/circuitlist.c: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -183,6 +183,22 @@ circuit_free_cpath_node(crypt_path_t *victim) {
  tor_free(victim);
}

/** DOCDOC **/
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 (circ->marked_for_close)
        return NULL;
      else
        return circ;
    }
  }
  return NULL;
}

/** Return a circ such that:
 *  - circ-\>n_circ_id or circ-\>p_circ_id is equal to <b>circ_id</b>, and
 *  - circ is attached to <b>conn</b>, either as p_conn, n-conn, or
+33 −16
Changes for src/or/circuituse.c: 33 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -980,6 +980,36 @@ consider_recording_trackhost(connection_t *conn, circuit_t *circ) {
                      time(NULL) + options->TrackHostExitsExpire);
}

/* DOCDOC. Return as for connection_ap_handshake_attach_chosen_circuit. */
int
connection_ap_handshake_attach_chosen_circuit(connection_t *conn,
                                              circuit_t *circ)
{
  tor_assert(conn);
  tor_assert(conn->type == CONN_TYPE_AP);
  tor_assert(conn->state == AP_CONN_STATE_CIRCUIT_WAIT ||
             conn->state == AP_CONN_STATE_CONTROLLER_WAIT);
  tor_assert(conn->socks_request);
  tor_assert(circ);

  conn->state = AP_CONN_STATE_CIRCUIT_WAIT;

  if (!circ->timestamp_dirty)
    circ->timestamp_dirty = time(NULL);

  link_apconn_to_circ(conn, circ);
  tor_assert(conn->socks_request);
  if (conn->socks_request->command == SOCKS_COMMAND_CONNECT) {
    consider_recording_trackhost(conn, circ);
    connection_ap_handshake_send_begin(conn, circ);
  } else {
    connection_ap_handshake_send_resolve(conn, circ);
  }

  return 1;
}


/** Try to find a safe live circuit for CONN_TYPE_AP connection conn. If
 * we don't find one: if conn cannot be handled by any known nodes,
 * warn and return -1 (conn needs to die);
@@ -1024,27 +1054,14 @@ int connection_ap_handshake_attach_circuit(connection_t *conn) {
    if (retval < 1)
      return retval;

    /* We have found a suitable circuit for our conn. Hurray. */
    tor_assert(circ);

    log_fn(LOG_DEBUG,"Attaching apconn to general circ %d (stream %d sec old).",
    log_fn(LOG_DEBUG,"Attaching apconn to circ %d (stream %d sec old).",
           circ->n_circ_id, conn_age);
    /* here, print the circ's path. so people can figure out which circs are sucking. */
    circuit_log_path(LOG_INFO,circ);

    if (!circ->timestamp_dirty)
      circ->timestamp_dirty = time(NULL);

    link_apconn_to_circ(conn, circ);
    tor_assert(conn->socks_request);
    if (conn->socks_request->command == SOCKS_COMMAND_CONNECT) {
      consider_recording_trackhost(conn, circ);
      connection_ap_handshake_send_begin(conn, circ);
    } else {
      connection_ap_handshake_send_resolve(conn, circ);
    }
    /* We have found a suitable circuit for our conn. Hurray. */
    return connection_ap_handshake_attach_chosen_circuit(conn, circ);

    return 1;
  } else { /* we're a rendezvous conn */
    circuit_t *rendcirc=NULL, *introcirc=NULL;

+4 −0
Changes for src/or/config.c: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ static config_var_t config_vars[] = {
  VAR("SysLog",              LINELIST_S, OldLogOptions,      NULL),
  OBSOLETE("TrafficShaping"),
  VAR("User",                STRING,   User,                 NULL),
  VAR("__ManageConnections", BOOL,     ManageConnections,    "1"),
  { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
};
#undef VAR
@@ -1155,6 +1156,9 @@ config_dump_options(or_options_t *options, int minimal)
    if (config_vars[i].type == CONFIG_TYPE_OBSOLETE ||
        config_vars[i].type == CONFIG_TYPE_LINELIST_S)
      continue;
    /* Don't save 'hidden' control variables. */
    if (!strcmpstart(config_vars[i].name, "__"))
      continue;
    if (minimal && option_is_same(options, defaults, config_vars[i].name))
      continue;
    line = config_get_assigned_option(options, config_vars[i].name);
Loading