Split dir_connection_t into its own header

This commit is contained in:
Nick Mathewson 2018-06-15 10:31:21 -04:00
parent 3b917b2408
commit 1416f54d1e
26 changed files with 116 additions and 70 deletions

View File

@ -67,6 +67,7 @@
#include "control.h"
#include "crypto_rand.h"
#include "crypto_util.h"
#include "directory.h"
#include "entrynodes.h"
#include "main.h"
#include "hs_circuit.h"
@ -91,6 +92,7 @@
#include "ht.h"
#include "dir_connection_st.h"
#include "edge_connection_st.h"
/********* START VARIABLES **********/

View File

@ -40,6 +40,7 @@
#include "connection.h"
#include "connection_edge.h"
#include "control.h"
#include "directory.h"
#include "entrynodes.h"
#include "hs_common.h"
#include "hs_client.h"
@ -56,6 +57,7 @@
#include "router.h"
#include "routerlist.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
static void circuit_expire_old_circuits_clientside(void);

View File

@ -113,6 +113,7 @@
#include <sys/un.h>
#endif
#include "dir_connection_st.h"
#include "control_connection_st.h"
#include "entry_connection_st.h"
#include "port_cfg_st.h"
@ -4112,6 +4113,13 @@ connection_write_to_buf_impl_,(const char *string, size_t len,
connection_write_to_buf_commit(conn, written);
}
void
connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done)
{
connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
}
/**
* Add all bytes from <b>buf</b> to <b>conn</b>'s outbuf, draining them
* from <b>buf</b>. (If the connection is marked and will soon be closed,

View File

@ -150,20 +150,13 @@ MOCK_DECL(void, connection_write_to_buf_impl_,
/* DOCDOC connection_write_to_buf */
static void connection_buf_add(const char *string, size_t len,
connection_t *conn);
/* DOCDOC connection_write_to_buf_compress */
static void connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done);
static inline void
connection_buf_add(const char *string, size_t len, connection_t *conn)
{
connection_write_to_buf_impl_(string, len, conn, 0);
}
static inline void
connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done)
{
connection_write_to_buf_impl_(string, len, TO_CONN(conn), done ? -1 : 1);
}
void connection_buf_add_compress(const char *string, size_t len,
dir_connection_t *conn, int done);
void connection_buf_add_buf(connection_t *conn, buf_t *buf);
/* DOCDOC connection_get_inbuf_len */

View File

@ -97,6 +97,7 @@
#include "routerset.h"
#include "circuitbuild.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
#ifdef HAVE_LINUX_TYPES_H

View File

@ -0,0 +1,64 @@
/* 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 DIR_CONNECTION_ST_H
#define DIR_CONNECTION_ST_H
/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
* connection to retrieve or serve directory material. */
struct dir_connection_t {
connection_t base_;
/** Which 'resource' did we ask the directory for? This is typically the part
* of the URL string that defines, relative to the directory conn purpose,
* what thing we want. For example, in router descriptor downloads by
* descriptor digest, it contains "d/", then one or more +-separated
* fingerprints.
**/
char *requested_resource;
unsigned int dirconn_direct:1; /**< Is this dirconn direct, or via Tor? */
/** If we're fetching descriptors, what router purpose shall we assign
* to them? */
uint8_t router_purpose;
/** List of spooled_resource_t for objects that we're spooling. We use
* it from back to front. */
smartlist_t *spool;
/** The compression object doing on-the-fly compression for spooled data. */
tor_compress_state_t *compress_state;
/** What rendezvous service are we querying for? */
rend_data_t *rend_data;
/* Hidden service connection identifier for dir connections: Used by HS
client-side code to fetch HS descriptors, and by the service-side code to
upload descriptors. */
struct hs_ident_dir_conn_t *hs_ident;
/** If this is a one-hop connection, tracks the state of the directory guard
* for this connection (if any). */
struct circuit_guard_state_t *guard_state;
char identity_digest[DIGEST_LEN]; /**< Hash of the public RSA key for
* the directory server's signing key. */
/** Unique ID for directory requests; this used to be in connection_t, but
* that's going away and being used on channels instead. The dirserver still
* needs this for the incoming side, so it's moved here. */
uint64_t dirreq_id;
#ifdef MEASUREMENTS_21206
/** Number of RELAY_DATA cells received. */
uint32_t data_cells_received;
/** Number of RELAY_DATA cells sent. */
uint32_t data_cells_sent;
#endif /* defined(MEASUREMENTS_21206) */
};
#endif

