Skip to content
Snippets Groups Projects
Commit 8e94097e authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

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
parent 12af8753
No related branches found
No related tags found
No related merge requests found
...@@ -49,16 +49,13 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason, ...@@ -49,16 +49,13 @@ _connection_mark_unattached_ap(edge_connection_t *conn, int endreason,
} }
if (!conn->socks_request->has_finished) { 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) if (endreason == END_STREAM_REASON_ALREADY_SOCKS_REPLIED)
log_warn(LD_BUG, log_warn(LD_BUG,
"Bug: stream (marked at %s:%d) sending two socks replies?", "Bug: stream (marked at %s:%d) sending two socks replies?",
file, line); file, line);
if (conn->socks_request->command == SOCKS_COMMAND_CONNECT) 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 else
connection_ap_handshake_socks_resolved(conn, RESOLVED_TYPE_ERROR, connection_ap_handshake_socks_resolved(conn, RESOLVED_TYPE_ERROR,
0, NULL, -1); 0, NULL, -1);
...@@ -421,7 +418,8 @@ connection_ap_expire_beginning(void) ...@@ -421,7 +418,8 @@ connection_ap_expire_beginning(void)
if (conn->num_socks_retries < 250) /* avoid overflow */ if (conn->num_socks_retries < 250) /* avoid overflow */
conn->num_socks_retries++; conn->num_socks_retries++;
/* move it back into 'pending' state, and try to attach. */ /* 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); connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_ATTACH);
} }
} /* end for */ } /* end for */
...@@ -496,10 +494,10 @@ circuit_discard_optional_exit_enclaves(extend_info_t *info) ...@@ -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. * Returns -1 on err, 1 on success, 0 on not-yet-sure.
*/ */
int 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, control_event_stream_status(conn, STREAM_EVENT_FAILED_RETRIABLE, reason);
END_STREAM_REASON_FIXME_XXXX);
conn->_base.timestamp_lastread = time(NULL); conn->_base.timestamp_lastread = time(NULL);
if (! get_options()->LeaveStreamsUnattached) { if (! get_options()->LeaveStreamsUnattached) {
conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT; conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT;
...@@ -1426,10 +1424,12 @@ connection_ap_handshake_process_socks(edge_connection_t *conn) ...@@ -1426,10 +1424,12 @@ connection_ap_handshake_process_socks(edge_connection_t *conn)
if (socks->replylen) { /* we should send reply back */ if (socks->replylen) { /* we should send reply back */
log_debug(LD_APP,"reply is already set for us. Using it."); log_debug(LD_APP,"reply is already set for us. Using it.");
connection_ap_handshake_socks_reply(conn, socks->reply, socks->replylen, connection_ap_handshake_socks_reply(conn, socks->reply, socks->replylen,
SOCKS5_GENERAL_ERROR); END_STREAM_REASON_SOCKSPROTOCOL);
} else { } else {
log_warn(LD_APP,"Fetching socks handshake failed. Closing."); 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, connection_mark_unattached_ap(conn,
END_STREAM_REASON_ALREADY_SOCKS_REPLIED); END_STREAM_REASON_ALREADY_SOCKS_REPLIED);
...@@ -1761,7 +1761,7 @@ connection_ap_handshake_socks_resolved(edge_connection_t *conn, ...@@ -1761,7 +1761,7 @@ connection_ap_handshake_socks_resolved(edge_connection_t *conn,
connection_ap_handshake_socks_reply(conn, buf, replylen, connection_ap_handshake_socks_reply(conn, buf, replylen,
(answer_type == RESOLVED_TYPE_IPV4 || (answer_type == RESOLVED_TYPE_IPV4 ||
answer_type == RESOLVED_TYPE_IPV6) ? 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 /** 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, ...@@ -1772,18 +1772,21 @@ connection_ap_handshake_socks_resolved(edge_connection_t *conn,
* to conn and return, else reply based on <b>status</b>. * to conn and return, else reply based on <b>status</b>.
* *
* If <b>reply</b> is undefined, <b>status</b> can't be 0. * If <b>reply</b> is undefined, <b>status</b> can't be 0.
* DOCDOC endreason
*/ */
void void
connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply, connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply,
size_t replylen, size_t replylen, int endreason)
socks5_reply_status_t status)
{ {
char buf[256]; 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 */ tor_assert(conn->socks_request); /* make sure it's an AP stream */
control_event_stream_status(conn, control_event_stream_status(conn,
status==SOCKS5_SUCCEEDED ? STREAM_EVENT_SUCCEEDED : STREAM_EVENT_FAILED, status==SOCKS5_SUCCEEDED ? STREAM_EVENT_SUCCEEDED : STREAM_EVENT_FAILED,
END_STREAM_REASON_FIXME_XXXX); endreason);
if (conn->socks_request->has_finished) { if (conn->socks_request->has_finished) {
log_warn(LD_BUG, "Harmless bug: duplicate calls to " log_warn(LD_BUG, "Harmless bug: duplicate calls to "
......
...@@ -2965,6 +2965,12 @@ stream_end_reason_to_string(int reason) ...@@ -2965,6 +2965,12 @@ stream_end_reason_to_string(int reason)
case END_STREAM_REASON_CONNRESET: return "CONNRESET"; case END_STREAM_REASON_CONNRESET: return "CONNRESET";
case END_STREAM_REASON_TORPROTOCOL: return "TORPROTOCOL"; case END_STREAM_REASON_TORPROTOCOL: return "TORPROTOCOL";
case END_STREAM_REASON_NOTDIRECTORY: return "NOTDIRECTORY"; 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; default: return NULL;
} }
} }
......
...@@ -483,10 +483,6 @@ typedef enum { ...@@ -483,10 +483,6 @@ typedef enum {
#define END_STREAM_REASON_TORPROTOCOL 13 #define END_STREAM_REASON_TORPROTOCOL 13
#define END_STREAM_REASON_NOTDIRECTORY 14 #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, /* 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 * 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 * to be more informative when sending back socks replies to the
...@@ -494,6 +490,11 @@ typedef enum { ...@@ -494,6 +490,11 @@ typedef enum {
#define END_STREAM_REASON_ALREADY_SOCKS_REPLIED 256 #define END_STREAM_REASON_ALREADY_SOCKS_REPLIED 256
#define END_STREAM_REASON_CANT_ATTACH 257 #define END_STREAM_REASON_CANT_ATTACH 257
#define END_STREAM_REASON_NET_UNREACHABLE 258 #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_HOSTNAME 0
#define RESOLVED_TYPE_IPV4 4 #define RESOLVED_TYPE_IPV4 4
...@@ -1966,7 +1967,7 @@ int connection_ap_handshake_send_resolve(edge_connection_t *ap_conn, ...@@ -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); int connection_ap_make_bridge(char *address, uint16_t port);
void connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply, void connection_ap_handshake_socks_reply(edge_connection_t *conn, char *reply,
size_t replylen, size_t replylen,
socks5_reply_status_t status); int endreason);
void connection_ap_handshake_socks_resolved(edge_connection_t *conn, void connection_ap_handshake_socks_resolved(edge_connection_t *conn,
int answer_type, int answer_type,
size_t answer_len, size_t answer_len,
...@@ -1982,7 +1983,8 @@ void connection_ap_expire_beginning(void); ...@@ -1982,7 +1983,8 @@ void connection_ap_expire_beginning(void);
void connection_ap_attach_pending(void); void connection_ap_attach_pending(void);
void circuit_discard_optional_exit_enclaves(extend_info_t *info); void circuit_discard_optional_exit_enclaves(extend_info_t *info);
int connection_ap_detach_retriable(edge_connection_t *conn, 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_init(void);
void addressmap_clean(time_t now); void addressmap_clean(time_t now);
......
...@@ -577,11 +577,14 @@ connection_edge_end_reason_str(int reason) ...@@ -577,11 +577,14 @@ connection_edge_end_reason_str(int reason)
/** Translate <b>reason</b> (as from a relay 'end' cell) into an /** Translate <b>reason</b> (as from a relay 'end' cell) into an
* appropriate SOCKS5 reply code. * appropriate SOCKS5 reply code.
* DODCDOC 0
*/ */
socks5_reply_status_t socks5_reply_status_t
connection_edge_end_reason_socks5_response(int reason) connection_edge_end_reason_socks5_response(int reason)
{ {
switch (reason) { switch (reason) {
case 0:
return SOCKS5_SUCCEEDED;
case END_STREAM_REASON_MISC: case END_STREAM_REASON_MISC:
return SOCKS5_GENERAL_ERROR; return SOCKS5_GENERAL_ERROR;
case END_STREAM_REASON_RESOLVEFAILED: case END_STREAM_REASON_RESOLVEFAILED:
...@@ -613,6 +616,8 @@ connection_edge_end_reason_socks5_response(int reason) ...@@ -613,6 +616,8 @@ connection_edge_end_reason_socks5_response(int reason)
return SOCKS5_GENERAL_ERROR; return SOCKS5_GENERAL_ERROR;
case END_STREAM_REASON_NET_UNREACHABLE: case END_STREAM_REASON_NET_UNREACHABLE:
return SOCKS5_NET_UNREACHABLE; return SOCKS5_NET_UNREACHABLE;
case END_STREAM_REASON_SOCKSPROTOCOL:
return SOCKS5_GENERAL_ERROR;
default: default:
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Reason for ending (%d) not recognized; " "Reason for ending (%d) not recognized; "
...@@ -701,6 +706,7 @@ connection_edge_process_end_not_open( ...@@ -701,6 +706,7 @@ connection_edge_process_end_not_open(
struct in_addr in; struct in_addr in;
routerinfo_t *exitrouter; routerinfo_t *exitrouter;
int reason = *(cell->payload+RELAY_HEADER_SIZE); int reason = *(cell->payload+RELAY_HEADER_SIZE);
int control_reason = reason | END_STREAM_REASON_FLAG_REMOTE;
(void) layer_hint; /* unused */ (void) layer_hint; /* unused */
if (rh->length > 0 && edge_reason_is_retriable(reason) && if (rh->length > 0 && edge_reason_is_retriable(reason) &&
...@@ -749,7 +755,7 @@ connection_edge_process_end_not_open( ...@@ -749,7 +755,7 @@ connection_edge_process_end_not_open(
conn->_base.chosen_exit_optional = 0; conn->_base.chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name); /* clears it */ 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; return 0;
/* else, conn will get closed below */ /* else, conn will get closed below */
break; break;
...@@ -773,7 +779,7 @@ connection_edge_process_end_not_open( ...@@ -773,7 +779,7 @@ connection_edge_process_end_not_open(
conn->_base.chosen_exit_optional = 0; conn->_base.chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name); /* clears it */ 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; return 0;
/* else, conn will get closed below */ /* else, conn will get closed below */
} else { } else {
...@@ -798,7 +804,7 @@ connection_edge_process_end_not_open( ...@@ -798,7 +804,7 @@ connection_edge_process_end_not_open(
conn->_base.chosen_exit_optional = 0; conn->_base.chosen_exit_optional = 0;
tor_free(conn->chosen_exit_name); /* clears it */ 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; return 0;
/* else, will close below */ /* else, will close below */
break; break;
...@@ -874,7 +880,7 @@ connection_edge_process_relay_cell_not_open( ...@@ -874,7 +880,7 @@ connection_edge_process_relay_cell_not_open(
circuit_log_path(LOG_INFO,LD_APP,TO_ORIGIN_CIRCUIT(circ)); circuit_log_path(LOG_INFO,LD_APP,TO_ORIGIN_CIRCUIT(circ));
/* don't send a socks reply to transparent conns */ /* don't send a socks reply to transparent conns */
if (!conn->socks_request->has_finished) 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 */ /* handle anything that might have queued */
if (connection_edge_package_raw_inbuf(conn, 1) < 0) { if (connection_edge_package_raw_inbuf(conn, 1) < 0) {
/* (We already sent an end cell if possible) */ /* (We already sent an end cell if possible) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment