* as unnamed for some server in the consensus. */
static strmap_t *unnamed_server_map = NULL;
-/** Most recently received and validated v3 consensus network status,
- * of whichever type we are using for our own circuits. This will be the same
- * as one of current_ns_consensus or current_md_consensus.
- */
-#define current_consensus \
- (we_use_microdescriptors_for_circuits(get_options()) ? \
- current_md_consensus : current_ns_consensus)
-
/** Most recently received and validated v3 "ns"-flavored consensus network
* status. */
static networkstatus_t *current_ns_consensus = NULL;
void
networkstatus_reset_warnings(void)
{
- if (current_consensus) {
+ if (networkstatus_get_latest_consensus()) {
SMARTLIST_FOREACH(nodelist_get_list(), node_t *, node,
node->name_lookup_warned = 0);
}
tor_free(filename);
}
- if (!current_consensus) {
+ if (!networkstatus_get_latest_consensus()) {
if (!named_server_map)
named_server_map = strmap_new();
if (!unnamed_server_map)
const char *digest))
{
if (!consensus)
- consensus = current_consensus;
+ consensus = networkstatus_get_latest_consensus();
if (!consensus)
return NULL;
if (!consensus->desc_digest_map) {
routerstatus_t *
router_get_mutable_consensus_status_by_id(const char *digest)
{
- if (!current_consensus)
+ if (!networkstatus_get_latest_consensus())
return NULL;
- return smartlist_bsearch(current_consensus->routerstatus_list, digest,
+ return smartlist_bsearch(networkstatus_get_latest_consensus()->routerstatus_list, digest,
compare_digest_to_routerstatus_entry);
}
MOCK_IMPL(networkstatus_t *,
networkstatus_get_latest_consensus,(void))
{
- return current_consensus;
+ if (we_use_microdescriptors_for_circuits(get_options()))
+ return current_md_consensus;
+ else
+ return current_ns_consensus;
}
/** Return the latest consensus we have whose flavor matches <b>f</b>, or NULL
MOCK_IMPL(networkstatus_t *,
networkstatus_get_live_consensus,(time_t now))
{
- if (current_consensus &&
- current_consensus->valid_after <= now &&
- now <= current_consensus->valid_until)
- return current_consensus;
+ if (networkstatus_get_latest_consensus() &&
+ networkstatus_get_latest_consensus()->valid_after <= now &&
+ now <= networkstatus_get_latest_consensus()->valid_until)
+ return networkstatus_get_latest_consensus();
else
return NULL;
}
const int is_usable_flavor = flav == usable_consensus_flavor();
if (is_usable_flavor) {
- notify_control_networkstatus_changed(current_consensus, c);
+ notify_control_networkstatus_changed(networkstatus_get_latest_consensus(), c);
}
if (flav == FLAV_NS) {
if (current_ns_consensus) {
networkstatus_copy_old_consensus_info(c, current_ns_consensus);
networkstatus_vote_free(current_ns_consensus);
- /* Defensive programming : we should set current_consensus very soon,
+ /* Defensive programming : we should set networkstatus_get_latest_consensus() very soon,
* but we're about to call some stuff in the meantime, and leaving this
* dangling pointer around has proven to be trouble. */
current_ns_consensus = NULL;
connection_or_update_token_buckets(get_connection_array(), options);
circuit_build_times_new_consensus_params(get_circuit_build_times_mutable(),
- current_consensus);
+ networkstatus_get_latest_consensus());
}
/* Reset the failure count only if this consensus is actually valid. */
static void
routerstatus_list_update_named_server_map(void)
{
- if (!current_consensus)
+ if (!networkstatus_get_latest_consensus())
return;
strmap_free(named_server_map, tor_free_);
named_server_map = strmap_new();
strmap_free(unnamed_server_map, NULL);
unnamed_server_map = strmap_new();
- SMARTLIST_FOREACH_BEGIN(current_consensus->routerstatus_list,
+ SMARTLIST_FOREACH_BEGIN(networkstatus_get_latest_consensus()->routerstatus_list,
const routerstatus_t *, rs) {
if (rs->is_named) {
strmap_set_lc(named_server_map, rs->nickname,
{
const or_options_t *options = get_options();
int authdir = authdir_mode_v3(options);
- networkstatus_t *ns = current_consensus;
+ networkstatus_t *ns = networkstatus_get_latest_consensus();
if (!ns || !smartlist_len(ns->routerstatus_list))
return;
const routerstatus_t *status;
(void) conn;
- if (!current_consensus) {
+ if (!networkstatus_get_latest_consensus()) {
*answer = tor_strdup("");
return 0;
}
if (!strcmp(question, "ns/all")) {
smartlist_t *statuses = smartlist_new();
- SMARTLIST_FOREACH(current_consensus->routerstatus_list,
+ SMARTLIST_FOREACH(networkstatus_get_latest_consensus()->routerstatus_list,
const routerstatus_t *, rs,
{
smartlist_add(statuses, networkstatus_getinfo_helper_single(rs));