diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-10-20 17:54:43 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-10-20 17:54:43 +0000 |
commit | 8e94097edb05b204cff7772588a3376507b3fd0b (patch) | |
tree | 689c79be5755747580c277c4943171e5e7ade91b /src | |
parent | 12af87539b3380e97a9433930e4fa60cd825c157 (diff) | |
download | tor-8e94097edb05b204cff7772588a3376507b3fd0b.tar.gz tor-8e94097edb05b204cff7772588a3376507b3fd0b.zip |
r9306@Kushana: nickm | 2006-10-20 13:27:43 -0400
Enable reasons for stream events in all cases but CLOSED in about_to_close_connection. That one will take a little longer.
svn:r8778
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection_edge.c | 31 | ||||
-rw-r--r-- | src/or/control.c | 6 | ||||
-rw-r--r-- | src/or/or.h | 14 | ||||
-rw-r--r-- | src/or/relay.c | 14 |
4 files changed, 41 insertions, 24 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 5a415bb04f..04e7b0f2fa 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -49,16 +49,13 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason, } if (!conn->socks_request->has_finished) { - socks5_reply_status_t socksreason = - connection_edge_end_reason_socks5_response(endreason); - if (endreason == END_STREAM_REASON_ALREADY_SOCKS_REPLIED) log_warn(LD_BUG, "Bug: stream (marked at %s:%d) sending two socks replies?", file, line); if (conn->socks_request->command == SOCKS_COMMAND_CONNECT) - connection_ap_handshake_socks_reply(conn, NULL, 0, socksreason); + connection_ap_handshake_socks_reply(conn, NULL, 0, endreason); else connection_ap_handshake_socks_resolved(conn, RESOLVED_TYPE_ERROR, 0, NULL, -1); @@ -421,7 +418,8 @@ connection_ap_expire_beginning(void) if (conn->num_socks_retries < 250) /* avoid overflow */ conn->num_socks_retries++; /* move it back into 'pending' state, and try to attach. */ - if (connection_ap_detach_retriable(conn, TO_ORIGIN_CIRCUIT(circ))<0) { + if (connection_ap_detach_retriable(conn, TO_ORIGIN_CIRCUIT(circ), + END_STREAM_REASON_TIMEOUT)<0) { connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_ATTACH); } } /* end for */ @@ -496,10 +494,10 @@ circuit_discard_optional_exit_enclaves(extend_info_t *info) * Returns -1 on err, 1 on success, 0 on not-yet-sure. */ int -connection_ap_detach_retriable(edge_connection_t *conn, origin_circuit_t *circ) +connection_ap_detach_retriable(edge_connection_t *conn, origin_circuit_t *circ, + int reason) { - control_event_stream_status(conn, STREAM_EVENT_FAILED_RETRIABLE, - END_STREAM_REASON_FIXME_XXXX); + control_event_stream_status(conn, STREAM_EVENT_FAILED_RETRIABLE, reason); conn->_base.timestamp_lastread = time(NULL); if (! get_options()->LeaveStreamsUnattached) { conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT; @@ -1426,10 +1424,12 @@ connection_ap_handshake_process_socks(edge_connection_t *conn) if (socks->replylen) { /* we should send reply back */ log_debug(LD_APP,"reply is already set for us. Using it."); connection_ap_handshake_socks_reply(conn, socks->reply, socks->replylen, - SOCKS5_GENERAL_ERROR); + END_STREAM_REASON_SOCKSPROTOCOL); + } else { log_warn(LD_APP,"Fetching socks handshake failed. Closing."); - connection_ap_handshake_socks_reply(conn, NULL, 0, SOCKS5_GENERAL_ERROR); + connection_ap_handshake_socks_reply(conn, NULL, 0, + END_STREAM_REASON_SOCKSPROTOCOL); } connection_mark_unattached_ap(conn, END_STREAM_REASON_ALREADY_SOCKS_REPLIED); @@ -1761,7 +1761,7 @@ connection_ap_handshake_socks_resolved(edge_connection_t *conn, connection_ap_handshake_socks_reply(conn, buf, replylen, (answer_type == RESOLVED_TYPE_IPV4 || answer_type == RESOLVED_TYPE_IPV6) ? - SOCKS5_SUCCEEDED : SOCKS5_HOST_UNREACHABLE); + 0 : END_STREAM_REASON_RESOLVEFAILED); } /** Send a socks reply to stream <b>conn</b>, using the appropriate @@ -1772,18 +1772,21 @@ connection_ap_handshake_socks_resolved(edge_connection_t *conn, * to conn and return, else reply based on <b>status</b>. * * If <b>reply</b> is undefined, <b>status</b> can't be 0. + * DOCDOC endreason */ void connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply, - size_t replylen, - socks5_reply_status_t status) + size_t replylen, int endreason) { char buf[256]; + socks5_reply_status_t status = + connection_edge_end_reason_socks5_response(endreason); + tor_assert(conn->socks_request); /* make sure it's an AP stream */ control_event_stream_status(conn, status==SOCKS5_SUCCEEDED ? STREAM_EVENT_SUCCEEDED : STREAM_EVENT_FAILED, - END_STREAM_REASON_FIXME_XXXX); + endreason); if (conn->socks_request->has_finished) { log_warn(LD_BUG, "Harmless bug: duplicate calls to " diff --git a/src/or/control.c b/src/or/control.c index 562c7c64ab..6fd88c4ed3 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -2965,6 +2965,12 @@ stream_end_reason_to_string(int reason) case END_STREAM_REASON_CONNRESET: return "CONNRESET"; case END_STREAM_REASON_TORPROTOCOL: return "TORPROTOCOL"; case END_STREAM_REASON_NOTDIRECTORY: return "NOTDIRECTORY"; + + case END_STREAM_REASON_ALREADY_SOCKS_REPLIED: return "INTERNAL"; + case END_STREAM_REASON_CANT_ATTACH: return "CANT_ATTACH"; + case END_STREAM_REASON_NET_UNREACHABLE: return "NET_UNREACHABLE"; + case END_STREAM_REASON_SOCKSPROTOCOL: return "SOCKS_PROTOCOL"; + default: return NULL; } } diff --git a/src/or/or.h b/src/or/or.h index ae116d0440..9c1db0f42d 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -483,10 +483,6 @@ typedef enum { #define END_STREAM_REASON_TORPROTOCOL 13 #define END_STREAM_REASON_NOTDIRECTORY 14 -/* OR this with the argument to control_event_stream_status to indicate that - * the reason came from an END cell. */ -#define END_STREAM_REASON_FLAG_REMOTE 512 - /* These high-numbered end reasons are not part of the official spec, * and are not intended to be put in relay end cells. They are here * to be more informative when sending back socks replies to the @@ -494,6 +490,11 @@ typedef enum { #define END_STREAM_REASON_ALREADY_SOCKS_REPLIED 256 #define END_STREAM_REASON_CANT_ATTACH 257 #define END_STREAM_REASON_NET_UNREACHABLE 258 +#define END_STREAM_REASON_SOCKSPROTOCOL 259 + +/* OR this with the argument to control_event_stream_status to indicate that + * the reason came from an END cell. */ +#define END_STREAM_REASON_FLAG_REMOTE 512 #define RESOLVED_TYPE_HOSTNAME 0 #define RESOLVED_TYPE_IPV4 4 @@ -1966,7 +1967,7 @@ int connection_ap_handshake_send_resolve(edge_connection_t *ap_conn, int connection_ap_make_bridge(char *address, uint16_t port); void connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply, size_t replylen, - socks5_reply_status_t status); + int endreason); void connection_ap_handshake_socks_resolved(edge_connection_t *conn, int answer_type, size_t answer_len, @@ -1982,7 +1983,8 @@ void connection_ap_expire_beginning(void); void connection_ap_attach_pending(void); void circuit_discard_optional_exit_enclaves(extend_info_t *info); int connection_ap_detach_retriable(edge_connection_t *conn, - origin_circuit_t *circ); + origin_circuit_t *circ, + int reason); void addressmap_init(void); void addressmap_clean(time_t now); diff --git a/src/or/relay.c b/src/or/relay.c index f084461c89..2d99453574 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -577,11 +577,14 @@ connection_edge_end_reason_str(int reason) /** Translate <b>reason</b> (as from a relay 'end' cell) into an * appropriate SOCKS5 reply code. + * DODCDOC 0 */ socks5_reply_status_t connection_edge_end_reason_socks5_response(int reason) { switch (reason) { + case 0: + return SOCKS5_SUCCEEDED; case END_STREAM_REASON_MISC: return SOCKS5_GENERAL_ERROR; case END_STREAM_REASON_RESOLVEFAILED: @@ -613,6 +616,8 @@ connection_edge_end_reason_socks5_response(int reason) return SOCKS5_GENERAL_ERROR; case END_STREAM_REASON_NET_UNREACHABLE: return SOCKS5_NET_UNREACHABLE; + case END_STREAM_REASON_SOCKSPROTOCOL: + return SOCKS5_GENERAL_ERROR; default: log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Reason for ending (%d) not recognized; " @@ -701,6 +706,7 @@ connection_edge_process_end_not_open( struct in_addr in; routerinfo_t *exitrouter; int reason = *(cell->payload+RELAY_HEADER_SIZE); + int control_reason = reason | END_STREAM_REASON_FLAG_REMOTE; (void) layer_hint; /* unused */ if (rh->length > 0 && edge_reason_is_retriable(reason) && @@ -749,7 +755,7 @@ connection_edge_process_end_not_open( conn->_base.chosen_exit_optional = 0; tor_free(conn->chosen_exit_name); /* clears it */ } - if (connection_ap_detach_retriable(conn, circ) >= 0) + if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0) return 0; /* else, conn will get closed below */ break; @@ -773,7 +779,7 @@ connection_edge_process_end_not_open( conn->_base.chosen_exit_optional = 0; tor_free(conn->chosen_exit_name); /* clears it */ } - if (connection_ap_detach_retriable(conn, circ) >= 0) + if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0) return 0; /* else, conn will get closed below */ } else { @@ -798,7 +804,7 @@ connection_edge_process_end_not_open( conn->_base.chosen_exit_optional = 0; tor_free(conn->chosen_exit_name); /* clears it */ } - if (connection_ap_detach_retriable(conn, circ) >= 0) + if (connection_ap_detach_retriable(conn, circ, control_reason) >= 0) return 0; /* else, will close below */ break; @@ -874,7 +880,7 @@ connection_edge_process_relay_cell_not_open( circuit_log_path(LOG_INFO,LD_APP,TO_ORIGIN_CIRCUIT(circ)); /* don't send a socks reply to transparent conns */ if (!conn->socks_request->has_finished) - connection_ap_handshake_socks_reply(conn, NULL, 0, SOCKS5_SUCCEEDED); + connection_ap_handshake_socks_reply(conn, NULL, 0, 0); /* handle anything that might have queued */ if (connection_edge_package_raw_inbuf(conn, 1) < 0) { /* (We already sent an end cell if possible) */ |