diff options
author | Roger Dingledine <arma@torproject.org> | 2004-05-09 16:33:04 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-05-09 16:33:04 +0000 |
commit | b384c5a18d7567d0bce7d6c14b820c61843ee987 (patch) | |
tree | df9f2eb9ca01360f962b1079bd276e878b5f6d07 /src | |
parent | d18528a2abb1b8b5af3d8e538ae07318ab479fa5 (diff) | |
download | tor-b384c5a18d7567d0bce7d6c14b820c61843ee987.tar tor-b384c5a18d7567d0bce7d6c14b820c61843ee987.tar.gz |
bugfix: do directory_send_command only after we've established a socket
also many comments, cleaning, etc
svn:r1823
Diffstat (limited to 'src')
-rw-r--r-- | src/or/circuit.c | 7 | ||||
-rw-r--r-- | src/or/connection.c | 21 | ||||
-rw-r--r-- | src/or/connection_or.c | 10 | ||||
-rw-r--r-- | src/or/cpuworker.c | 2 | ||||
-rw-r--r-- | src/or/directory.c | 12 | ||||
-rw-r--r-- | src/or/main.c | 2 | ||||
-rw-r--r-- | src/or/or.h | 1 |
7 files changed, 38 insertions, 17 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index 7643f15df..93b13a852 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -1,4 +1,4 @@ -/* 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; diff --git a/src/or/connection.c b/src/or/connection.c index 0b4e88dd3..75d0981f3 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -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); } diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 85afb0150..3c1b22e54 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -122,7 +122,7 @@ connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *router) { * state to 'connecting' and return. If connect to router succeeds, call * connection_tls_start_handshake() on it. * - * This function is called from router_retry_connections() , for + * This function is called from router_retry_connections(), for * ORs connecting to ORs, and circuit_establish_circuit(), for * OPs connecting to ORs. * @@ -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 diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index f872d1419..d57119f91 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -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); diff --git a/src/or/directory.c b/src/or/directory.c index b26346fb2..85813a834 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -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: diff --git a/src/or/main.c b/src/or/main.c index 17000ab79..5a8ae948c 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -172,9 +172,7 @@ int connection_is_writing(connection_t *conn) { /* Tell the main loop to stop notifying 'conn' of any write events. */ void connection_stop_writing(connection_t *conn) { - tor_assert(conn && conn->poll_index >= 0 && conn->poll_index < nfds); - if(poll_array[conn->poll_index].events & POLLOUT) poll_array[conn->poll_index].events -= POLLOUT; } diff --git a/src/or/or.h b/src/or/or.h index 124ed8974..f5e2475f4 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -674,7 +674,6 @@ void assert_buf_ok(buf_t *buf); /********************************* circuit.c ***************************/ extern char *circuit_state_to_string[]; -void circuit_add(circuit_t *circ); void circuit_remove(circuit_t *circ); circuit_t *circuit_new(uint16_t p_circ_id, connection_t *p_conn); void circuit_close_all_marked(void); |