tor  0.4.0.0-alpha-dev
Macros | Functions | Variables
voteflags.c File Reference
#include "core/or/or.h"
#include "feature/dirauth/voteflags.h"
#include "app/config/config.h"
#include "core/mainloop/mainloop.h"
#include "core/or/policies.h"
#include "feature/dirauth/bwauth.h"
#include "feature/dirauth/reachability.h"
#include "feature/hibernate/hibernate.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/relay/router.h"
#include "feature/stats/rephist.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/vote_routerstatus_st.h"
#include "lib/container/order.h"

Go to the source code of this file.

Macros

#define VOTEFLAGS_PRIVATE
 
#define UPTIME_TO_GUARANTEE_STABLE   (3600*24*30)
 
#define MTBF_TO_GUARANTEE_STABLE   (60*60*24*5)
 
#define TIME_KNOWN_TO_GUARANTEE_FAMILIAR   (8*24*60*60)
 
#define WFU_TO_GUARANTEE_GUARD   (0.98)
 
#define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB   4
 
#define ABSOLUTE_MIN_VALUE_FOR_FAST_FLAG   4
 
#define REACHABLE_TIMEOUT   (45*60)
 
#define HIBERNATION_PUBLICATION_SKEW   (60*60)
 

Functions

static long real_uptime (const routerinfo_t *router, time_t now)
 
static int dirserv_thinks_router_is_unreliable (time_t now, const routerinfo_t *router, int need_uptime, int need_capacity)
 
static int router_is_active (const routerinfo_t *ri, const node_t *node, time_t now)
 
static int dirserv_thinks_router_is_hs_dir (const routerinfo_t *router, const node_t *node, time_t now)
 
static int router_counts_toward_thresholds (const node_t *node, time_t now, const digestmap_t *omit_as_sybil, int require_mbw)
 
void dirserv_compute_performance_thresholds (digestmap_t *omit_as_sybil)
 
void dirserv_compute_bridge_flag_thresholds (void)
 
char * dirserv_get_flag_thresholds_line (void)
 
int running_long_enough_to_decide_unreachable (void)
 
void dirserv_set_router_is_running (routerinfo_t *router, time_t now)
 
void set_routerstatus_from_routerinfo (routerstatus_t *rs, node_t *node, const routerinfo_t *ri, time_t now, int listbadexits)
 
STATIC void dirserv_set_routerstatus_testing (routerstatus_t *rs)
 

Variables

static uint32_t stable_uptime = 0
 
static double stable_mtbf = 0.0
 
static int enough_mtbf_info = 0
 
static double guard_wfu = 0.0
 
static long guard_tk = 0
 
static uint32_t fast_bandwidth_kb = 0
 
static uint32_t guard_bandwidth_including_exits_kb = 0
 
static uint32_t guard_bandwidth_excluding_exits_kb = 0
 

Detailed Description

Authority code for deciding the performance thresholds for flags, and assigning flags to routers.

Definition in file voteflags.c.

Macro Definition Documentation

◆ ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB

#define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB   4

Don't consider routers with less bandwidth than this when computing thresholds.

Definition at line 199 of file voteflags.c.

Referenced by router_counts_toward_thresholds().

◆ HIBERNATION_PUBLICATION_SKEW

#define HIBERNATION_PUBLICATION_SKEW   (60*60)

If we tested a router and found it reachable at least this long after it declared itself hibernating, it is probably done hibernating and we just missed a descriptor from it.

Definition at line 469 of file voteflags.c.

Referenced by dirserv_set_router_is_running().

◆ MTBF_TO_GUARANTEE_STABLE

#define MTBF_TO_GUARANTEE_STABLE   (60*60*24*5)

If a router's MTBF is at least this value, then it is always stable. See above. (Corresponds to about 7 days for current decay rates.)

Definition at line 44 of file voteflags.c.

Referenced by dirserv_thinks_router_is_unreliable().

◆ REACHABLE_TIMEOUT

#define REACHABLE_TIMEOUT   (45*60)

Each server needs to have passed a reachability test no more than this number of seconds ago, or it is listed as down in the directory.

Definition at line 464 of file voteflags.c.

Referenced by dirserv_set_router_is_running().

◆ TIME_KNOWN_TO_GUARANTEE_FAMILIAR

#define TIME_KNOWN_TO_GUARANTEE_FAMILIAR   (8*24*60*60)

