Clarify comment. Use CONN_IS_EDGE more. Try to be more zealous about calling connection_edge_end when things go bad with edge conns in connection.c

svn:r3671
This commit is contained in:
Nick Mathewson 2005-02-23 20:35:26 +00:00
parent 5dd58e27d9
commit 22c38b0f9b
2 changed files with 22 additions and 12 deletions

View File

@ -220,7 +220,7 @@ void connection_about_to_close_connection(connection_t *conn)
assert(conn->marked_for_close); assert(conn->marked_for_close);
if (conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) { if (CONN_IS_EDGE(conn)) {
if (!conn->has_sent_end) { if (!conn->has_sent_end) {
log_fn(LOG_WARN,"Harmless bug: Edge connection hasn't sent end yet?"); log_fn(LOG_WARN,"Harmless bug: Edge connection hasn't sent end yet?");
#ifdef TOR_FRAGILE #ifdef TOR_FRAGILE
@ -903,10 +903,10 @@ loop_again:
if (connection_read_to_buf(conn, &max_to_read) < 0) { if (connection_read_to_buf(conn, &max_to_read) < 0) {
/* There's a read error; kill the connection.*/ /* There's a read error; kill the connection.*/
connection_close_immediate(conn); /* Don't flush; connection is dead. */ connection_close_immediate(conn); /* Don't flush; connection is dead. */
if (conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) { if (CONN_IS_EDGE(conn)) {
connection_edge_end(conn, (char)(connection_state_is_open(conn) ? connection_edge_end(conn, (char)(connection_state_is_open(conn) ?
END_STREAM_REASON_MISC : END_STREAM_REASON_CONNECTFAILED), END_STREAM_REASON_MISC : END_STREAM_REASON_CONNECTFAILED),
conn->cpath_layer); conn->cpath_layer);
} }
connection_mark_for_close(conn); connection_mark_for_close(conn);
return -1; return -1;
@ -1073,7 +1073,8 @@ int connection_handle_write(connection_t *conn) {
if (connection_state_is_connecting(conn)) { if (connection_state_is_connecting(conn)) {
if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) {
log_fn(LOG_WARN,"getsockopt() syscall failed?! Please report to tor-ops."); log_fn(LOG_WARN,"getsockopt() syscall failed?! Please report to tor-ops.");
connection_close_immediate(conn); if (CONN_IS_EDGE(conn))
connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
connection_mark_for_close(conn); connection_mark_for_close(conn);
return -1; return -1;
} }
@ -1081,6 +1082,10 @@ int connection_handle_write(connection_t *conn) {
/* some sort of error, but maybe just inprogress still */ /* some sort of error, but maybe just inprogress still */
if (!ERRNO_IS_CONN_EINPROGRESS(e)) { if (!ERRNO_IS_CONN_EINPROGRESS(e)) {
log_fn(LOG_INFO,"in-progress connect failed. Removing."); log_fn(LOG_INFO,"in-progress connect failed. Removing.");
if (CONN_IS_EDGE(conn))
connection_edge_end(conn, END_STREAM_REASON_CONNECTFAILED,
conn->cpath_layer);
connection_close_immediate(conn); connection_close_immediate(conn);
connection_mark_for_close(conn); connection_mark_for_close(conn);
/* it's safe to pass OPs to router_mark_as_down(), since it just /* it's safe to pass OPs to router_mark_as_down(), since it just
@ -1143,6 +1148,11 @@ int connection_handle_write(connection_t *conn) {
} else { } else {
result = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); result = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen);
if (result < 0) { if (result < 0) {
/* XXXX Is this right? -NM
if (CONN_IS_EDGE(conn))
connection_edge_end(conn, END_STREAM_REASON_MISC,
conn->cpath_layer);
*/
connection_close_immediate(conn); /* Don't flush; connection is dead. */ connection_close_immediate(conn); /* Don't flush; connection is dead. */
conn->has_sent_end = 1; conn->has_sent_end = 1;
connection_mark_for_close(conn); connection_mark_for_close(conn);
@ -1177,7 +1187,7 @@ void connection_write_to_buf(const char *string, size_t len, connection_t *conn)
return; return;
if (write_to_buf(string, len, conn->outbuf) < 0) { if (write_to_buf(string, len, conn->outbuf) < 0) {
if (conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) { if (CONN_IS_EDGE(conn)) {
/* if it failed, it means we have our package/delivery windows set /* if it failed, it means we have our package/delivery windows set
wrong compared to our max outbuf size. close the whole circuit. */ wrong compared to our max outbuf size. close the whole circuit. */
log_fn(LOG_WARN,"write_to_buf failed. Closing circuit (fd %d).", conn->s); log_fn(LOG_WARN,"write_to_buf failed. Closing circuit (fd %d).", conn->s);
@ -1566,7 +1576,7 @@ void assert_connection_ok(connection_t *conn, time_t now)
tor_assert(conn->tls); tor_assert(conn->tls);
} }
if (conn->type != CONN_TYPE_EXIT && conn->type != CONN_TYPE_AP) { if (CONN_IS_EDGE(conn)) {
tor_assert(!conn->stream_id); tor_assert(!conn->stream_id);
tor_assert(!conn->next_stream); tor_assert(!conn->next_stream);
tor_assert(!conn->cpath_layer); tor_assert(!conn->cpath_layer);

View File

@ -64,7 +64,7 @@ int connection_edge_reached_eof(connection_t *conn) {
int connection_edge_process_inbuf(connection_t *conn, int package_partial) { int connection_edge_process_inbuf(connection_t *conn, int package_partial) {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); tor_assert(CONN_IS_EDGE(conn));
switch (conn->state) { switch (conn->state) {
case AP_CONN_STATE_SOCKS_WAIT: case AP_CONN_STATE_SOCKS_WAIT:
@ -105,7 +105,7 @@ int connection_edge_process_inbuf(connection_t *conn, int package_partial) {
* Mark it for close and return 0. * Mark it for close and return 0.
*/ */
int connection_edge_destroy(uint16_t circ_id, connection_t *conn) { int connection_edge_destroy(uint16_t circ_id, connection_t *conn) {
tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); tor_assert(CONN_IS_EDGE(conn));
if (conn->marked_for_close) if (conn->marked_for_close)
return 0; /* already marked; probably got an 'end' */ return 0; /* already marked; probably got an 'end' */
@ -173,7 +173,7 @@ connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer)
*/ */
int connection_edge_finished_flushing(connection_t *conn) { int connection_edge_finished_flushing(connection_t *conn) {
tor_assert(conn); tor_assert(conn);
tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT); tor_assert(CONN_IS_EDGE(conn));
switch (conn->state) { switch (conn->state) {
case AP_CONN_STATE_OPEN: case AP_CONN_STATE_OPEN:
@ -1148,8 +1148,8 @@ connection_exit_connect(connection_t *conn) {
conn->state = EXIT_CONN_STATE_CONNECTING; conn->state = EXIT_CONN_STATE_CONNECTING;
connection_watch_events(conn, EV_WRITE | EV_READ); connection_watch_events(conn, EV_WRITE | EV_READ);
/* writable indicates finish, readable indicates broken link, /* writable indicates finish;
error indicates broken link in windowsland. */ * readable/error indicates broken link in windowsland. */
return; return;
/* case 1: fall through */ /* case 1: fall through */
} }