2010-07-23 20:18:55 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 21:13:17 +01:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2010-07-23 20:18:55 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file networkstatus.h
|
|
|
|
* \brief Header file for networkstatus.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_NETWORKSTATUS_H
|
|
|
|
#define TOR_NETWORKSTATUS_H
|
2010-07-23 20:18:55 +02:00
|
|
|
|
2014-10-07 15:20:44 +02:00
|
|
|
#include "testsupport.h"
|
|
|
|
|
2010-07-23 20:18:55 +02:00
|
|
|
void networkstatus_reset_warnings(void);
|
|
|
|
void networkstatus_reset_download_failures(void);
|
2017-05-03 21:08:59 +02:00
|
|
|
char *networkstatus_read_cached_consensus(const char *flavorname);
|
2010-07-23 20:18:55 +02:00
|
|
|
int router_reload_consensus_networkstatus(void);
|
|
|
|
void routerstatus_free(routerstatus_t *rs);
|
|
|
|
void networkstatus_vote_free(networkstatus_t *ns);
|
|
|
|
networkstatus_voter_info_t *networkstatus_get_voter_by_id(
|
|
|
|
networkstatus_t *vote,
|
|
|
|
const char *identity);
|
|
|
|
int networkstatus_check_consensus_signature(networkstatus_t *consensus,
|
|
|
|
int warn);
|
|
|
|
int networkstatus_check_document_signature(const networkstatus_t *consensus,
|
|
|
|
document_signature_t *sig,
|
|
|
|
const authority_cert_t *cert);
|
|
|
|
int compare_digest_to_routerstatus_entry(const void *_key,
|
|
|
|
const void **_member);
|
Refactor storing of measured_bw versus Unmeasured=1.
This patch moves the measured_bw field and the has_measured_bw field
into vote_routerstatus_t, since only votes have 'Measured=XX' set on
their weight line.
I also added a new bw_is_unmeasured flag to routerstatus_t to
represent the Unmeasured=1 flag on a w line. Previously, I was using
has_measured_bw for this, which was quite incorrect: has_measured_bw
means that the measured_bw field is set, and it's probably a mistake
to have it serve double duty as meaning that 'baandwidth' represents a
measured value.
While making this change,I also found a harmless but stupid bug in
dirserv_read_measured_bandwidths: It assumes that it's getting a
smartlist of routerstatus_t, when really it's getting a smartlist of
vote_routerstatus_t. C's struct layout rules mean that we could never
actually get an error because of that, but it's still quite incorrect.
I fixed that, and in the process needed to add two more sorting and
searching helpers.
Finally, I made the Unmeasured=1 flag get parsed. We don't use it for
anything yet, but someday we might.
This isn't complete yet -- the new 2286 unit test doesn't build.
2013-02-19 16:39:27 +01:00
|
|
|
int compare_digest_to_vote_routerstatus_entry(const void *_key,
|
|
|
|
const void **_member);
|
2010-09-29 07:35:08 +02:00
|
|
|
const routerstatus_t *networkstatus_vote_find_entry(networkstatus_t *ns,
|
|
|
|
const char *digest);
|
|
|
|
routerstatus_t *networkstatus_vote_find_mutable_entry(networkstatus_t *ns,
|
2010-07-23 20:18:55 +02:00
|
|
|
const char *digest);
|
|
|
|
int networkstatus_vote_find_entry_idx(networkstatus_t *ns,
|
|
|
|
const char *digest, int *found_out);
|
2014-10-07 15:20:44 +02:00
|
|
|
|
2016-06-28 23:30:57 +02:00
|
|
|
MOCK_DECL(download_status_t *,
|
|
|
|
networkstatus_get_dl_status_by_flavor,
|
|
|
|
(consensus_flavor_t flavor));
|
|
|
|
MOCK_DECL(download_status_t *,
|
|
|
|
networkstatus_get_dl_status_by_flavor_bootstrap,
|
|
|
|
(consensus_flavor_t flavor));
|
|
|
|
MOCK_DECL(download_status_t *,
|
|
|
|
networkstatus_get_dl_status_by_flavor_running,
|
|
|
|
(consensus_flavor_t flavor));
|
2016-06-27 18:38:37 +02:00
|
|
|
|
2016-06-28 23:30:57 +02:00
|
|
|
MOCK_DECL(smartlist_t *, router_get_descriptor_digests, (void));
|
2014-10-07 15:20:44 +02:00
|
|
|
MOCK_DECL(download_status_t *,router_get_dl_status_by_descriptor_digest,
|
|
|
|
(const char *d));
|
|
|
|
|
2010-09-29 07:35:08 +02:00
|
|
|
const routerstatus_t *router_get_consensus_status_by_id(const char *digest);
|
|
|
|
routerstatus_t *router_get_mutable_consensus_status_by_id(
|
|
|
|
const char *digest);
|
|
|
|
const routerstatus_t *router_get_consensus_status_by_descriptor_digest(
|
|
|
|
networkstatus_t *consensus,
|
|
|
|
const char *digest);
|
2014-10-07 15:20:44 +02:00
|
|
|
MOCK_DECL(routerstatus_t *,
|
|
|
|
router_get_mutable_consensus_status_by_descriptor_digest,
|
|
|
|
(networkstatus_t *consensus, const char *digest));
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const routerstatus_t *router_get_consensus_status_by_nickname(
|
|
|
|
const char *nickname,
|
|
|
|
int warn_if_unnamed);
|
2010-07-23 20:18:55 +02:00
|
|
|
const char *networkstatus_get_router_digest_by_nickname(const char *nickname);
|
|
|
|
int networkstatus_nickname_is_unnamed(const char *nickname);
|
2016-11-30 01:06:36 +01:00
|
|
|
int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
|
2016-11-30 01:07:48 +01:00
|
|
|
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
|
2010-09-17 04:12:03 +02:00
|
|
|
void networkstatus_consensus_download_failed(int status_code,
|
|
|
|
const char *flavname);
|
2010-07-23 20:18:55 +02:00
|
|
|
void update_consensus_networkstatus_fetch_time(time_t now);
|
2014-03-08 14:13:12 +01:00
|
|
|
int should_delay_dir_fetches(const or_options_t *options,const char **msg_out);
|
2010-07-23 20:18:55 +02:00
|
|
|
void update_networkstatus_downloads(time_t now);
|
|
|
|
void update_certificate_downloads(time_t now);
|
|
|
|
int consensus_is_waiting_for_certs(void);
|
2017-05-10 23:57:35 +02:00
|
|
|
int client_would_use_router(const routerstatus_t *rs, time_t now);
|
2016-05-03 17:42:50 +02:00
|
|
|
MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus,(void));
|
2014-10-07 15:20:44 +02:00
|
|
|
MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus_by_flavor,
|
|
|
|
(consensus_flavor_t f));
|
2016-05-03 17:42:50 +02:00
|
|
|
MOCK_DECL(networkstatus_t *, networkstatus_get_live_consensus,(time_t now));
|
2017-08-04 11:21:14 +02:00
|
|
|
int networkstatus_is_live(const networkstatus_t *ns, time_t now);
|
2017-05-15 01:43:41 +02:00
|
|
|
int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus,
|
2016-11-09 22:16:18 +01:00
|
|
|
time_t now);
|
2017-05-15 01:43:41 +02:00
|
|
|
int networkstatus_valid_until_is_reasonably_live(time_t valid_until,
|
|
|
|
time_t now);
|
2010-09-20 20:18:17 +02:00
|
|
|
networkstatus_t *networkstatus_get_reasonably_live_consensus(time_t now,
|
|
|
|
int flavor);
|
2016-05-19 03:31:03 +02:00
|
|
|
MOCK_DECL(int, networkstatus_consensus_is_bootstrapping,(time_t now));
|
2015-12-07 07:55:38 +01:00
|
|
|
int networkstatus_consensus_can_use_multiple_directories(
|
|
|
|
const or_options_t *options);
|
2016-05-19 03:31:03 +02:00
|
|
|
MOCK_DECL(int, networkstatus_consensus_can_use_extra_fallbacks,(
|
|
|
|
const or_options_t *options));
|
2016-04-13 07:08:17 +02:00
|
|
|
int networkstatus_consensus_is_already_downloading(const char *resource);
|
2015-12-07 07:55:38 +01:00
|
|
|
|
2010-07-23 20:18:55 +02:00
|
|
|
#define NSSET_FROM_CACHE 1
|
|
|
|
#define NSSET_WAS_WAITING_FOR_CERTS 2
|
|
|
|
#define NSSET_DONT_DOWNLOAD_CERTS 4
|
|
|
|
#define NSSET_ACCEPT_OBSOLETE 8
|
|
|
|
#define NSSET_REQUIRE_FLAVOR 16
|
|
|
|
int networkstatus_set_current_consensus(const char *consensus,
|
|
|
|
const char *flavor,
|
2016-05-04 08:38:27 +02:00
|
|
|
unsigned flags,
|
|
|
|
const char *source_dir);
|
2016-05-04 08:47:28 +02:00
|
|
|
void networkstatus_note_certs_arrived(const char *source_dir);
|
2010-07-23 20:18:55 +02:00
|
|
|
void routers_update_all_from_networkstatus(time_t now, int dir_version);
|
|
|
|
void routers_update_status_from_consensus_networkstatus(smartlist_t *routers,
|
|
|
|
int reset_failures);
|
|
|
|
void signed_descs_update_status_from_consensus_networkstatus(
|
|
|
|
smartlist_t *descs);
|
|
|
|
|
2010-09-29 07:35:08 +02:00
|
|
|
char *networkstatus_getinfo_helper_single(const routerstatus_t *rs);
|
2010-07-23 20:18:55 +02:00
|
|
|
char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now);
|
|
|
|
void networkstatus_dump_bridge_status_to_file(time_t now);
|
2011-06-14 19:01:38 +02:00
|
|
|
int32_t networkstatus_get_param(const networkstatus_t *ns,
|
|
|
|
const char *param_name,
|
2010-12-30 19:54:13 +01:00
|
|
|
int32_t default_val, int32_t min_val,
|
|
|
|
int32_t max_val);
|
2016-11-26 15:22:04 +01:00
|
|
|
int32_t networkstatus_get_overridable_param(const networkstatus_t *ns,
|
|
|
|
int32_t torrc_value,
|
|
|
|
const char *param_name,
|
|
|
|
int32_t default_val,
|
|
|
|
int32_t min_val, int32_t max_val);
|
2010-07-23 20:18:55 +02:00
|
|
|
int getinfo_helper_networkstatus(control_connection_t *conn,
|
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg);
|
|
|
|
int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight,
|
|
|
|
int32_t default_val);
|
|
|
|
const char *networkstatus_get_flavor_name(consensus_flavor_t flav);
|
|
|
|
int networkstatus_parse_flavor_name(const char *flavname);
|
|
|
|
void document_signature_free(document_signature_t *sig);
|
|
|
|
document_signature_t *document_signature_dup(const document_signature_t *sig);
|
|
|
|
void networkstatus_free_all(void);
|
2013-01-31 03:41:10 +01:00
|
|
|
int networkstatus_get_weight_scale_param(networkstatus_t *ns);
|
2010-07-23 20:18:55 +02:00
|
|
|
|
2017-01-23 20:52:51 +01:00
|
|
|
void vote_routerstatus_free(vote_routerstatus_t *rs);
|
|
|
|
|
2014-04-26 19:32:36 +02:00
|
|
|
#ifdef NETWORKSTATUS_PRIVATE
|
2015-01-26 20:49:48 +01:00
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
STATIC int networkstatus_set_current_consensus_from_ns(networkstatus_t *c,
|
|
|
|
const char *flavor);
|
2017-05-08 21:38:05 +02:00
|
|
|
extern networkstatus_t *current_ns_consensus;
|
|
|
|
extern networkstatus_t *current_md_consensus;
|
|
|
|
#endif
|
2014-04-26 19:32:36 +02:00
|
|
|
#endif
|
|
|
|
|
2010-07-23 20:18:55 +02:00
|
|
|
#endif
|
|
|
|
|