Similarly, every node with at least this much weighted time known can be considered familiar enough to be a guard. Corresponds to about 20 days for current decay rates.

Definition at line 49 of file voteflags.c.

◆ UPTIME_TO_GUARANTEE_STABLE

#define UPTIME_TO_GUARANTEE_STABLE   (3600*24*30)

If a router's uptime is at least this value, then it is always considered stable, regardless of the rest of the network. This way we resist attacks where an attacker doubles the size of the network using allegedly high-uptime nodes, displacing all the current guards.

Definition at line 41 of file voteflags.c.

Referenced by dirserv_thinks_router_is_unreliable().

◆ WFU_TO_GUARANTEE_GUARD

#define WFU_TO_GUARANTEE_GUARD   (0.98)

Similarly, every node with sufficient WFU is around enough to be a guard.

Definition at line 52 of file voteflags.c.

Function Documentation

◆ dirserv_compute_performance_thresholds()

void dirserv_compute_performance_thresholds ( digestmap_t *  omit_as_sybil)

Look through the routerlist, the Mean Time Between Failure history, and the Weighted Fractional Uptime history, and use them to set thresholds for the Stable, Fast, and Guard flags. Update the fields stable_uptime, stable_mtbf, enough_mtbf_info, guard_wfu, guard_tk, fast_bandwidth, guard_bandwidth_including_exits, and guard_bandwidth_excluding_exits.

Also, set the is_exit flag of each router appropriately.

Definition at line 235 of file voteflags.c.

References dirserv_get_last_n_measured_bws(), fast_bandwidth_kb, guard_bandwidth_excluding_exits_kb, guard_bandwidth_including_exits_kb, guard_tk, guard_wfu, or_options_t::MinMeasuredBWsForAuthToIgnoreAdvertised, nodelist_assert_ok(), stable_mtbf, and stable_uptime.

◆ dirserv_get_flag_thresholds_line()

char* dirserv_get_flag_thresholds_line ( void  )

Give a statement of our current performance thresholds for inclusion in a vote document.

Definition at line 426 of file voteflags.c.

References dirserv_get_last_n_measured_bws(), enough_mtbf_info, fast_bandwidth_kb, guard_bandwidth_excluding_exits_kb, guard_bandwidth_including_exits_kb, guard_tk, guard_wfu, stable_mtbf, stable_uptime, and tor_asprintf().

◆ dirserv_set_router_is_running()

void dirserv_set_router_is_running ( routerinfo_t router,
time_t  now 
)

◆ dirserv_set_routerstatus_testing()

STATIC void dirserv_set_routerstatus_testing ( routerstatus_t rs)

Use TestingDirAuthVoteExit, TestingDirAuthVoteGuard, and TestingDirAuthVoteHSDir to give out the Exit, Guard, and HSDir flags, respectively. But don't set the corresponding node flags. Should only be called if TestingTorNetwork is set.

Definition at line 622 of file voteflags.c.

References routerstatus_t::is_exit, routerstatus_t::is_hs_dir, routerstatus_t::is_possible_guard, routerset_contains_routerstatus(), or_options_t::TestingDirAuthVoteExit, or_options_t::TestingDirAuthVoteGuard, or_options_t::TestingDirAuthVoteHSDir, or_options_t::TestingTorNetwork, and tor_assert().

◆ dirserv_thinks_router_is_hs_dir()

static int dirserv_thinks_router_is_hs_dir ( const routerinfo_t router,
const node_t node,
time_t  now 
)
static

Return true iff router should be assigned the "HSDir" flag.

Right now this means it advertises support for it, it has a high uptime, it's a directory cache, it has the Stable and Fast flags, and it's currently considered Running.

This function needs to be called after router->is_running has been set.

Definition at line 170 of file voteflags.c.

◆ dirserv_thinks_router_is_unreliable()

static int dirserv_thinks_router_is_unreliable ( time_t  now,
const routerinfo_t router,
int  need_uptime,
int  need_capacity 
)
static

Return 1 if router is not suitable for these parameters, else 0. If need_uptime is non-zero, we require a minimum uptime. If need_capacity is non-zero, we require a minimum advertised bandwidth.

Definition at line 97 of file voteflags.c.

References dirserv_get_credible_bandwidth_kb(), enough_mtbf_info, fast_bandwidth_kb, signed_descriptor_t::identity_digest, MTBF_TO_GUARANTEE_STABLE, real_uptime(), rep_hist_get_stability(), stable_mtbf, stable_uptime, and UPTIME_TO_GUARANTEE_STABLE.

