summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-12-14 08:32:14 +0000
committerRoger Dingledine <arma@torproject.org>2003-12-14 08:32:14 +0000
commit08534a6271972cad48cfb2156e6b754f5f2b7f91 (patch)
tree253a6ffae149e911512c0ea1f52cf344cbb4ed6a
parent0ea88d508dbc043f40e5209ad50b75e7b07099d3 (diff)
downloadtor-08534a6271972cad48cfb2156e6b754f5f2b7f91.tar.gz
tor-08534a6271972cad48cfb2156e6b754f5f2b7f91.zip
start tracking the 'It appears I've already sent the end' warning
svn:r932
-rw-r--r--src/or/circuit.c3
-rw-r--r--src/or/connection.c3
-rw-r--r--src/or/connection_edge.c35
-rw-r--r--src/or/dns.c10
-rw-r--r--src/or/or.h2
5 files changed, 34 insertions, 19 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index 471428ef40..d3fa4a3eb7 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -625,7 +625,8 @@ void circuit_about_to_close_connection(connection_t *conn) {
if(!conn->has_sent_end) {
log_fn(LOG_INFO,"Edge connection hasn't sent end yet? Bug.");
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
}
if(conn == circ->p_streams) {
diff --git a/src/or/connection.c b/src/or/connection.c
index 9ba9f9946a..36a9282193 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -655,7 +655,8 @@ int connection_send_destroy(circ_id_t circ_id, connection_t *conn) {
if(!connection_speaks_cells(conn)) {
log_fn(LOG_INFO,"CircID %d: At an edge. Marking connection for close.",
circ_id);
- connection_edge_end(conn, END_STREAM_REASON_DESTROY, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_DESTROY, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
/* if they already sent a destroy, they know. XXX can just close? */
return 0;
}
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 0b279b4d92..da33142a3b 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -31,7 +31,8 @@ int connection_edge_process_inbuf(connection_t *conn) {
conn->done_receiving = 1;
shutdown(conn->s, 0); /* XXX check return, refactor NM */
if (conn->done_sending) {
- connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
} else {
connection_edge_send_command(conn, circuit_get_by_conn(conn), RELAY_COMMAND_END,
NULL, 0, conn->cpath_layer);
@@ -40,7 +41,8 @@ int connection_edge_process_inbuf(connection_t *conn) {
#else
/* eof reached, kill it. */
log_fn(LOG_INFO,"conn (fd %d) reached eof. Closing.", conn->s);
- connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"2: I called connection_edge_end redundantly.");
return -1;
#endif
}
@@ -48,7 +50,8 @@ int connection_edge_process_inbuf(connection_t *conn) {
switch(conn->state) {
case AP_CONN_STATE_SOCKS_WAIT:
if(connection_ap_handshake_process_socks(conn) < 0) {
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"3: I called connection_edge_end redundantly.");
return -1;
}
return 0;
@@ -59,7 +62,8 @@ int connection_edge_process_inbuf(connection_t *conn) {
return 0;
}
if(connection_edge_package_raw_inbuf(conn) < 0) {
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"4: I called connection_edge_end redundantly.");
return -1;
}
return 0;
@@ -92,14 +96,14 @@ char *connection_edge_end_reason(char *payload, unsigned char length) {
return "";
}
-void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer) {
+int connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer) {
char payload[5];
int payload_len=1;
circuit_t *circ;
if(conn->has_sent_end) {
log_fn(LOG_WARN,"It appears I've already sent the end. Are you calling me twice?");
- return;
+ return -1;
}
payload[0] = reason;
@@ -117,6 +121,7 @@ void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_la
conn->marked_for_close = 1;
conn->has_sent_end = 1;
+ return 0;
}
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
@@ -197,7 +202,8 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
} else {
log_fn(LOG_WARN,"Got an unexpected relay command %d, in state %d (%s). Closing.",
relay_command, conn->state, conn_state_to_string[conn->type][conn->state]);
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
return -1;
}
}
@@ -219,7 +225,8 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
if((edge_type == EDGE_AP && --layer_hint->deliver_window < 0) ||
(edge_type == EDGE_EXIT && --circ->deliver_window < 0)) {
log_fn(LOG_WARN,"(relay data) circ deliver_window below 0. Killing.");
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"2: I called connection_edge_end redundantly.");
return -1;
}
log_fn(LOG_DEBUG,"circ deliver_window now %d.", edge_type == EDGE_AP ? layer_hint->deliver_window : circ->deliver_window);
@@ -346,7 +353,8 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
}
if(connection_ap_handshake_socks_reply(conn, NULL, 0, 1) < 0) {
log_fn(LOG_INFO,"Writing to socks-speaking application failed. Closing.");
- connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+ if(connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer) < 0)
+ log_fn(LOG_WARN,"3: I called connection_edge_end redundantly.");
}
return 0;
case RELAY_COMMAND_SENDME:
@@ -775,7 +783,8 @@ static int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) {
return 0;
case -1: /* resolve failed */
log_fn(LOG_INFO,"Resolve failed (%s).", n_stream->address);
- connection_edge_end(n_stream, END_STREAM_REASON_RESOLVEFAILED, NULL);
+ if(connection_edge_end(n_stream, END_STREAM_REASON_RESOLVEFAILED, NULL) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
/* case 0, resolve added to pending list */
}
return 0;
@@ -786,13 +795,15 @@ void connection_exit_connect(connection_t *conn) {
if(router_compare_to_my_exit_policy(conn) < 0) {
log_fn(LOG_INFO,"%s:%d failed exit policy. Closing.", conn->address, conn->port);
- connection_edge_end(conn, END_STREAM_REASON_EXITPOLICY, NULL);
+ if(connection_edge_end(conn, END_STREAM_REASON_EXITPOLICY, NULL) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
return;
}
switch(connection_connect(conn, conn->address, conn->addr, conn->port)) {
case -1:
- connection_edge_end(conn, END_STREAM_REASON_CONNECTFAILED, NULL);
+ if(connection_edge_end(conn, END_STREAM_REASON_CONNECTFAILED, NULL) < 0)
+ log_fn(LOG_WARN,"2: I called connection_edge_end redundantly.");
return;
case 0:
connection_set_poll_socket(conn);
diff --git a/src/or/dns.c b/src/or/dns.c
index eb648a9995..8225b4e2b0 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -265,7 +265,8 @@ void dns_cancel_pending_resolve(char *address, connection_t *onlyconn) {
address);
while(resolve->pending_connections) {
pend = resolve->pending_connections;
- connection_edge_end(pend->conn, END_STREAM_REASON_MISC, NULL);
+ if(connection_edge_end(pend->conn, END_STREAM_REASON_MISC, NULL) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
resolve->pending_connections = pend->next;
free(pend);
}
@@ -327,9 +328,10 @@ static void dns_found_answer(char *address, uint32_t addr) {
while(resolve->pending_connections) {
pend = resolve->pending_connections;
pend->conn->addr = resolve->addr;
- if(resolve->state == CACHE_STATE_FAILED)
- connection_edge_end(pend->conn, END_STREAM_REASON_RESOLVEFAILED, NULL);
- else
+ if(resolve->state == CACHE_STATE_FAILED) {
+ if(connection_edge_end(pend->conn, END_STREAM_REASON_RESOLVEFAILED, NULL) < 0)
+ log_fn(LOG_WARN,"1: I called connection_edge_end redundantly.");
+ } else
connection_exit_connect(pend->conn);
resolve->pending_connections = pend->next;
free(pend);
diff --git a/src/or/or.h b/src/or/or.h
index fdf17e0f2f..753cbf3e4c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -618,7 +618,7 @@ void assert_connection_ok(connection_t *conn, time_t now);
/********************************* connection_edge.c ***************************/
int connection_edge_process_inbuf(connection_t *conn);
-void connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
+int connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ, int relay_command,
void *payload, int payload_len, crypt_path_t *cpath_layer);