diff options
-rw-r--r-- | src/or/connection.c | 8 | ||||
-rw-r--r-- | src/or/directory.c | 29 | ||||
-rw-r--r-- | src/or/or.h | 2 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 2a038e29cb..86a89f3cb0 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -208,13 +208,7 @@ void connection_about_to_close_connection(connection_t *conn) if (conn->state == DIR_CONN_STATE_CONNECTING) { /* it's a directory server and connecting failed: forget about this router */ - router_mark_as_down(conn->identity_digest); - if (conn->purpose == DIR_PURPOSE_FETCH_DIR && - !all_trusted_directory_servers_down()) { - log_fn(LOG_INFO,"Giving up on dirserver %s; trying another.", - conn->address); - directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL); - } + connection_dir_connect_failed(conn); } if (conn->purpose == DIR_PURPOSE_FETCH_RENDDESC) rend_client_desc_fetched(conn->rend_query, 0); diff --git a/src/or/directory.c b/src/or/directory.c index c6459cb0ca..c89b2125ce 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -213,6 +213,28 @@ directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv, NULL, dirserv->digest, purpose, resource, payload, payload_len); } +/** Called when we are unable to complete our connection to a + * directory server: Mark the router as down and try again if possible. + */ +int +connection_dir_connect_failed(connection_t *conn) +{ + router_mark_as_down(conn->identity_digest); /* don't try him again */ + if (conn->purpose == DIR_PURPOSE_FETCH_DIR || + conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) { + /* XXX This should possibly take into account that + * !advertised_server_mode() allows us to use more directory + * servers, and fascistfirewall allows us to use less. + */ + if (!all_trusted_directory_servers_down()) { + log_fn(LOG_INFO,"Giving up on dirserver '%s'; trying another.", conn->address); + directory_get_from_dirserver(conn->purpose, NULL); + } else { + log_fn(LOG_INFO,"Giving up on dirserver '%s'; no more to try.", conn->address); + } + } +} + /** Helper for directory_initiate_command(router|trusted_dir): send the * command to a server whose address is <b>address</b>, whose IP is * <b>addr</b>, whose directory port is <b>dir_port</b>, whose tor version is @@ -282,12 +304,7 @@ directory_initiate_command(const char *address, uint32_t addr, /* then we want to connect directly */ switch (connection_connect(conn, conn->address, addr, dir_port)) { case -1: - router_mark_as_down(conn->identity_digest); /* don't try him again */ - if (purpose == DIR_PURPOSE_FETCH_DIR && - !all_trusted_directory_servers_down()) { - log_fn(LOG_INFO,"Giving up on dirserver '%s'; trying another.", conn->address); - directory_get_from_dirserver(purpose, NULL); - } + connection_dir_connect_failed(conn); connection_free(conn); return; case 1: diff --git a/src/or/or.h b/src/or/or.h index 2bc621400a..770d321d58 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1318,6 +1318,7 @@ int connection_dir_reached_eof(connection_t *conn); int connection_dir_process_inbuf(connection_t *conn); int connection_dir_finished_flushing(connection_t *conn); int connection_dir_finished_connecting(connection_t *conn); +int connection_dir_failed(connection_t *conn); void parse_dir_policy(void); /********************************* dirserv.c ***************************/ @@ -1704,4 +1705,3 @@ int tor_version_compare(tor_version_t *a, tor_version_t *b); void assert_addr_policy_ok(addr_policy_t *t); #endif - |