[tor-commits] [tor/master] Improve how we access or_state_t.

nickm at torproject.org nickm at torproject.org
Fri Oct 7 20:03:18 UTC 2011


commit 2703e41d8b6ffcad653af68a8261c22b5a1ed26f
Author: George Kadianakis <desnacked at gmail.com>
Date:   Sun Sep 11 20:57:01 2011 +0200

    Improve how we access or_state_t.
    
    * Use get_or_state()->VirtualOption instead of relying on
      config_find_option(), STRUCT_VAR_P and voodoo.
---
 src/or/config.c |   30 ++++++++++--------------------
 1 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 829d5ff..bacdae3 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5513,16 +5513,11 @@ static int
 validate_transports_in_state(or_state_t *state)
 {
   int broken = 0;
+  config_line_t *line;
 
-  config_var_t *var = config_find_option(&state_format,"TransportProxies");
-  if (!var)
-    return 0;
-
-  config_line_t **value = STRUCT_VAR_P(state, var->var_offset);
-  config_line_t *search = NULL;
-
-  for (search = *value ; search ; search = search->next) {
-    if (!state_transport_line_is_valid(search->value)<0)
+  for (line = state->TransportProxies ; line ; line = line->next) {
+    tor_assert(!strcmp(line->key, "TransportProxy"));
+    if (!state_transport_line_is_valid(line->value)<0)
       broken = 1;
   }
 
@@ -5790,18 +5785,13 @@ or_state_save(time_t now)
 static config_line_t *
 get_transport_in_state_by_name(const char *transport)
 {
-  config_var_t *var = config_find_option(&state_format,"TransportProxies");
-  if (!var)
-    return NULL;
-
-  config_line_t **value = STRUCT_VAR_P(get_or_state(), var->var_offset);
-  config_line_t *search = *value;
-
-  while (search) {
-    if (!strcmpstart(search->value, transport))
-      return search;
+  or_state_t *or_state = get_or_state();
+  config_line_t *line;
 
-    search = search->next;
+  for (line = or_state->TransportProxies ; line ; line = line->next) {
+    tor_assert(!strcmp(line->key, "TransportProxy"));
+    if (!strcmpstart(line->value, transport))
+      return line;
   }
   return NULL;
 }





More information about the tor-commits mailing list