From 37ca621301134d567fbaa7cbbc84b3c10807726c Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 10 Feb 2005 06:31:34 +0000 Subject: [PATCH] when a client asks us for a dir mirror and we don't have one, launch an attempt to get a fresh one. svn:r3609 --- src/or/connection.c | 17 +++++++++++++++++ src/or/directory.c | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/or/connection.c b/src/or/connection.c index d410e9b895..6fd80c8745 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1256,6 +1256,23 @@ connection_t *connection_get_by_type_state(int type, int state) { return NULL; } +/** Return a connection of type type that has purpose purpose, + * and that is not marked for close. + */ +connection_t *connection_get_by_type_purpose(int type, int purpose) { + int i, n; + connection_t *conn; + connection_t **carray; + + get_connection_array(&carray,&n); + for (i=0;itype == type && conn->purpose == purpose && !conn->marked_for_close) + return conn; + } + return NULL; +} + /** Return the connection of type type that is in state * state, that was written to least recently, and that is not * marked for close. diff --git a/src/or/directory.c b/src/or/directory.c index 29e86d7620..6cb6b64c93 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -876,6 +876,9 @@ directory_handle_command_get(connection_t *conn, char *headers, if (dlen == 0) { log_fn(LOG_NOTICE,"Client asked for the mirrored directory, but we don't have a good one yet. Sending 503 Dir not available."); write_http_status_line(conn, 503, "Directory unavailable"); + /* try to get a new one now */ + if (!connection_get_by_type_purpose(CONN_TYPE_DIR, DIR_PURPOSE_FETCH_DIR)) + directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1); return 0; } @@ -898,6 +901,10 @@ directory_handle_command_get(connection_t *conn, char *headers, dlen = dirserv_get_runningrouters(&cp, deflated); if (!dlen) { /* we failed to create/cache cp */ write_http_status_line(conn, 503, "Directory unavailable"); + /* try to get a new one now */ + if (!connection_get_by_type_purpose(CONN_TYPE_DIR, + DIR_PURPOSE_FETCH_RUNNING_LIST)) + directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST, NULL, 1); return 0; }