[or-cvs] [tor/master 1/6] New function to grab a directory connection fetching a resource

nickm at torproject.org nickm at torproject.org
Tue Sep 28 04:44:15 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Mon, 20 Sep 2010 11:24:01 -0400
Subject: New function to grab a directory connection fetching a resource
Commit: 4bfc64ba1c23da0bd6f5165a788cc07d934c9a9b

We need this to tell if a given consensus flavor is being downloaded
or not.
---
 src/or/connection.c |   27 +++++++++++++++++++++++++++
 src/or/connection.h |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 80144c4..9c6166d 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -3397,6 +3397,33 @@ connection_get_by_type_state_rendquery(int type, int state,
   return NULL;
 }
 
+/** Return a directory connection (if any one exists) that is fetching
+ * the item described by <b>state</b>/<b>resource</b> */
+dir_connection_t *
+connection_dir_get_by_purpose_and_resource(int purpose,
+                                           const char *resource)
+{
+  smartlist_t *conns = get_connection_array();
+
+  SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
+    dir_connection_t *dirconn;
+    if (conn->type != CONN_TYPE_DIR || conn->marked_for_close ||
+        conn->purpose != purpose)
+      continue;
+    dirconn = TO_DIR_CONN(conn);
+    if (dirconn->requested_resource == NULL) {
+      if (resource == NULL)
+        return dirconn;
+    } else if (resource) {
+      if (0 == strcmp(resource, dirconn->requested_resource))
+        return dirconn;
+    }
+  } SMARTLIST_FOREACH_END(conn);
+
+  return NULL;
+}
+
+
 /** Return an open, non-marked connection of a given type and purpose, or NULL
  * if no such connection exists. */
 connection_t *
diff --git a/src/or/connection.h b/src/or/connection.h
index a40b1a5..004ede5 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -124,6 +124,8 @@ connection_t *connection_get_by_type_addr_port_purpose(int type,
 connection_t *connection_get_by_type_state(int type, int state);
 connection_t *connection_get_by_type_state_rendquery(int type, int state,
                                                      const char *rendquery);
+dir_connection_t *connection_dir_get_by_purpose_and_resource(
+                                           int state, const char *resource);
 
 #define connection_speaks_cells(conn) ((conn)->type == CONN_TYPE_OR)
 int connection_is_listener(connection_t *conn);
-- 
1.7.1




More information about the tor-commits mailing list