[or-cvs] r8778: Enable reasons for stream events in all cases but CLOSED in (in tor/trunk: . src/or)
nickm at seul.org
nickm at seul.org
Fri Oct 20 17:54:45 UTC 2006
Author: nickm
Date: 2006-10-20 13:54:43 -0400 (Fri, 20 Oct 2006)
New Revision: 8778
Modified:
tor/trunk/
tor/trunk/src/or/connection_edge.c
tor/trunk/src/or/control.c
tor/trunk/src/or/or.h
tor/trunk/src/or/relay.c
Log:
r9306 at 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.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/branches/stream-reasons [r9306] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c 2006-10-20 17:54:36 UTC (rev 8777)
+++ tor/trunk/src/or/connection_edge.c 2006-10-20 17:54:43 UTC (rev 8778)
@@ -49,16 +49,13 @@
}
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 @@
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 @@
* 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 @@
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_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 @@
* 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 "
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2006-10-20 17:54:36 UTC (rev 8777)
+++ tor/trunk/src/or/control.c 2006-10-20 17:54:43 UTC (rev 8778)
@@ -2965,6 +2965,12 @@
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;
}
}
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2006-10-20 17:54:36 UTC (rev 8777)
+++ tor/trunk/src/or/or.h 2006-10-20 17:54:43 UTC (rev 8778)
@@ -483,10 +483,6 @@
#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,7 +490,12 @@
#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
#define RESOLVED_TYPE_IPV6 6
@@ -1966,7 +1967,7 @@
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_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);
Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c 2006-10-20 17:54:36 UTC (rev 8777)
+++ tor/trunk/src/or/relay.c 2006-10-20 17:54:43 UTC (rev 8778)
@@ -577,11 +577,14 @@
/** 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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) */
More information about the tor-commits
mailing list