-/* Copyright 2001,2002,2003 Roger Dingledine, Matej Pfajfar. */
+/* Copyright 2001 Matej Pfajfar, 2001-2004 Roger Dingledine. */
/* See LICENSE for licensing information */
/* $Id$ */
/********* 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;
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 */
"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 */
/**************************************************************/
+/* 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);
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);
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);
}
* 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.
*
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.
*
* 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
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);
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;
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. */
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);
}
}
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:
/* 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;
}
/********************************* 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);