◆ real_uptime()

static long real_uptime ( const routerinfo_t router,
time_t  now 
)
inlinestatic

Helper: estimate the uptime of a router given its stated uptime and the amount of time since it last stated its stated uptime.

Definition at line 83 of file voteflags.c.

References signed_descriptor_t::published_on, and routerinfo_t::uptime.

Referenced by dirserv_thinks_router_is_unreliable().

◆ router_counts_toward_thresholds()

static int router_counts_toward_thresholds ( const node_t node,
time_t  now,
const digestmap_t *  omit_as_sybil,
int  require_mbw 
)
static

Helper for dirserv_compute_performance_thresholds(): Decide whether to include a router in our calculations, and return true iff we should; the require_mbw parameter is passed in by dirserv_compute_performance_thresholds() and controls whether we ever count routers with only advertised bandwidths

Definition at line 207 of file voteflags.c.

References ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB, dirserv_get_credible_bandwidth_kb(), dirserv_has_measured_bw(), node_t::identity, router_is_active(), or_options_t::TestingMinExitFlagThreshold, and or_options_t::TestingTorNetwork.

◆ router_is_active()

static int router_is_active ( const routerinfo_t ri,
const node_t node,
time_t  now 
)
static

Return 1 if ri's descriptor is "active" – running, valid, not hibernating, having observed bw greater 0, and not too old. Else return 0.

Definition at line 134 of file voteflags.c.

References routerinfo_t::bandwidthcapacity, routerinfo_t::is_hibernating, node_t::is_running, node_t::is_valid, signed_descriptor_t::published_on, and ROUTER_MAX_AGE_TO_PUBLISH.

Referenced by router_counts_toward_thresholds().

◆ set_routerstatus_from_routerinfo()

void set_routerstatus_from_routerinfo ( routerstatus_t rs,
node_t node,
const routerinfo_t ri,
time_t  now,
int  listbadexits 
)

Extract status information from ri and from other authority functions and store it in rs. rs is zeroed out before it is set.

We assume that ri->is_running has already been set, e.g. by dirserv_set_router_is_running(ri, now);

Definition at line 542 of file voteflags.c.

References dirserv_get_credible_bandwidth_kb(), and routerstatus_t::is_authority.

Variable Documentation

◆ enough_mtbf_info

int enough_mtbf_info = 0
static

If true, we have measured enough mtbf info to look at stable_mtbf rather than stable_uptime.

Definition at line 64 of file voteflags.c.

Referenced by dirserv_get_flag_thresholds_line(), and dirserv_thinks_router_is_unreliable().

◆ fast_bandwidth_kb

uint32_t fast_bandwidth_kb = 0
static

Any router with a bandwidth at least this high is "Fast"

Definition at line 72 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), dirserv_get_flag_thresholds_line(), and dirserv_thinks_router_is_unreliable().

◆ guard_bandwidth_excluding_exits_kb

uint32_t guard_bandwidth_excluding_exits_kb = 0
static

If exits can't be guards, then all guards must have a bandwidth this high.

Definition at line 78 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), and dirserv_get_flag_thresholds_line().

◆ guard_bandwidth_including_exits_kb

uint32_t guard_bandwidth_including_exits_kb = 0
static

If exits can be guards, then all guards must have a bandwidth this high.

Definition at line 75 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), and dirserv_get_flag_thresholds_line().

◆ guard_tk

long guard_tk = 0
static

Don't call a router a guard unless we've known about it for at least this many seconds.

Definition at line 70 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), and dirserv_get_flag_thresholds_line().

◆ guard_wfu

double guard_wfu = 0.0
static

Any router with a weighted fractional uptime of at least this much might be good as a guard.

Definition at line 67 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), and dirserv_get_flag_thresholds_line().

◆ stable_mtbf

double stable_mtbf = 0.0
static

Any router with an mtbf of at least this value is stable.

Definition at line 61 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), dirserv_get_flag_thresholds_line(), and dirserv_thinks_router_is_unreliable().

◆ stable_uptime

uint32_t stable_uptime = 0
static

Any router with an uptime of at least this value is stable.

Definition at line 59 of file voteflags.c.

Referenced by dirserv_compute_performance_thresholds(), dirserv_get_flag_thresholds_line(), and dirserv_thinks_router_is_unreliable().