Split getinfo handling into a new control_getinfo.c

This commit is contained in:
Nick Mathewson 2019-03-25 12:48:52 -04:00
parent a49f506e05
commit 4754e9058b
12 changed files with 1803 additions and 1693 deletions

View File

@ -112,9 +112,9 @@ 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.c:handle_control_authenticate() 188
problem function-size /src/feature/control/control.c:getinfo_helper_misc() 109
problem function-size /src/feature/control/control.c:getinfo_helper_dir() 304
problem function-size /src/feature/control/control.c:getinfo_helper_events() 236
problem function-size /src/feature/control/control_getinfo.c:getinfo_helper_misc() 109
problem function-size /src/feature/control/control_getinfo.c:getinfo_helper_dir() 304
problem function-size /src/feature/control/control_getinfo.c:getinfo_helper_events() 236
problem function-size /src/feature/control/control.c:handle_control_extendcircuit() 151
problem function-size /src/feature/control/control.c:handle_control_authchallenge() 115
problem function-size /src/feature/control/control.c:handle_control_hsfetch() 114
@ -123,6 +123,7 @@ problem function-size /src/feature/control/control.c:handle_control_add_onion()
problem function-size /src/feature/control/control.c:add_onion_helper_keyarg() 125
problem function-size /src/feature/control/control.c:connection_control_process_inbuf() 239
problem function-size /src/feature/control/control_events.c:control_event_stream_status() 119
problem include-count /src/feature/control/control_getinfo.c 51
problem function-size /src/feature/stats/rephist.c:rep_hist_load_mtbf_data() 185
problem function-size /src/feature/stats/rephist.c:rep_hist_format_exit_stats() 148
problem function-size /src/feature/dircache/consdiffmgr.c:consdiffmgr_cleanup() 115

View File

@ -73,6 +73,7 @@ LIBTOR_APP_A_SOURCES = \
src/feature/control/control_bootstrap.c \
src/feature/control/control_events.c \
src/feature/control/control_fmt.c \
src/feature/control/control_getinfo.c \
src/feature/control/fmt_serverstatus.c \
src/feature/control/getinfo_geoip.c \
src/feature/dirauth/keypin.c \
@ -291,7 +292,8 @@ noinst_HEADERS += \
src/feature/control/control.h \
src/feature/control/control_connection_st.h \
src/feature/control/control_events.h \
src/feature/control/control_fmt.h \
src/feature/control/control_fmt.h \
src/feature/control/control_getinfo.h \
src/feature/control/fmt_serverstatus.h \
src/feature/control/getinfo_geoip.h \
src/feature/dirauth/authmode.h \

File diff suppressed because it is too large Load Diff

View File

