[tor-commits] [tor/master] Use an enum for INTRO_POINT_FAILURE_*

nickm at torproject.org nickm at torproject.org
Tue Aug 11 13:36:11 UTC 2015


commit 1070be8217c26c8917323ead944124e2cd14f9f2
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Thu Jun 25 16:13:15 2015 -0400

    Use an enum for INTRO_POINT_FAILURE_*
    
    Safer, wiser, stronger!
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/or/rendcache.c  |    7 ++++---
 src/or/rendcache.h  |    4 ++--
 src/or/rendclient.h |    4 ----
 src/or/rendcommon.h |    6 ++++++
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index acb9447..8f3ddf5 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -125,7 +125,7 @@ rend_cache_failure_intro_entry_free(rend_cache_failure_intro_t *entry)
 /** Allocate a rend cache failure intro object and return it. <b>failure</b>
  * is set into the object. This function can not fail. */
 static rend_cache_failure_intro_t *
-rend_cache_failure_intro_entry_new(unsigned int failure)
+rend_cache_failure_intro_entry_new(rend_intro_point_failure_t failure)
 {
   rend_cache_failure_intro_t *entry = tor_malloc(sizeof(*entry));
   entry->failure_type = failure;
@@ -309,7 +309,7 @@ not_found:
  * <b>failure</b> in that object. */
 static void
 cache_failure_intro_add(const uint8_t *identity, const char *service_id,
-                        unsigned int failure)
+                        rend_intro_point_failure_t failure)
 {
   rend_cache_failure_t *fail_entry;
   rend_cache_failure_intro_t *entry;
@@ -376,7 +376,8 @@ validate_intro_point_failure(const rend_service_descriptor_t *desc,
  * <b>identity</b> and service ID <b>service_id</b>. If an entry already
  * exists in the cache, the failure type is changed with <b>failure</b>. */
 void
-rend_cache_intro_failure_note(unsigned int failure, const uint8_t *identity,
+rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
+                              const uint8_t *identity,
                               const char *service_id)
 {
   int found;
diff --git a/src/or/rendcache.h b/src/or/rendcache.h
index 9a18810..b214a48 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -34,7 +34,7 @@ typedef struct rend_cache_entry_t {
 
 /* Introduction point failure type. */
 typedef struct rend_cache_failure_intro_t {
-  unsigned int failure_type;
+  rend_intro_point_failure_t failure_type;
 } rend_cache_failure_intro_t;
 
 /** Cache failure object indexed by service ID. */
@@ -65,7 +65,7 @@ rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
                                                 rend_cache_entry_t **entry);
 size_t rend_cache_get_total_allocation(void);
 
-void rend_cache_intro_failure_note(unsigned int failure,
+void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
                                    const uint8_t *identity,
                                    const char *service_id);
 void rend_cache_failure_purge(void);
diff --git a/src/or/rendclient.h b/src/or/rendclient.h
index 439f428..124433e 100644
--- a/src/or/rendclient.h
+++ b/src/or/rendclient.h
@@ -26,10 +26,6 @@ int rend_client_fetch_v2_desc(rend_data_t *query, smartlist_t *hsdirs);
 void rend_client_cancel_descriptor_fetches(void);
 void rend_client_purge_last_hid_serv_requests(void);
 
-#define INTRO_POINT_FAILURE_GENERIC 0
-#define INTRO_POINT_FAILURE_TIMEOUT 1
-#define INTRO_POINT_FAILURE_UNREACHABLE 2
-
 int rend_client_report_intro_point_failure(extend_info_t *failed_intro,
                                            rend_data_t *rend_query,
                                            unsigned int failure_type);
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index ba5e077..3b2f86d 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -12,6 +12,12 @@
 #ifndef TOR_RENDCOMMON_H
 #define TOR_RENDCOMMON_H
 
+typedef enum rend_intro_point_failure_t {
+  INTRO_POINT_FAILURE_GENERIC     = 0,
+  INTRO_POINT_FAILURE_TIMEOUT     = 1,
+  INTRO_POINT_FAILURE_UNREACHABLE = 2,
+} rend_intro_point_failure_t;
+
 /** Free all storage associated with <b>data</b> */
 static INLINE void
 rend_data_free(rend_data_t *data)





More information about the tor-commits mailing list