[tor-commits] [tor/master] Expose/mock some functions to make ext_orport.c testing possible
nickm at torproject.org
nickm at torproject.org
Thu Aug 15 16:16:46 UTC 2013
commit d7358e8598710a4b78274bddd371d036ad0d47ea
Author: Nick Mathewson <nickm at torproject.org>
Date: Thu Aug 1 13:15:58 2013 -0400
Expose/mock some functions to make ext_orport.c testing possible
---
src/or/control.c | 4 ++--
src/or/control.h | 3 ++-
src/or/main.c | 23 ++++++++++++++++-------
src/or/main.h | 5 +++++
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/src/or/control.c b/src/or/control.c
index faf7942..3a32ea6 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -4699,8 +4699,8 @@ control_event_bootstrap(bootstrap_status_t status, int progress)
* that indicates a problem. <b>warn</b> gives a hint as to why, and
* <b>reason</b> provides an "or_conn_end_reason" tag.
*/
-void
-control_event_bootstrap_problem(const char *warn, int reason)
+MOCK_IMPL(void,
+control_event_bootstrap_problem, (const char *warn, int reason))
{
int status = bootstrap_percent;
const char *tag, *summary;
diff --git a/src/or/control.h b/src/or/control.h
index 288c286..3b2004b 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -85,7 +85,8 @@ void enable_control_logging(void);
void monitor_owning_controller_process(const char *process_spec);
void control_event_bootstrap(bootstrap_status_t status, int progress);
-void control_event_bootstrap_problem(const char *warn, int reason);
+MOCK_DECL(void, control_event_bootstrap_problem,(const char *warn,
+ int reason));
void control_event_clients_seen(const char *controller_str);
diff --git a/src/or/main.c b/src/or/main.c
index d172825..20cc292 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -10,6 +10,7 @@
* connections, implements main loop, and drives scheduled events.
**/
+#define MAIN_PRIVATE
#include "or.h"
#include "addressmap.h"
#include "buffers.h"
@@ -412,6 +413,19 @@ connection_unlink(connection_t *conn)
connection_free(conn);
}
+/** Initialize the global connection list, closeable connection list,
+ * and active connection list. */
+STATIC void
+init_connection_lists(void)
+{
+ if (!connection_array)
+ connection_array = smartlist_new();
+ if (!closeable_connection_lst)
+ closeable_connection_lst = smartlist_new();
+ if (!active_linked_connection_lst)
+ active_linked_connection_lst = smartlist_new();
+}
+
/** Schedule <b>conn</b> to be closed. **/
void
add_connection_to_closeable_list(connection_t *conn)
@@ -685,7 +699,7 @@ connection_stop_reading_from_linked_conn(connection_t *conn)
}
/** Close all connections that have been scheduled to get closed. */
-static void
+STATIC void
close_closeable_connections(void)
{
int i;
@@ -2307,12 +2321,7 @@ tor_init(int argc, char *argv[])
char buf[256];
int i, quiet = 0;
time_of_process_start = time(NULL);
- if (!connection_array)
- connection_array = smartlist_new();
- if (!closeable_connection_lst)
- closeable_connection_lst = smartlist_new();
- if (!active_linked_connection_lst)
- active_linked_connection_lst = smartlist_new();
+ init_connection_lists();
/* Have the log set up with our application name. */
tor_snprintf(buf, sizeof(buf), "Tor %s", get_version());
log_set_application_name(buf);
diff --git a/src/or/main.h b/src/or/main.h
index 85621a3..4aebe3e 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -69,5 +69,10 @@ int tor_main(int argc, char *argv[]);
int do_main_loop(void);
int tor_init(int argc, char **argv);
+#ifdef MAIN_PRIVATE
+STATIC void init_connection_lists(void);
+STATIC void close_closeable_connections(void);
+#endif
+
#endif
More information about the tor-commits
mailing list