summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-05-23 05:20:52 +0000
committerRoger Dingledine <arma@torproject.org>2005-05-23 05:20:52 +0000
commit040a748d87c7f7d1e81317498efa3ba0833303f7 (patch)
treeb2800c06fcdbb771254bffb1b90a03ba1de04b99
parent36a21de66d5078fd01e8378f17dcbd4738aaacd4 (diff)
downloadtor-040a748d87c7f7d1e81317498efa3ba0833303f7.tar.gz
tor-040a748d87c7f7d1e81317498efa3ba0833303f7.zip
i screwed up the dirport reachability testing when we don't yet
have a cached version of the directory. hopefully now fixed. svn:r4284
-rw-r--r--src/or/connection.c17
-rw-r--r--src/or/directory.c27
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/router.c16
5 files changed, 36 insertions, 32 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 95912072b4..9c9bea4517 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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.
diff --git a/src/or/directory.c b/src/or/directory.c
index 3a4da0c04e..fcea980ead 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -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;
}
diff --git a/src/or/main.c b/src/or/main.c
index 51f18c0e6e..d80ab6fb7b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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) &&
diff --git a/src/or/or.h b/src/or/or.h
index 6c030a48ec..ad7ae7597a 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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,
diff --git a/src/or/router.c b/src/or/router.c
index bc67c28713..8cd0a1fd23 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -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)