Extract desc_store_t and routerlist_t into their own headers.

This commit is contained in:
Nick Mathewson 2018-06-15 14:07:17 -04:00
parent 62315dab84
commit b8ae4111e3
15 changed files with 89 additions and 49 deletions

View File

@ -92,6 +92,7 @@
#include "rend_authorized_client_st.h" #include "rend_authorized_client_st.h"
#include "rend_encoded_v2_service_descriptor_st.h" #include "rend_encoded_v2_service_descriptor_st.h"
#include "rend_service_descriptor_st.h" #include "rend_service_descriptor_st.h"
#include "routerlist_st.h"
#include "socks_request_st.h" #include "socks_request_st.h"
#ifndef _WIN32 #ifndef _WIN32

34
src/or/desc_store_st.h Normal file
View File

@ -0,0 +1,34 @@
/* 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 DESC_STORE_ST_H
#define DESC_STORE_ST_H
/** A 'store' is a set of descriptors saved on disk, with accompanying
* journal, mmaped as needed, rebuilt as needed. */
struct desc_store_t {
/** Filename (within DataDir) for the store. We append .tmp to this
* filename for a temporary file when rebuilding the store, and .new to this
* filename for the journal. */
const char *fname_base;
/** Human-readable description of what this store contains. */
const char *description;
tor_mmap_t *mmap; /**< A mmap for the main file in the store. */
store_type_t type; /**< What's stored in this store? */
/** The size of the router log, in bytes. */
size_t journal_len;
/** The size of the router store, in bytes. */
size_t store_len;
/** Total bytes dropped since last rebuild: this is space currently
* used in the cache and the journal that could be freed by a rebuild. */
size_t bytes_dropped;
};
#endif

View File

@ -34,6 +34,7 @@
#include "networkstatus_voter_info_st.h" #include "networkstatus_voter_info_st.h"
#include "node_st.h" #include "node_st.h"
#include "ns_detached_signatures_st.h" #include "ns_detached_signatures_st.h"
#include "routerlist_st.h"
#include "vote_microdesc_hash_st.h" #include "vote_microdesc_hash_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"
#include "vote_timing_st.h" #include "vote_timing_st.h"

View File

@ -38,6 +38,7 @@
#include "dir_connection_st.h" #include "dir_connection_st.h"
#include "node_st.h" #include "node_st.h"
#include "routerlist_st.h"
#include "tor_version_st.h" #include "tor_version_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"

View File

@ -210,6 +210,7 @@ ORHEADERS = \
src/or/crypt_path_st.h \ src/or/crypt_path_st.h \
src/or/crypt_path_reference_st.h \ src/or/crypt_path_reference_st.h \
src/or/cpuworker.h \ src/or/cpuworker.h \
src/or/desc_store_st.h \
src/or/directory.h \ src/or/directory.h \
src/or/dirserv.h \ src/or/dirserv.h \
src/or/dir_connection_st.h \ src/or/dir_connection_st.h \
@ -294,6 +295,7 @@ ORHEADERS = \
src/or/router.h \ src/or/router.h \
src/or/routerkeys.h \ src/or/routerkeys.h \
src/or/routerlist.h \ src/or/routerlist.h \
src/or/routerlist_st.h \
src/or/routerkeys.h \ src/or/routerkeys.h \
src/or/routerset.h \ src/or/routerset.h \
src/or/routerparse.h \ src/or/routerparse.h \

View File

@ -81,6 +81,7 @@
#include "networkstatus_voter_info_st.h" #include "networkstatus_voter_info_st.h"
#include "ns_detached_signatures_st.h" #include "ns_detached_signatures_st.h"
#include "node_st.h" #include "node_st.h"
#include "routerlist_st.h"
#include "vote_microdesc_hash_st.h" #include "vote_microdesc_hash_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"

View File

@ -71,6 +71,7 @@
#include "dir_server_st.h" #include "dir_server_st.h"
#include "networkstatus_st.h" #include "networkstatus_st.h"
#include "node_st.h" #include "node_st.h"
#include "routerlist_st.h"
static void nodelist_drop_node(node_t *node, int remove_from_ht); static void nodelist_drop_node(node_t *node, int remove_from_ht);
#define node_free(val) \ #define node_free(val) \

View File

@ -1891,55 +1891,8 @@ typedef enum store_type_t {
EXTRAINFO_STORE = 1 EXTRAINFO_STORE = 1
} store_type_t; } store_type_t;
/** A 'store' is a set of descriptors saved on disk, with accompanying typedef struct desc_store_t desc_store_t;
* journal, mmaped as needed, rebuilt as needed. */ typedef struct routerlist_t routerlist_t;
typedef struct desc_store_t {
/** Filename (within DataDir) for the store. We append .tmp to this
* filename for a temporary file when rebuilding the store, and .new to this
* filename for the journal. */
const char *fname_base;
/** Human-readable description of what this store contains. */
const char *description;
tor_mmap_t *mmap; /**< A mmap for the main file in the store. */
store_type_t type; /**< What's stored in this store? */
/** The size of the router log, in bytes. */
size_t journal_len;
/** The size of the router store, in bytes. */
size_t store_len;
/** Total bytes dropped since last rebuild: this is space currently
* used in the cache and the journal that could be freed by a rebuild. */
size_t bytes_dropped;
} desc_store_t;
/** Contents of a directory of onion routers. */
typedef struct {
/** Map from server identity digest to a member of routers. */
struct digest_ri_map_t *identity_map;
/** Map from server descriptor digest to a signed_descriptor_t from
* routers or old_routers. */
struct digest_sd_map_t *desc_digest_map;
/** Map from extra-info digest to an extrainfo_t. Only exists for
* routers in routers or old_routers. */
struct digest_ei_map_t *extra_info_map;
/** Map from extra-info digests to a signed_descriptor_t for a router
* descriptor having that extra-info digest. Only exists for
* routers in routers or old_routers. */
struct digest_sd_map_t *desc_by_eid_map;
/** List of routerinfo_t for all currently live routers we know. */
smartlist_t *routers;
/** List of signed_descriptor_t for older router descriptors we're
* caching. */
smartlist_t *old_routers;
/** Store holding server descriptors. If present, any router whose
* cache_info.saved_location == SAVED_IN_CACHE is stored in this file
* starting at cache_info.saved_offset */
desc_store_t desc_store;
/** Store holding extra-info documents. */
desc_store_t extrainfo_store;
} routerlist_t;
/** Information on router used when extending a circuit. We don't need a /** Information on router used when extending a circuit. We don't need a
* full routerinfo_t to extend: we only need addr:port:keyid to build an OR * full routerinfo_t to extend: we only need addr:port:keyid to build an OR

View File

@ -131,6 +131,7 @@
#include "networkstatus_st.h" #include "networkstatus_st.h"
#include "networkstatus_voter_info_st.h" #include "networkstatus_voter_info_st.h"
#include "node_st.h" #include "node_st.h"
#include "routerlist_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"
// #define DEBUG_ROUTERLIST // #define DEBUG_ROUTERLIST

40
src/or/routerlist_st.h Normal file
View File

@ -0,0 +1,40 @@
/* 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 ROUTERLIST_ST_H
#define ROUTERLIST_ST_H
#include "desc_store_st.h"
/** Contents of a directory of onion routers. */
struct routerlist_t {
/** Map from server identity digest to a member of routers. */
struct digest_ri_map_t *identity_map;
/** Map from server descriptor digest to a signed_descriptor_t from
* routers or old_routers. */
struct digest_sd_map_t *desc_digest_map;
/** Map from extra-info digest to an extrainfo_t. Only exists for
* routers in routers or old_routers. */
struct digest_ei_map_t *extra_info_map;
/** Map from extra-info digests to a signed_descriptor_t for a router
* descriptor having that extra-info digest. Only exists for
* routers in routers or old_routers. */
struct digest_sd_map_t *desc_by_eid_map;
/** List of routerinfo_t for all currently live routers we know. */
smartlist_t *routers;
/** List of signed_descriptor_t for older router descriptors we're
* caching. */
smartlist_t *old_routers;
/** Store holding server descriptors. If present, any router whose
* cache_info.saved_location == SAVED_IN_CACHE is stored in this file
* starting at cache_info.saved_offset */
desc_store_t desc_store;
/** Store holding extra-info documents. */
desc_store_t extrainfo_store;
};
#endif

View File

@ -88,6 +88,7 @@
#include "rend_authorized_client_st.h" #include "rend_authorized_client_st.h"
#include "rend_intro_point_st.h" #include "rend_intro_point_st.h"
#include "rend_service_descriptor_st.h" #include "rend_service_descriptor_st.h"
#include "routerlist_st.h"
#include "tor_version_st.h" #include "tor_version_st.h"
#include "vote_microdesc_hash_st.h" #include "vote_microdesc_hash_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"

View File

@ -43,6 +43,7 @@ routerinfo_t *router_parse_entry_from_string(const char *s, const char *end,
int allow_annotations, int allow_annotations,
const char *prepend_annotations, const char *prepend_annotations,
int *can_dl_again_out); int *can_dl_again_out);
struct digest_ri_map_t;
extrainfo_t *extrainfo_parse_entry_from_string(const char *s, const char *end, extrainfo_t *extrainfo_parse_entry_from_string(const char *s, const char *end,
int cache_copy, struct digest_ri_map_t *routermap, int cache_copy, struct digest_ri_map_t *routermap,
int *can_dl_again_out); int *can_dl_again_out);

View File

@ -50,6 +50,7 @@
#include "networkstatus_voter_info_st.h" #include "networkstatus_voter_info_st.h"
#include "ns_detached_signatures_st.h" #include "ns_detached_signatures_st.h"
#include "port_cfg_st.h" #include "port_cfg_st.h"
#include "routerlist_st.h"
#include "tor_version_st.h" #include "tor_version_st.h"
#include "vote_microdesc_hash_st.h" #include "vote_microdesc_hash_st.h"
#include "vote_routerstatus_st.h" #include "vote_routerstatus_st.h"

View File

@ -38,6 +38,7 @@
#include "dir_server_st.h" #include "dir_server_st.h"
#include "networkstatus_st.h" #include "networkstatus_st.h"
#include "rend_encoded_v2_service_descriptor_st.h" #include "rend_encoded_v2_service_descriptor_st.h"
#include "routerlist_st.h"
#ifdef _WIN32 #ifdef _WIN32
/* For mkdir() */ /* For mkdir() */

View File

@ -27,6 +27,7 @@
#include "connection_st.h" #include "connection_st.h"
#include "node_st.h" #include "node_st.h"
#include "origin_circuit_st.h" #include "origin_circuit_st.h"
#include "routerlist_st.h"
#include "test.h" #include "test.h"
#include "test_helpers.h" #include "test_helpers.h"