i screwed up the dirport reachability testing when we don't yet

have a cached version of the directory. hopefully now fixed.


svn:r4284
This commit is contained in:
Roger Dingledine 2005-05-23 05:20:52 +00:00
parent 36a21de66d
commit 040a748d87
5 changed files with 36 additions and 32 deletions

View File

@ -1437,23 +1437,6 @@ connection_t *connection_get_by_type_state(int type, int state) {
return NULL;
}
/** Return a connection of type <b>type</b> that has purpose <b>purpose</b>,
* 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;i<n;i++) {
conn = carray[i];
if (conn->type == type && conn->purpose == purpose && !conn->marked_for_close)
return conn;
}
return NULL;
}
/** Return the connection of type <b>type</b> that is in state
* <b>state</b>, that was written to least recently, and that is not
* marked for close.

View File

@ -903,6 +903,28 @@ write_http_status_line(connection_t *conn, int status,
connection_write_to_buf(buf, strlen(buf), conn);
}
/** Helper function: return 1 if there are any dir conns of purpose
* <b>purpose</b> that are going elsewhere than our own ORPort/Dirport.
* Else return 0.
*/
static int
already_fetching_directory(int purpose) {
int i, n;
connection_t *conn;
connection_t **carray;
get_connection_array(&carray,&n);
for (i=0;i<n;i++) {
conn = carray[i];
if (conn->type == CONN_TYPE_DIR &&
conn->purpose == purpose &&
!conn->marked_for_close &&
!router_digest_is_me(conn->identity_digest))
return 1;
}
return 0;
}
/** Helper function: called when a dirserver gets a complete HTTP GET
* request. Look for a request for a directory or for a rendezvous
* service descriptor. On finding one, write a response into
@ -938,7 +960,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
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))
if (!already_fetching_directory(DIR_PURPOSE_FETCH_DIR))
directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
return 0;
}
@ -963,8 +985,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
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))
if (!already_fetching_directory(DIR_PURPOSE_FETCH_RUNNING_LIST))
directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST, NULL, 1);
return 0;
}

View File

@ -523,12 +523,8 @@ void directory_has_arrived(time_t now, char *identity_digest) {
if (server_mode(options) && identity_digest) {
/* if this is us, then our dirport is reachable */
routerinfo_t *router = router_get_by_digest(identity_digest);
if (!router) // XXX
log_fn(LOG_WARN,"Bug: router_get_by_digest doesn't find me.");
if (router && router_is_me(router)) {
if (router_digest_is_me(identity_digest))
router_dirport_found_reachable();
}
}
if (server_mode(options) &&

View File

@ -1304,7 +1304,6 @@ connection_t *connection_get_by_global_id(uint32_t id);
connection_t *connection_get_by_type(int type);
connection_t *connection_get_by_type_state(int type, int state);
connection_t *connection_get_by_type_purpose(int type, int purpose);
connection_t *connection_get_by_type_state_lastwritten(int type, int state);
connection_t *connection_get_by_type_state_rendquery(int type, int state, const char *rendquery);
@ -1752,6 +1751,7 @@ void mark_my_descriptor_dirty(void);
int router_compare_to_my_exit_policy(connection_t *conn);
routerinfo_t *router_get_my_routerinfo(void);
const char *router_get_my_descriptor(void);
int router_digest_is_me(const char *digest);
int router_is_me(routerinfo_t *router);
int router_rebuild_descriptor(int force);
int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,

View File

@ -593,18 +593,22 @@ int router_compare_to_my_exit_policy(connection_t *conn)
desc_routerinfo->exit_policy) != ADDR_POLICY_ACCEPTED;
}
/** Return true iff <b>router</b> has the same nickname as this OR. (For an
* OP, always returns false.)
*/
int router_is_me(routerinfo_t *router)
/** Return true iff I'm a server and <b>digest</b> is equal to
* my identity digest. */
int router_digest_is_me(const char *digest)
{
routerinfo_t *me = router_get_my_routerinfo();
tor_assert(router);
if (!me || memcmp(me->identity_digest, router->identity_digest, DIGEST_LEN))
if (!me || memcmp(me->identity_digest, digest, DIGEST_LEN))
return 0;
return 1;
}
/** A wrapper around router_digest_is_me(). */
int router_is_me(routerinfo_t *router)
{
return router_digest_is_me(router->identity_digest);
}
/** Return a routerinfo for this OR, rebuilding a fresh one if
* necessary. Return NULL on error, or if called on an OP. */
routerinfo_t *router_get_my_routerinfo(void)