Commit b384c5a1 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

bugfix: do directory_send_command only after we've established a socket

also many comments, cleaning, etc


svn:r1823
parent d18528a2
Loading
Loading
Loading
Loading
+5 −2
Changes for src/or/circuit.c: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
/* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
/* Copyright 2001 Matej Pfajfar, 2001-2004 Roger Dingledine. */
/* See LICENSE for licensing information */
/* $Id$ */

@@ -37,7 +37,10 @@ char *circuit_state_to_string[] = {

/********* END VARIABLES ************/

void circuit_add(circuit_t *circ) {
/* add 'circ' to the global list of circuits. This is called only from
 * within circuit_new.
 */
static void circuit_add(circuit_t *circ) {
  if(!global_circuitlist) { /* first one */
    global_circuitlist = circ;
    circ->next = NULL;
+20 −1
Changes for src/or/connection.c: 20 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

extern or_options_t options; /* command-line and config-file options */

/* Array of strings to make conn->type human-readable */
char *conn_type_to_string[] = {
  "",            /* 0 */
  "OP listener", /* 1 */
@@ -23,6 +24,7 @@ char *conn_type_to_string[] = {
  "CPU worker",  /* 11 */
};

/* Array of string arrays to make {conn->type,conn->state} human-readable */
char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
  { NULL }, /* no type associated with 0 */
  { NULL }, /* op listener, obsolete */
@@ -72,6 +74,19 @@ static int connection_receiver_bucket_should_increase(connection_t *conn);

/**************************************************************/

/* 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 'type'. Set conn->s and conn->poll_index to
 * -1 to signify they are not yet assigned.
 *
 * If conn is not a listener type, allocate buffers for it. If it's
 * an AP type, allocate space to store the socks_request.
 *
 * Assign a pseudorandom next_circ_id between 0 and 2**15.
 *
 * Initialize conn's timestamps to now.
 */
connection_t *connection_new(int type) {
  connection_t *conn;
  time_t now = time(NULL);
@@ -99,6 +114,10 @@ connection_t *connection_new(int type) {
  return conn;
}

/* Deallocate memory used by 'conn'. Deallocate its buffers if necessary,
 * close its socket if necessary, and mark the directory as dirty if conn
 * is an OR or OP connection.
 */
void connection_free(connection_t *conn) {
  tor_assert(conn);
  tor_assert(conn->magic == CONNECTION_MAGIC);
@@ -110,7 +129,7 @@ void connection_free(connection_t *conn) {
  tor_free(conn->address);

  if(connection_speaks_cells(conn)) {
    directory_set_dirty();
    directory_set_dirty(); /* XXX should only do this for an open OR conn */
    if (conn->tls)
      tor_tls_free(conn->tls);
  }
+4 −4
Changes for src/or/connection_or.c: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ int connection_tls_start_handshake(connection_t *conn, int receiving) {
  return 0;
}

/* Move forward with ths tls handshake. If it finishes, hand
/* Move forward with the tls handshake. If it finishes, hand
 * conn to connection_tls_finish_handshake().
 *
 * Return -1 if conn is broken, else return 0.
@@ -221,9 +221,9 @@ int connection_tls_continue_handshake(connection_t *conn) {
 *
 * Make sure we are happy with the person we just handshaked with:
 * If it's an OP (that is, it has no certificate), make sure I'm an OR.
 * If it's an OR (is has a certificate), make sure it has a recognized
 * nickname, its cert is signed by the identity key of that nickname;
 * if I initiated the connection, make sure it's the right guy, and if
 * If it's an OR (it has a certificate), make sure it has a recognized
 * nickname, and its cert is signed by the identity key of that nickname.
 * If I initiated the connection, make sure it's the right guy; and if
 * he initiated the connection, make sure he's not already connected.
 *
 * If he initiated the conn, also initialize conn from the information
+1 −1
Changes for src/or/cpuworker.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@ int cpuworker_main(void *data) {

    if(recv(fd, &question_type, 1, 0) != 1) {
//      log_fn(LOG_ERR,"read type failed. Exiting.");
      log_fn(LOG_INFO,"cpuworker exiting because tor process died.");
      log_fn(LOG_INFO,"cpuworker exiting because tor process closed connection (either rotated keys or died).");
      goto end;
    }
    tor_assert(question_type == CPUWORKER_TASK_ONION);
+7 −5
Changes for src/or/directory.c: 7 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -75,9 +75,6 @@ void directory_initiate_command(routerinfo_t *router, int purpose,

  conn->purpose = purpose;

  /* queue the command on the outbuf */
  directory_send_command(conn, purpose, payload, payload_len);

  /* give it an initial state */
  conn->state = DIR_CONN_STATE_CONNECTING;

@@ -93,6 +90,9 @@ void directory_initiate_command(routerinfo_t *router, int purpose,
        conn->state = DIR_CONN_STATE_CLIENT_SENDING; /* start flushing conn */
        /* fall through */
      case 0:
        /* queue the command on the outbuf */
        directory_send_command(conn, purpose, payload, payload_len);

        connection_watch_events(conn, POLLIN | POLLOUT | POLLERR);
        /* writable indicates finish, readable indicates broken link,
           error indicates broken link in windowsland. */
@@ -111,7 +111,9 @@ void directory_initiate_command(routerinfo_t *router, int purpose,

    conn->state = DIR_CONN_STATE_CLIENT_SENDING;
    connection_add(conn);
    connection_start_reading(conn);
    /* queue the command on the outbuf */
    directory_send_command(conn, purpose, payload, payload_len);
    connection_watch_events(conn, POLLIN | POLLOUT | POLLERR);
  }
}

@@ -286,7 +288,7 @@ int connection_dir_process_inbuf(connection_t *conn) {
          log_fn(LOG_WARN,"http status 400 (bad request) response from dirserver. Malformed server descriptor?");
          break;
        case 403:
          log_fn(LOG_WARN,"http status 403 (unapproved server) response from dirserver. Is your clock skewed? Have you mailed arma your identity fingerprint? Are you using the right key? See README.");
          log_fn(LOG_WARN,"http status 403 (unapproved server) response from dirserver. Is your clock skewed? Have you mailed us your identity fingerprint? Are you using the right key? See README.");

          break;
        default:
Loading