From 61cebb2035b8cfb2f84ab5e198742d0b29b41192 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 25 Mar 2019 14:14:56 -0400 Subject: [PATCH] Minimize the includes in control.c --- scripts/maint/practracker/exceptions.txt | 2 - src/feature/control/control.c | 92 +----------------------- src/feature/control/control.h | 1 - src/feature/control/control_fmt.c | 15 ++++ src/feature/control/control_fmt.h | 2 + src/test/test_hs.c | 1 + src/test/test_hs_control.c | 1 + 7 files changed, 20 insertions(+), 94 deletions(-) diff --git a/scripts/maint/practracker/exceptions.txt b/scripts/maint/practracker/exceptions.txt index fe91e0c345..a6726ef570 100644 --- a/scripts/maint/practracker/exceptions.txt +++ b/scripts/maint/practracker/exceptions.txt @@ -109,8 +109,6 @@ problem function-size /src/tools/tor-gencert.c:parse_commandline() 111 problem function-size /src/feature/keymgt/loadkey.c:ed_key_init_from_file() 333 problem function-size /src/feature/dircommon/consdiff.c:gen_ed_diff() 204 problem function-size /src/feature/dircommon/consdiff.c:apply_ed_diff() 159 -problem file-size /src/feature/control/control.c 7592 -problem include-count /src/feature/control/control.c 90 problem function-size /src/feature/control/control_auth.c:handle_control_authenticate() 188 problem function-size /src/feature/control/control_auth.c:handle_control_authchallenge() 115 problem function-size /src/feature/control/control_getinfo.c:getinfo_helper_misc() 109 diff --git a/src/feature/control/control.c b/src/feature/control/control.c index 70d70bedac..41e21c0a14 100644 --- a/src/feature/control/control.c +++ b/src/feature/control/control.c @@ -33,91 +33,25 @@ **/ #define CONTROL_MODULE_PRIVATE -#define CONTROL_EVENTS_PRIVATE -#define OCIRC_EVENT_PRIVATE #include "core/or/or.h" #include "app/config/config.h" -#include "app/config/confparse.h" #include "app/main/main.h" #include "core/mainloop/connection.h" #include "core/mainloop/mainloop.h" -#include "core/or/channel.h" -#include "core/or/channeltls.h" -#include "core/or/circuitbuild.h" -#include "core/or/circuitlist.h" -#include "core/or/circuitstats.h" -#include "core/or/circuituse.h" -#include "core/or/command.h" -#include "core/or/connection_edge.h" #include "core/or/connection_or.h" -#include "core/or/ocirc_event.h" -#include "core/or/policies.h" -#include "core/or/reasons.h" -#include "core/or/versions.h" #include "core/proto/proto_control0.h" #include "core/proto/proto_http.h" -#include "feature/client/addressmap.h" -#include "feature/client/bridges.h" -#include "feature/client/dnsserv.h" -#include "feature/client/entrynodes.h" #include "feature/control/control.h" #include "feature/control/control_auth.h" #include "feature/control/control_cmd.h" #include "feature/control/control_events.h" #include "feature/control/control_fmt.h" -#include "feature/control/control_getinfo.h" -#include "feature/control/fmt_serverstatus.h" -#include "feature/control/getinfo_geoip.h" -#include "feature/dircache/dirserv.h" -#include "feature/dirclient/dirclient.h" -#include "feature/dirclient/dlstatus.h" -#include "feature/dircommon/directory.h" -#include "feature/hibernate/hibernate.h" -#include "feature/hs/hs_cache.h" -#include "feature/hs/hs_common.h" -#include "feature/hs/hs_control.h" -#include "feature/hs_common/shared_random_client.h" -#include "feature/nodelist/authcert.h" -#include "feature/nodelist/dirlist.h" -#include "feature/nodelist/microdesc.h" -#include "feature/nodelist/networkstatus.h" -#include "feature/nodelist/nodelist.h" -#include "feature/nodelist/routerinfo.h" -#include "feature/nodelist/routerlist.h" -#include "feature/relay/router.h" -#include "feature/relay/routermode.h" -#include "feature/relay/selftest.h" -#include "feature/rend/rendclient.h" #include "feature/rend/rendcommon.h" -#include "feature/rend/rendparse.h" #include "feature/rend/rendservice.h" -#include "feature/stats/geoip_stats.h" -#include "feature/stats/predict_ports.h" -#include "lib/buf/buffers.h" -#include "lib/crypt_ops/crypto_rand.h" -#include "lib/crypt_ops/crypto_util.h" -#include "lib/encoding/confline.h" -#include "lib/evloop/compat_libevent.h" -#include "lib/version/torversion.h" +#include "lib/evloop/procmon.h" -#include "feature/dircache/cached_dir_st.h" #include "feature/control/control_connection_st.h" -#include "core/or/cpath_build_state_st.h" -#include "core/or/entry_connection_st.h" -#include "feature/nodelist/extrainfo_st.h" -#include "feature/nodelist/networkstatus_st.h" -#include "feature/nodelist/node_st.h" -#include "core/or/or_connection_st.h" -#include "core/or/or_circuit_st.h" -#include "core/or/origin_circuit_st.h" -#include "feature/nodelist/microdesc_st.h" -#include "feature/rend/rend_authorized_client_st.h" -#include "feature/rend/rend_encoded_v2_service_descriptor_st.h" -#include "feature/rend/rend_service_descriptor_st.h" -#include "feature/nodelist/routerinfo_st.h" -#include "feature/nodelist/routerlist_st.h" -#include "core/or/socks_request_st.h" #ifdef HAVE_UNISTD_H #include @@ -126,15 +60,6 @@ #include #endif -#ifndef _WIN32 -#include -#include -#endif - -#include "lib/crypt_ops/crypto_s2k.h" -#include "lib/evloop/procmon.h" -#include "lib/evloop/compat_libevent.h" - /** Convert a connection_t* to an control_connection_t*; assert if the cast is * invalid. */ control_connection_t * @@ -610,21 +535,6 @@ monitor_owning_controller_process(const char *process_spec) } } -/** Return a longname the node whose identity is id_digest. If - * node_get_by_id() returns NULL, base 16 encoding of id_digest is - * returned instead. - * - * This function is not thread-safe. Each call to this function invalidates - * previous values returned by this function. - */ -MOCK_IMPL(const char *, -node_describe_longname_by_id,(const char *id_digest)) -{ - static char longname[MAX_VERBOSE_NICKNAME_LEN+1]; - node_get_verbose_nickname_by_id(id_digest, longname); - return longname; -} - /** Free any leftover allocated memory of the control.c subsystem. */ void control_free_all(void) diff --git a/src/feature/control/control.h b/src/feature/control/control.h index d20bc6fa2b..3083837931 100644 --- a/src/feature/control/control.h +++ b/src/feature/control/control.h @@ -48,7 +48,6 @@ void enable_control_logging(void); void monitor_owning_controller_process(const char *process_spec); const char *rend_auth_type_to_string(rend_auth_type_t auth_type); -MOCK_DECL(const char *, node_describe_longname_by_id,(const char *id_digest)); void control_free_all(void); #ifdef CONTROL_MODULE_PRIVATE diff --git a/src/feature/control/control_fmt.c b/src/feature/control/control_fmt.c index 290ea61450..71f9d82163 100644 --- a/src/feature/control/control_fmt.c +++ b/src/feature/control/control_fmt.c @@ -392,3 +392,18 @@ decode_escaped_string(const char *start, size_t in_len_max, return end+1; } + +/** Return a longname the node whose identity is id_digest. If + * node_get_by_id() returns NULL, base 16 encoding of id_digest is + * returned instead. + * + * This function is not thread-safe. Each call to this function invalidates + * previous values returned by this function. + */ +MOCK_IMPL(const char *, +node_describe_longname_by_id,(const char *id_digest)) +{ + static char longname[MAX_VERBOSE_NICKNAME_LEN+1]; + node_get_verbose_nickname_by_id(id_digest, longname); + return longname; +} diff --git a/src/feature/control/control_fmt.h b/src/feature/control/control_fmt.h index e7ab6608a4..74545eb309 100644 --- a/src/feature/control/control_fmt.h +++ b/src/feature/control/control_fmt.h @@ -31,4 +31,6 @@ const char *decode_escaped_string(const char *start, size_t in_len_max, char **out, size_t *out_len); void send_control_done(control_connection_t *conn); +MOCK_DECL(const char *, node_describe_longname_by_id,(const char *id_digest)); + #endif /* !defined(TOR_CONTROL_FMT_H) */ diff --git a/src/test/test_hs.c b/src/test/test_hs.c index de10a10d81..aeb3387471 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -16,6 +16,7 @@ #include "test/test.h" #include "feature/control/control.h" #include "feature/control/control_events.h" +#include "feature/control/control_fmt.h" #include "app/config/config.h" #include "feature/hs/hs_common.h" #include "feature/rend/rendcommon.h" diff --git a/src/test/test_hs_control.c b/src/test/test_hs_control.c index d23d31954b..481ef1eb39 100644 --- a/src/test/test_hs_control.c +++ b/src/test/test_hs_control.c @@ -12,6 +12,7 @@ #include "test/test.h" #include "feature/control/control.h" #include "feature/control/control_events.h" +#include "feature/control/control_fmt.h" #include "app/config/config.h" #include "feature/hs/hs_common.h" #include "feature/hs/hs_control.h"