View File

@ -53,6 +53,7 @@
#include "dirauth/mode.h"
#include "dirauth/shared_random.h"
#include "dir_connection_st.h"
#include "dir_server_st.h"
#include "entry_connection_st.h"
@ -154,6 +155,15 @@ static void connection_dir_close_consensus_fetches(
/********* END VARIABLES ************/
/** Convert a connection_t* to a dir_connection_t*; assert if the cast is
* invalid. */
dir_connection_t *
TO_DIR_CONN(connection_t *c)
{
tor_assert(c->magic == DIR_CONNECTION_MAGIC);
return DOWNCAST(dir_connection_t, c);
}
/** Return false if the directory purpose <b>dir_purpose</b>
* does not require an anonymous (three-hop) connection.
*

View File

@ -14,6 +14,7 @@
#include "hs_ident.h"
dir_connection_t *TO_DIR_CONN(connection_t *c);
int directories_have_accepted_server_descriptor(void);
void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
dirinfo_type_t type, const char *payload,

View File

@ -36,6 +36,8 @@
#include "dirauth/dirvote.h"
#include "dir_connection_st.h"
/**
* \file dirserv.c
* \brief Directory server core implementation. Manages directory

View File

@ -35,6 +35,7 @@
#include "router.h"
#include "routerset.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
/* Return a human-readable string for the client fetch status code. */

View File

@ -39,6 +39,7 @@
#include "hs_service.h"
#include "hs_stats.h"
#include "dir_connection_st.h"
#include "edge_connection_st.h"
/* Trunnel */

View File

@ -207,6 +207,7 @@ ORHEADERS = \
src/or/cpuworker.h \
src/or/directory.h \
src/or/dirserv.h \
src/or/dir_connection_st.h \
src/or/dir_server_st.h \
src/or/dns.h \
src/or/dns_structs.h \

View File

@ -74,6 +74,7 @@
#include "dirauth/mode.h"
#include "dirauth/shared_random.h"
#include "dir_connection_st.h"
#include "dir_server_st.h"
/** Most recently received and validated v3 "ns"-flavored consensus network

View File

@ -1640,62 +1640,10 @@ typedef struct or_connection_t {
} or_connection_t;
typedef struct control_connection_t control_connection_t;
typedef struct dir_connection_t dir_connection_t;
typedef struct edge_connection_t edge_connection_t;
typedef struct entry_connection_t entry_connection_t;
/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
* connection to retrieve or serve directory material. */
typedef struct dir_connection_t {
connection_t base_;
/** Which 'resource' did we ask the directory for? This is typically the part
* of the URL string that defines, relative to the directory conn purpose,
* what thing we want. For example, in router descriptor downloads by
* descriptor digest, it contains "d/", then one or more +-separated
* fingerprints.
**/
char *requested_resource;
unsigned int dirconn_direct:1; /**< Is this dirconn direct, or via Tor? */
/** If we're fetching descriptors, what router purpose shall we assign
* to them? */
uint8_t router_purpose;
/** List of spooled_resource_t for objects that we're spooling. We use
* it from back to front. */
smartlist_t *spool;
/** The compression object doing on-the-fly compression for spooled data. */
tor_compress_state_t *compress_state;
/** What rendezvous service are we querying for? */
rend_data_t *rend_data;
/* Hidden service connection identifier for dir connections: Used by HS
client-side code to fetch HS descriptors, and by the service-side code to
upload descriptors. */
struct hs_ident_dir_conn_t *hs_ident;
/** If this is a one-hop connection, tracks the state of the directory guard
* for this connection (if any). */
struct circuit_guard_state_t *guard_state;
char identity_digest[DIGEST_LEN]; /**< Hash of the public RSA key for
* the directory server's signing key. */
/** Unique ID for directory requests; this used to be in connection_t, but
* that's going away and being used on channels instead. The dirserver still
* needs this for the incoming side, so it's moved here. */
uint64_t dirreq_id;
#ifdef MEASUREMENTS_21206
/** Number of RELAY_DATA cells received. */
uint32_t data_cells_received;
/** Number of RELAY_DATA cells sent. */
uint32_t data_cells_sent;
#endif /* defined(MEASUREMENTS_21206) */
} dir_connection_t;
/** Cast a connection_t subtype pointer to a connection_t **/
#define TO_CONN(c) (&(((c)->base_)))
@ -1705,9 +1653,6 @@ typedef struct dir_connection_t {
/** Convert a connection_t* to an or_connection_t*; assert if the cast is
* invalid. */
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 listener_connection_t*; assert if the cast is
* invalid. */
static listener_connection_t *TO_LISTENER_CONN(connection_t *);
@ -1717,11 +1662,6 @@ static inline or_connection_t *TO_OR_CONN(connection_t *c)
tor_assert(c->magic == OR_CONNECTION_MAGIC);
return DOWNCAST(or_connection_t, c);
}
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 listener_connection_t *TO_LISTENER_CONN(connection_t *c)
{
tor_assert(c->magic == LISTENER_CONNECTION_MAGIC);

View File

@ -63,6 +63,7 @@
#include "control.h"
#include "crypto_rand.h"
#include "crypto_util.h"
#include "directory.h"
#include "geoip.h"
#include "hs_cache.h"
#include "main.h"
@ -81,6 +82,7 @@
#include "scheduler.h"
#include "rephist.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
static edge_connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell,

View File

@ -33,6 +33,7 @@
#include "routerlist.h"
#include "routerset.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
static extend_info_t *rend_client_get_random_intro_impl(

View File

@ -39,6 +39,7 @@
#include "dirauth/mode.h"
#include "dir_connection_st.h"
#include "dir_server_st.h"
#include "port_cfg_st.h"

View File

@ -125,6 +125,7 @@
#include "dirauth/dirvote.h"
#include "dirauth/mode.h"
#include "dir_connection_st.h"
#include "dir_server_st.h"
// #define DEBUG_ROUTERLIST

View File

@ -14,6 +14,8 @@
#include "directory.h"
#include "torlog.h"
#include "dir_connection_st.h"
#include "fuzzing.h"
static void

View File

@ -24,6 +24,7 @@
#include "test_connection.h"
#include "test_helpers.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
static void * test_conn_get_basic_setup(const struct testcase_t *tc);

View File

@ -34,6 +34,7 @@
#include "log_test_helpers.h"
#include "voting_schedule.h"
#include "dir_connection_st.h"
#include "dir_server_st.h"
#ifdef _WIN32

View File

@ -30,6 +30,8 @@
#include "statefile.h"
#include "util.h"
#include "dir_connection_st.h"
#include "test_helpers.h"
#include "log_test_helpers.h"

View File

@ -18,6 +18,8 @@
#include "connection.h"
#include "proto_http.h"
#include "dir_connection_st.h"
#include "hs_test_helpers.h"
#include "test_helpers.h"
#include "test.h"

View File

@ -37,6 +37,7 @@
#include "connection_edge.h"
#include "networkstatus.h"
#include "dir_connection_st.h"
#include "entry_connection_st.h"
static int

View File

@ -12,6 +12,8 @@
#include "main.h"
#include "test.h"
#include "dir_connection_st.h"
static or_options_t mock_options;
static void

View File

@ -33,6 +33,9 @@
#include "routerparse.h"
#include "dirauth/shared_random.h"
#include "statefile.h"
#include "dir_connection_st.h"
#include "test.h"
#include "test_dir_common.h"
#include "log_test_helpers.h"