@ -77,48 +77,18 @@ STATIC int add_onion_helper_keyarg(const char *arg, int discard_pk,
STATIC rend_authorized_client_t *
add_onion_helper_clientauth(const char *arg, int *created, char **err_msg_out);
STATIC int getinfo_helper_onions(
control_connection_t *control_conn,
const char *question,
char **answer,
const char **errmsg);
STATIC void getinfo_helper_downloads_networkstatus(
const char *flavor,
download_status_t **dl_to_emit,
const char **errmsg);
STATIC void getinfo_helper_downloads_cert(
const char *fp_sk_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_desc(
const char *desc_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_bridge(
const char *bridge_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC int getinfo_helper_downloads(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_dir(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_current_time(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
#endif /* defined(CONTROL_PRIVATE) */
#ifdef CONTROL_MODULE_PRIVATE
struct signal_name_t {
int sig;
const char *signal_name;
};
extern const struct signal_name_t signal_table[];
int get_cached_network_liveness(void);
void set_cached_network_liveness(int liveness);
smartlist_t * get_detached_onion_services(void);
#endif /* defined(CONTROL_MODULE_PRIVATE) */
#endif /* !defined(TOR_CONTROL_H) */

View File

@ -72,6 +72,43 @@ static void send_control_event(uint16_t event,
const char *format, ...)
CHECK_PRINTF(2,3);
/** Table mapping event values to their names. Used to implement SETEVENTS
* and GETINFO events/names, and to keep they in sync. */
const struct control_event_t control_event_table[] = {
{ EVENT_CIRCUIT_STATUS, "CIRC" },
{ EVENT_CIRCUIT_STATUS_MINOR, "CIRC_MINOR" },
{ EVENT_STREAM_STATUS, "STREAM" },
{ EVENT_OR_CONN_STATUS, "ORCONN" },
{ EVENT_BANDWIDTH_USED, "BW" },
{ EVENT_DEBUG_MSG, "DEBUG" },
{ EVENT_INFO_MSG, "INFO" },
{ EVENT_NOTICE_MSG, "NOTICE" },
{ EVENT_WARN_MSG, "WARN" },
{ EVENT_ERR_MSG, "ERR" },
{ EVENT_NEW_DESC, "NEWDESC" },
{ EVENT_ADDRMAP, "ADDRMAP" },
{ EVENT_DESCCHANGED, "DESCCHANGED" },
{ EVENT_NS, "NS" },
{ EVENT_STATUS_GENERAL, "STATUS_GENERAL" },
{ EVENT_STATUS_CLIENT, "STATUS_CLIENT" },
{ EVENT_STATUS_SERVER, "STATUS_SERVER" },
{ EVENT_GUARD, "GUARD" },
{ EVENT_STREAM_BANDWIDTH_USED, "STREAM_BW" },
{ EVENT_CLIENTS_SEEN, "CLIENTS_SEEN" },
{ EVENT_NEWCONSENSUS, "NEWCONSENSUS" },
{ EVENT_BUILDTIMEOUT_SET, "BUILDTIMEOUT_SET" },
{ EVENT_GOT_SIGNAL, "SIGNAL" },
{ EVENT_CONF_CHANGED, "CONF_CHANGED"},
{ EVENT_CONN_BW, "CONN_BW" },
{ EVENT_CELL_STATS, "CELL_STATS" },
{ EVENT_CIRC_BANDWIDTH_USED, "CIRC_BW" },
{ EVENT_TRANSPORT_LAUNCHED, "TRANSPORT_LAUNCHED" },
{ EVENT_HS_DESC, "HS_DESC" },
{ EVENT_HS_DESC_CONTENT, "HS_DESC_CONTENT" },
{ EVENT_NETWORK_LIVENESS, "NETWORK_LIVENESS" },
{ 0, NULL },
};
/** Given a log severity, return the corresponding control event code. */
static inline int
log_severity_to_event(int severity)

View File

@ -327,6 +327,14 @@ void append_cell_stats_by_command(smartlist_t *event_parts,
void format_cell_stats(char **event_string, circuit_t *circ,
cell_stats_t *cell_stats);
/** Helper structure: maps event values to their names. */
struct control_event_t {
uint16_t event_code;
const char *event_name;
};
extern const struct control_event_t control_event_table[];
#ifdef TOR_UNIT_TESTS
MOCK_DECL(STATIC void,
send_control_event_string,(uint16_t event, const char *msg));

View File

@ -23,6 +23,16 @@
#include "core/or/socks_request_st.h"
#include "feature/control/control_connection_st.h"
/** Append a NUL-terminated string <b>s</b> to the end of
* <b>conn</b>-\>outbuf.
*/
void
connection_write_str_to_buf(const char *s, control_connection_t *conn)
{
size_t len = strlen(s);
connection_buf_add(s, len, TO_CONN(conn));
}
/** Acts like sprintf, but writes its formatted string to the end of
* <b>conn</b>-\>outbuf. */
void

View File

@ -12,6 +12,7 @@
#ifndef TOR_CONTROL_FMT_H
#define TOR_CONTROL_FMT_H
void connection_write_str_to_buf(const char *s, control_connection_t *conn);
void connection_printf_to_buf(control_connection_t *conn,
const char *format, ...)
CHECK_PRINTF(2,3);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2019, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file control.h
* \brief Header file for control.c.
**/
#ifndef TOR_CONTROL_GETINFO_H
#define TOR_CONTROL_GETINFO_H
int handle_control_getinfo(control_connection_t *conn, uint32_t len,
const char *body);
#ifdef CONTROL_GETINFO_PRIVATE
STATIC int getinfo_helper_onions(
control_connection_t *control_conn,
const char *question,
char **answer,
const char **errmsg);
STATIC void getinfo_helper_downloads_networkstatus(
const char *flavor,
download_status_t **dl_to_emit,
const char **errmsg);
STATIC void getinfo_helper_downloads_cert(
const char *fp_sk_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_desc(
const char *desc_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC void getinfo_helper_downloads_bridge(
const char *bridge_req,
download_status_t **dl_to_emit,
smartlist_t **digest_list,
const char **errmsg);
STATIC int getinfo_helper_downloads(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_dir(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_current_time(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
#endif /* defined(CONTROL_GETINFO_PRIVATE) */
#endif /* !defined(TOR_CONTROL_GETINFO) */

View File

@ -2,10 +2,12 @@
/* See LICENSE for licensing information */
#define CONTROL_PRIVATE
#define CONTROL_GETINFO_PRIVATE
#include "core/or/or.h"
#include "lib/crypt_ops/crypto_ed25519.h"
#include "feature/client/bridges.h"
#include "feature/control/control.h"
#include "feature/control/control_getinfo.h"
#include "feature/client/entrynodes.h"
#include "feature/hs/hs_common.h"
#include "feature/nodelist/networkstatus.h"

View File

@ -8,7 +8,7 @@
#define BWAUTH_PRIVATE
#define CONFIG_PRIVATE
#define CONTROL_PRIVATE
#define CONTROL_GETINFO_PRIVATE
#define DIRCACHE_PRIVATE
#define DIRCLIENT_PRIVATE
#define DIRSERV_PRIVATE
@ -32,7 +32,7 @@
#include "core/or/versions.h"
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/control/control_getinfo.h"
#include "feature/dirauth/bwauth.h"
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/dsigs_parse.h"