mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
Remove named_map and unnamed_map from networkstatus.c
This commit is contained in:
parent
42b5e3cbb7
commit
035fe2d208
@ -66,12 +66,6 @@
|
|||||||
#include "torcert.h"
|
#include "torcert.h"
|
||||||
#include "channelpadding.h"
|
#include "channelpadding.h"
|
||||||
|
|
||||||
/** Map from lowercase nickname to identity digest of named server, if any. */
|
|
||||||
static strmap_t *named_server_map = NULL;
|
|
||||||
/** Map from lowercase nickname to (void*)1 for all names that are listed
|
|
||||||
* as unnamed for some server in the consensus. */
|
|
||||||
static strmap_t *unnamed_server_map = NULL;
|
|
||||||
|
|
||||||
/** Most recently received and validated v3 "ns"-flavored consensus network
|
/** Most recently received and validated v3 "ns"-flavored consensus network
|
||||||
* status. */
|
* status. */
|
||||||
STATIC networkstatus_t *current_ns_consensus = NULL;
|
STATIC networkstatus_t *current_ns_consensus = NULL;
|
||||||
@ -142,7 +136,6 @@ static int have_warned_about_old_version = 0;
|
|||||||
* listed by the authorities. */
|
* listed by the authorities. */
|
||||||
static int have_warned_about_new_version = 0;
|
static int have_warned_about_new_version = 0;
|
||||||
|
|
||||||
static void routerstatus_list_update_named_server_map(void);
|
|
||||||
static void update_consensus_bootstrap_multiple_downloads(
|
static void update_consensus_bootstrap_multiple_downloads(
|
||||||
time_t now,
|
time_t now,
|
||||||
const or_options_t *options);
|
const or_options_t *options);
|
||||||
@ -250,13 +243,6 @@ router_reload_consensus_networkstatus(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!networkstatus_get_latest_consensus()) {
|
|
||||||
if (!named_server_map)
|
|
||||||
named_server_map = strmap_new();
|
|
||||||
if (!unnamed_server_map)
|
|
||||||
unnamed_server_map = strmap_new();
|
|
||||||
}
|
|
||||||
|
|
||||||
update_certificate_downloads(time(NULL));
|
update_certificate_downloads(time(NULL));
|
||||||
|
|
||||||
routers_update_all_from_networkstatus(time(NULL), 3);
|
routers_update_all_from_networkstatus(time(NULL), 3);
|
||||||
@ -794,16 +780,6 @@ router_get_consensus_status_by_id(const char *digest)
|
|||||||
return router_get_mutable_consensus_status_by_id(digest);
|
return router_get_mutable_consensus_status_by_id(digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the identity digest that's mapped to officially by
|
|
||||||
* <b>nickname</b>. */
|
|
||||||
const char *
|
|
||||||
networkstatus_get_router_digest_by_nickname(const char *nickname)
|
|
||||||
{
|
|
||||||
if (!named_server_map)
|
|
||||||
return NULL;
|
|
||||||
return strmap_get_lc(named_server_map, nickname);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** How frequently do directory authorities re-download fresh networkstatus
|
/** How frequently do directory authorities re-download fresh networkstatus
|
||||||
* documents? */
|
* documents? */
|
||||||
#define AUTHORITY_NS_CACHE_INTERVAL (10*60)
|
#define AUTHORITY_NS_CACHE_INTERVAL (10*60)
|
||||||
@ -1960,7 +1936,6 @@ networkstatus_set_current_consensus(const char *consensus,
|
|||||||
update_consensus_networkstatus_fetch_time(now);
|
update_consensus_networkstatus_fetch_time(now);
|
||||||
|
|
||||||
dirvote_recalculate_timing(options, now);
|
dirvote_recalculate_timing(options, now);
|
||||||
routerstatus_list_update_named_server_map();
|
|
||||||
|
|
||||||
/* Update ewma and adjust policy if needed; first cache the old value */
|
/* Update ewma and adjust policy if needed; first cache the old value */
|
||||||
old_ewma_enabled = cell_ewma_enabled();
|
old_ewma_enabled = cell_ewma_enabled();
|
||||||
@ -2129,31 +2104,6 @@ routers_update_all_from_networkstatus(time_t now, int dir_version)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update our view of the list of named servers from the most recently
|
|
||||||
* retrieved networkstatus consensus. */
|
|
||||||
static void
|
|
||||||
routerstatus_list_update_named_server_map(void)
|
|
||||||
{
|
|
||||||
networkstatus_t *ns = networkstatus_get_latest_consensus();
|
|
||||||
if (!ns)
|
|
||||||
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_t *rslist = ns->routerstatus_list;
|
|
||||||
SMARTLIST_FOREACH_BEGIN(rslist, const routerstatus_t *, rs) {
|
|
||||||
if (rs->is_named) {
|
|
||||||
strmap_set_lc(named_server_map, rs->nickname,
|
|
||||||
tor_memdup(rs->identity_digest, DIGEST_LEN));
|
|
||||||
}
|
|
||||||
if (rs->is_unnamed) {
|
|
||||||
strmap_set_lc(unnamed_server_map, rs->nickname, (void*)1);
|
|
||||||
}
|
|
||||||
} SMARTLIST_FOREACH_END(rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Given a list <b>routers</b> of routerinfo_t *, update each status field
|
/** Given a list <b>routers</b> of routerinfo_t *, update each status field
|
||||||
* according to our current consensus networkstatus. May re-order
|
* according to our current consensus networkstatus. May re-order
|
||||||
* <b>routers</b>. */
|
* <b>routers</b>. */
|
||||||
@ -2639,8 +2589,5 @@ networkstatus_free_all(void)
|
|||||||
}
|
}
|
||||||
tor_free(waiting->body);
|
tor_free(waiting->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
strmap_free(named_server_map, tor_free_);
|
|
||||||
strmap_free(unnamed_server_map, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,6 @@ const routerstatus_t *router_get_consensus_status_by_descriptor_digest(
|
|||||||
MOCK_DECL(routerstatus_t *,
|
MOCK_DECL(routerstatus_t *,
|
||||||
router_get_mutable_consensus_status_by_descriptor_digest,
|
router_get_mutable_consensus_status_by_descriptor_digest,
|
||||||
(networkstatus_t *consensus, const char *digest));
|
(networkstatus_t *consensus, const char *digest));
|
||||||
const char *networkstatus_get_router_digest_by_nickname(const char *nickname);
|
|
||||||
int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
|
int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
|
||||||
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
|
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options);
|
||||||
void networkstatus_consensus_download_failed(int status_code,
|
void networkstatus_consensus_download_failed(int status_code,
|
||||||
|
@ -850,15 +850,6 @@ node_get_by_nickname,(const char *nickname, unsigned flags))
|
|||||||
if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
|
if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Okay, so if we get here, the nickname is just a nickname. Is there
|
|
||||||
* a binding for it in the consensus? */
|
|
||||||
{
|
|
||||||
const char *named_id =
|
|
||||||
networkstatus_get_router_digest_by_nickname(nickname);
|
|
||||||
if (named_id)
|
|
||||||
return node_get_by_id(named_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Okay, so the name is not canonical for anybody. */
|
/* Okay, so the name is not canonical for anybody. */
|
||||||
{
|
{
|
||||||
smartlist_t *matches = smartlist_new();
|
smartlist_t *matches = smartlist_new();
|
||||||
|
@ -3497,7 +3497,7 @@ router_get_description(char *buf, const routerinfo_t *ri)
|
|||||||
return "<null>";
|
return "<null>";
|
||||||
return format_node_description(buf,
|
return format_node_description(buf,
|
||||||
ri->cache_info.identity_digest,
|
ri->cache_info.identity_digest,
|
||||||
router_is_named(ri),
|
0,
|
||||||
ri->nickname,
|
ri->nickname,
|
||||||
NULL,
|
NULL,
|
||||||
ri->addr);
|
ri->addr);
|
||||||
@ -3623,21 +3623,16 @@ extend_info_describe(const extend_info_t *ei)
|
|||||||
* verbose representation of the identity of <b>router</b>. The format is:
|
* verbose representation of the identity of <b>router</b>. The format is:
|
||||||
* A dollar sign.
|
* A dollar sign.
|
||||||
* The upper-case hexadecimal encoding of the SHA1 hash of router's identity.
|
* The upper-case hexadecimal encoding of the SHA1 hash of router's identity.
|
||||||
* A "=" if the router is named; a "~" if it is not.
|
* A "=" if the router is named (no longer implemented); a "~" if it is not.
|
||||||
* The router's nickname.
|
* The router's nickname.
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
router_get_verbose_nickname(char *buf, const routerinfo_t *router)
|
router_get_verbose_nickname(char *buf, const routerinfo_t *router)
|
||||||
{
|
{
|
||||||
const char *good_digest = networkstatus_get_router_digest_by_nickname(
|
|
||||||
router->nickname);
|
|
||||||
int is_named = good_digest && tor_memeq(good_digest,
|
|
||||||
router->cache_info.identity_digest,
|
|
||||||
DIGEST_LEN);
|
|
||||||
buf[0] = '$';
|
buf[0] = '$';
|
||||||
base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
|
base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
buf[1+HEX_DIGEST_LEN] = is_named ? '=' : '~';
|
buf[1+HEX_DIGEST_LEN] = '~';
|
||||||
strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
|
strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2957,18 +2957,6 @@ hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest,
|
|||||||
return tor_memeq(digest, identity_digest, DIGEST_LEN);
|
return tor_memeq(digest, identity_digest, DIGEST_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return true iff <b>router</b> is listed as named in the current
|
|
||||||
* consensus. */
|
|
||||||
int
|
|
||||||
router_is_named(const routerinfo_t *router)
|
|
||||||
{
|
|
||||||
const char *digest =
|
|
||||||
networkstatus_get_router_digest_by_nickname(router->nickname);
|
|
||||||
|
|
||||||
return (digest &&
|
|
||||||
tor_memeq(digest, router->cache_info.identity_digest, DIGEST_LEN));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true iff <b>digest</b> is the digest of the identity key of a
|
/** Return true iff <b>digest</b> is the digest of the identity key of a
|
||||||
* trusted directory matching at least one bit of <b>type</b>. If <b>type</b>
|
* trusted directory matching at least one bit of <b>type</b>. If <b>type</b>
|
||||||
* is zero (NO_DIRINFO), or ALL_DIRINFO, any authority is okay. */
|
* is zero (NO_DIRINFO), or ALL_DIRINFO, any authority is okay. */
|
||||||
|
@ -80,7 +80,6 @@ const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
|
|||||||
struct routerset_t *excludedset,
|
struct routerset_t *excludedset,
|
||||||
router_crn_flags_t flags);
|
router_crn_flags_t flags);
|
||||||
|
|
||||||
int router_is_named(const routerinfo_t *router);
|
|
||||||
int router_digest_is_trusted_dir_type(const char *digest,
|
int router_digest_is_trusted_dir_type(const char *digest,
|
||||||
dirinfo_type_t type);
|
dirinfo_type_t type);
|
||||||
#define router_digest_is_trusted_dir(d) \
|
#define router_digest_is_trusted_dir(d) \
|
||||||
|
Loading…
Reference in New Issue
Block a user