Split control_connection_t into its own header.

This one was actually fairly simple.
This commit is contained in:
Nick Mathewson 2018-06-15 10:17:27 -04:00
parent 5d5c442e6a
commit 3b917b2408
8 changed files with 63 additions and 40 deletions

View File

@ -113,6 +113,7 @@
#include <sys/un.h>
#endif
#include "control_connection_st.h"
#include "entry_connection_st.h"
#include "port_cfg_st.h"

View File

@ -81,6 +81,7 @@
#include "routerparse.h"
#include "shared_random_client.h"
#include "control_connection_st.h"
#include "entry_connection_st.h"
#ifndef _WIN32
@ -228,6 +229,15 @@ static void flush_queued_events_cb(mainloop_event_t *event, void *arg);
static char * download_status_to_string(const download_status_t *dl);
static void control_get_bytes_rw_last_sec(uint64_t *r, uint64_t *w);
/** Convert a connection_t* to an control_connection_t*; assert if the cast is
* invalid. */
control_connection_t *
TO_CONTROL_CONN(connection_t *c)
{
tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);
return DOWNCAST(control_connection_t, c);
}
/** Given a control event code for a message event, return the corresponding
* log severity. */
static inline int

View File

@ -12,6 +12,8 @@
#ifndef TOR_CONTROL_H
#define TOR_CONTROL_H
control_connection_t *TO_CONTROL_CONN(connection_t *);
void control_initialize_event_queue(void);
void control_update_global_event_mask(void);

View File

@ -0,0 +1,45 @@
/* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef CONTROL_CONNECTION_ST_H
#define CONTROL_CONNECTION_ST_H
#include "or.h"
/** Subtype of connection_t for an connection to a controller. */
struct control_connection_t {
connection_t base_;
uint64_t event_mask; /**< Bitfield: which events does this controller
* care about?
* EVENT_MAX_ is >31, so we need a 64 bit mask */
/** True if we have sent a protocolinfo reply on this connection. */
unsigned int have_sent_protocolinfo:1;
/** True if we have received a takeownership command on this
* connection. */
unsigned int is_owning_control_connection:1;
/** List of ephemeral onion services belonging to this connection. */
smartlist_t *ephemeral_onion_services;
/** If we have sent an AUTHCHALLENGE reply on this connection and
* have not received a successful AUTHENTICATE command, points to
* the value which the client must send to authenticate itself;
* otherwise, NULL. */
char *safecookie_client_hash;
/** Amount of space allocated in incoming_cmd. */
uint32_t incoming_cmd_len;
/** Number of bytes currently stored in incoming_cmd. */
uint32_t incoming_cmd_cur_len;
/** A control command that we're reading from the inbuf, but which has not
* yet arrived completely. */
char *incoming_cmd;
};
#endif

View File

@ -30,6 +30,7 @@
#include "main.h"
#include "policies.h"
#include "control_connection_st.h"
#include "entry_connection_st.h"
#include <event2/dns.h>

View File

@ -202,6 +202,7 @@ ORHEADERS = \
src/or/conscache.h \
src/or/consdiff.h \
src/or/consdiffmgr.h \
src/or/control_connection_st.h \
src/or/control.h \
src/or/cpuworker.h \
src/or/directory.h \

View File

@ -1639,6 +1639,7 @@ typedef struct or_connection_t {
uint64_t bytes_xmitted, bytes_xmitted_by_tls;
} or_connection_t;
typedef struct control_connection_t control_connection_t;
typedef struct edge_connection_t edge_connection_t;
typedef struct entry_connection_t entry_connection_t;
@ -1695,38 +1696,6 @@ typedef struct dir_connection_t {
#endif /* defined(MEASUREMENTS_21206) */
} dir_connection_t;
/** Subtype of connection_t for an connection to a controller. */
typedef struct control_connection_t {
connection_t base_;
uint64_t event_mask; /**< Bitfield: which events does this controller
* care about?
* EVENT_MAX_ is >31, so we need a 64 bit mask */
/** True if we have sent a protocolinfo reply on this connection. */
unsigned int have_sent_protocolinfo:1;
/** True if we have received a takeownership command on this
* connection. */
unsigned int is_owning_control_connection:1;
/** List of ephemeral onion services belonging to this connection. */
smartlist_t *ephemeral_onion_services;
/** If we have sent an AUTHCHALLENGE reply on this connection and
* have not received a successful AUTHENTICATE command, points to
* the value which the client must send to authenticate itself;
* otherwise, NULL. */
char *safecookie_client_hash;
/** Amount of space allocated in incoming_cmd. */
uint32_t incoming_cmd_len;
/** Number of bytes currently stored in incoming_cmd. */
uint32_t incoming_cmd_cur_len;
/** A control command that we're reading from the inbuf, but which has not
* yet arrived completely. */
char *incoming_cmd;
} control_connection_t;
/** Cast a connection_t subtype pointer to a connection_t **/
#define TO_CONN(c) (&(((c)->base_)))
@ -1739,9 +1708,6 @@ static or_connection_t *TO_OR_CONN(connection_t *);
/** Convert a connection_t* to a dir_connection_t*; assert if the cast is
* invalid. */
static dir_connection_t *TO_DIR_CONN(connection_t *);
/** Convert a connection_t* to an control_connection_t*; assert if the cast is
* invalid. */
static control_connection_t *TO_CONTROL_CONN(connection_t *);
/** Convert a connection_t* to an listener_connection_t*; assert if the cast is
* invalid. */
static listener_connection_t *TO_LISTENER_CONN(connection_t *);
@ -1756,11 +1722,6 @@ static inline dir_connection_t *TO_DIR_CONN(connection_t *c)
tor_assert(c->magic == DIR_CONNECTION_MAGIC);
return DOWNCAST(dir_connection_t, c);
}
static inline control_connection_t *TO_CONTROL_CONN(connection_t *c)
{
tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);
return DOWNCAST(control_connection_t, c);
}
static inline listener_connection_t *TO_LISTENER_CONN(connection_t *c)
{
tor_assert(c->magic == LISTENER_CONNECTION_MAGIC);

View File

@ -13,6 +13,8 @@
#include "test.h"
#include "test_helpers.h"
#include "control_connection_st.h"
static void
test_add_onion_helper_keyarg_v3(void *arg)
{