summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-05-19 23:32:20 +0000
committerRoger Dingledine <arma@torproject.org>2004-05-19 23:32:20 +0000
commitb37450ce553d206e115ed57da80b9546fe34e0fb (patch)
treeaf40ece562a2a60367c0898cbff33824bca1a862
parentb8f535a2d8b94cea6e5222591fe3b9a28bdf87c0 (diff)
downloadtor-b37450ce553d206e115ed57da80b9546fe34e0fb.tar.gz
tor-b37450ce553d206e115ed57da80b9546fe34e0fb.zip
do all the heavy lifting in connection_about_to_close_connection,
not in _connection_mark_for_close this will hopefully clean up the huge cyclical function mess svn:r1903
-rw-r--r--src/or/connection.c80
-rw-r--r--src/or/dns.c6
2 files changed, 37 insertions, 49 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 3fd1efff0b..64b0632d0e 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -172,16 +172,46 @@ void connection_free_all(void) {
void connection_about_to_close_connection(connection_t *conn)
{
+
+ if(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) {
+ if(!conn->has_sent_end)
+ log_fn(LOG_WARN,"Edge connection hasn't sent end yet? Bug.");
+ }
+
switch(conn->type) {
case CONN_TYPE_DIR:
if(conn->purpose == DIR_PURPOSE_FETCH_RENDDESC)
rend_client_desc_fetched(conn->rend_query, 0);
break;
+ case CONN_TYPE_OR:
+ /* Remember why we're closing this connection. */
+ if (conn->state != OR_CONN_STATE_OPEN) {
+ /* XXX Nick: this still isn't right, because it might be
+ * dying even though we didn't initiate the connect. Can
+ * you look at this more? -RD */
+ if(conn->nickname)
+ rep_hist_note_connect_failed(conn->nickname, time(NULL));
+ } else if (0) { // XXX reason == CLOSE_REASON_UNUSED_OR_CONN) {
+ rep_hist_note_disconnect(conn->nickname, time(NULL));
+ } else {
+ rep_hist_note_connection_died(conn->nickname, time(NULL));
+ }
+ break;
case CONN_TYPE_AP:
+ if (conn->socks_request->has_finished == 0) {
+ log_fn(LOG_INFO,"Cleaning up AP -- sending socks reject.");
+ connection_ap_handshake_socks_reply(conn, NULL, 0, 0);
+ conn->socks_request->has_finished = 1;
+ conn->hold_open_until_flushed = 1;
+ }
+ break;
case CONN_TYPE_EXIT:
- if(!conn->has_sent_end) {
- log_fn(LOG_WARN,"Edge connection hasn't sent end yet? Bug.");
- connection_mark_for_close(conn);
+ if (conn->state == EXIT_CONN_STATE_RESOLVING)
+ connection_dns_remove(conn);
+ break;
+ case CONN_TYPE_DNSWORKER:
+ if (conn->state == DNSWORKER_STATE_BUSY) {
+ dns_cancel_pending_resolve(conn->address);
}
break;
}
@@ -230,50 +260,6 @@ _connection_mark_for_close(connection_t *conn)
return -1;
}
- switch (conn->type)
- {
- case CONN_TYPE_OR_LISTENER:
- case CONN_TYPE_AP_LISTENER:
- case CONN_TYPE_DIR_LISTENER:
- case CONN_TYPE_CPUWORKER:
- case CONN_TYPE_DIR:
- /* No special processing needed immediately. */
- break;
- case CONN_TYPE_OR:
- /* Remember why we're closing this connection. */
- if (conn->state != OR_CONN_STATE_OPEN) {
- /* XXX Nick: this still isn't right, because it might be
- * dying even though we didn't initiate the connect. Can
- * you look at this more? -RD */
- if(conn->nickname)
- rep_hist_note_connect_failed(conn->nickname, time(NULL));
- } else if (0) { // XXX reason == CLOSE_REASON_UNUSED_OR_CONN) {
- rep_hist_note_disconnect(conn->nickname, time(NULL));
- } else {
- rep_hist_note_connection_died(conn->nickname, time(NULL));
- }
- break;
- case CONN_TYPE_AP:
- if (conn->socks_request->has_finished == 0) {
- log_fn(LOG_INFO,"Cleaning up AP -- sending socks reject.");
- connection_ap_handshake_socks_reply(conn, NULL, 0, 0);
- conn->socks_request->has_finished = 1;
- conn->hold_open_until_flushed = 1;
- }
- /* fall through, to do things for both ap and exit */
- case CONN_TYPE_EXIT:
- if (conn->state == EXIT_CONN_STATE_RESOLVING)
- connection_dns_remove(conn);
- break;
- case CONN_TYPE_DNSWORKER:
- if (conn->state == DNSWORKER_STATE_BUSY) {
- dns_cancel_pending_resolve(conn->address);
- }
- break;
- default:
- log(LOG_ERR, "Unknown connection type %d", conn->type);
- ;
- }
conn->marked_for_close = 1;
/* in case we're going to be held-open-til-flushed, reset
diff --git a/src/or/dns.c b/src/or/dns.c
index 958e05bc67..f00868d9f1 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -343,8 +343,10 @@ void dns_cancel_pending_resolve(char *address) {
pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
pendconn = pend->conn; /* don't pass complex things to the
connection_mark_for_close macro */
- connection_edge_end(pendconn, END_STREAM_REASON_MISC, pendconn->cpath_layer);
- connection_mark_for_close(pendconn);
+ if(!pendconn->marked_for_close) {
+ connection_edge_end(pendconn, END_STREAM_REASON_MISC, pendconn->cpath_layer);
+ connection_mark_for_close(pendconn);
+ }
resolve->pending_connections = pend->next;
tor_free(pend);
}