Commit c7ce6b98 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Split main.c into main.c and mainloop.c

The main.c code is responsible for initialization and shutdown;
the mainloop.c code is responsible for running the main loop of Tor.

Splitting the "generic event loop" part of mainloop.c from the
event-loop-specific part is not done as part of this patch.
parent 98ef3e82
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
......@@ -96,7 +95,8 @@
#include "lib/log/git_revision.h"
#include "feature/stats/geoip.h"
#include "feature/hibernate/hibernate.h"
#include "core/mainloop/main.h"
#include "app/main/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/policies.h"
......
......@@ -33,11 +33,11 @@
#include "core/or/circuitstats.h"
#include "app/config/config.h"
#include "app/config/confparse.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/connection.h"
#include "feature/control/control.h"
#include "feature/client/entrynodes.h"
#include "feature/hibernate/hibernate.h"
#include "core/mainloop/main.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "lib/sandbox/sandbox.h"
......
This diff is collapsed.
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file main.h
* \brief Header file for main.c.
**/
#ifndef TOR_MAIN_H
#define TOR_MAIN_H
void handle_signals(void);
void activate_signal(int signal_num);
int try_locking(const or_options_t *options, int err_if_locked);
int have_lockfile(void);
void release_lockfile(void);
void tor_remove_file(const char *filename);
void tor_cleanup(void);
void tor_free_all(int postfork);
int tor_init(int argc, char **argv);
#endif /* !defined(TOR_MAIN_H) */
......@@ -21,7 +21,7 @@
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/main.h"
#include "app/main/main.h"
#include "app/main/ntmain.h"
#include "lib/log/win32err.h"
#include "lib/fs/winlib.h"
......
......@@ -10,6 +10,7 @@ LIBTOR_APP_A_SOURCES = \
src/app/config/config.c \
src/app/config/confparse.c \
src/app/config/statefile.c \
src/app/main/main.c \
src/core/crypto/hs_ntor.c \
src/core/crypto/onion_crypto.c \
src/core/crypto/onion_fast.c \
......@@ -18,7 +19,7 @@ LIBTOR_APP_A_SOURCES = \
src/core/crypto/relay_crypto.c \
src/core/mainloop/connection.c \
src/core/mainloop/cpuworker.c \
src/core/mainloop/main.c \
src/core/mainloop/mainloop.c \
src/core/mainloop/periodic.c \
src/core/or/address_set.c \
src/core/or/channel.c \
......@@ -164,6 +165,7 @@ noinst_HEADERS += \
src/app/config/or_options_st.h \
src/app/config/or_state_st.h \
src/app/config/statefile.h \
src/app/main/main.h \
src/app/main/ntmain.h \
src/core/crypto/hs_ntor.h \
src/core/crypto/onion_crypto.h \
......@@ -173,7 +175,7 @@ noinst_HEADERS += \
src/core/crypto/relay_crypto.h \
src/core/mainloop/connection.h \
src/core/mainloop/cpuworker.h \
src/core/mainloop/main.h \
src/core/mainloop/mainloop.h \
src/core/mainloop/periodic.h \
src/core/or/addr_policy_st.h \
src/core/or/address_set.h \
......
......@@ -85,7 +85,7 @@
#include "feature/client/entrynodes.h"
#include "feature/relay/ext_orport.h"
#include "feature/stats/geoip.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_ident.h"
......
......@@ -26,7 +26,6 @@
#include "core/mainloop/cpuworker.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "core/mainloop/main.h"
#include "core/or/onion.h"
#include "feature/relay/onion_queue.h"
#include "feature/stats/rephist.h"
......
......@@ -5,12 +5,12 @@
/* See LICENSE for licensing information */
/**
* \file main.h
* \brief Header file for main.c.
* \file mainloop.h
* \brief Header file for mainloop.c.
**/
#ifndef TOR_MAIN_H
#define TOR_MAIN_H
#ifndef TOR_MAINLOOP_H
#define TOR_MAINLOOP_H
int have_completed_a_circuit(void);
void note_that_we_completed_a_circuit(void);
......@@ -73,20 +73,7 @@ MOCK_DECL(void,reset_uptime,(void));
unsigned get_signewnym_epoch(void);
void handle_signals(void);
void activate_signal(int signal_num);
int try_locking(const or_options_t *options, int err_if_locked);
int have_lockfile(void);
void release_lockfile(void);
void tor_remove_file(const char *filename);
void tor_cleanup(void);
void tor_free_all(int postfork);
int do_main_loop(void);
int tor_init(int argc, char **argv);
void reset_main_loop_counters(void);
uint64_t get_main_loop_success_count(void);
......@@ -96,6 +83,12 @@ uint64_t get_main_loop_idle_count(void);
void periodic_events_on_new_options(const or_options_t *options);
void reschedule_per_second_timer(void);
void do_signewnym(time_t);
time_t get_last_signewnym_time(void);
void tor_init_connection_lists(void);
void tor_mainloop_free_all(void);
struct token_bucket_rw_t;
extern time_t time_of_process_start;
......@@ -103,13 +96,12 @@ extern int quiet_level;
extern struct token_bucket_rw_t global_bucket;
extern struct token_bucket_rw_t global_relayed_bucket;
#ifdef MAIN_PRIVATE
STATIC void init_connection_lists(void);
#ifdef MAINLOOP_PRIVATE
STATIC void initialize_mainloop_events(void);
STATIC void close_closeable_connections(void);
STATIC void initialize_periodic_events(void);
STATIC void teardown_periodic_events(void);
STATIC int get_my_roles(const or_options_t *options);
STATIC int get_my_roles(const or_options_t *);
#ifdef TOR_UNIT_TESTS
extern smartlist_t *connection_array;
......@@ -119,4 +111,4 @@ extern periodic_event_item_t periodic_events[];
#endif
#endif /* defined(MAIN_PRIVATE) */
#endif /* !defined(TOR_MAIN_H) */
#endif
......@@ -14,7 +14,7 @@
#include "core/or/or.h"
#include "lib/evloop/compat_libevent.h"
#include "app/config/config.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/periodic.h"
#include "lib/evloop/compat_libevent.h"
......
......@@ -69,7 +69,7 @@
#include "core/or/circuitmux.h"
#include "feature/client/entrynodes.h"
#include "feature/stats/geoip.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
#include "feature/stats/rephist.h"
......
......@@ -17,7 +17,7 @@
#include "core/mainloop/connection.h"
#include "core/or/connection_or.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "lib/time/compat_time.h"
......
......@@ -47,7 +47,7 @@
#include "feature/dircache/directory.h"
#include "feature/client/entrynodes.h"
#include "core/crypto/hs_ntor.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
......
......@@ -71,7 +71,7 @@
#include "lib/crypt_ops/crypto_dh.h"
#include "feature/dircache/directory.h"
#include "feature/client/entrynodes.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_circuitmap.h"
#include "feature/hs/hs_ident.h"
......
......@@ -32,7 +32,7 @@
#include "app/config/confparse.h"
#include "feature/control/control.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
......
......@@ -80,7 +80,7 @@
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_circuit.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/policies.h"
......
......@@ -44,7 +44,7 @@
#include "feature/dirauth/reachability.h"
#include "feature/client/entrynodes.h"
#include "feature/stats/geoip.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "trunnel/link_handshake.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
......
......@@ -15,7 +15,7 @@
#include "core/or/connection_or.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "feature/stats/geoip.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
......
......@@ -67,7 +67,7 @@
#include "feature/relay/dns.h"
#include "feature/stats/geoip.h"
#include "feature/hs/hs_cache.h"
#include "core/mainloop/main.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/onion.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment