Tor  0.4.8.0-alpha-dev
voteflags.c
Go to the documentation of this file.
1 /* Copyright (c) 2001-2004, Roger Dingledine.
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file voteflags.c
8  * \brief Authority code for deciding the performance thresholds for flags,
9  * and assigning flags to routers.
10  **/
11 
12 #define VOTEFLAGS_PRIVATE
13 #include "core/or/or.h"
15 
16 #include "app/config/config.h"
17 #include "core/mainloop/mainloop.h"
18 #include "core/or/policies.h"
19 #include "feature/dirauth/bwauth.h"
28 #include "feature/relay/router.h"
29 #include "feature/stats/rephist.h"
30 
36 
37 #include "lib/container/order.h"
38 
39 /* Thresholds for server performance: set by
40  * dirserv_compute_performance_thresholds, and used by
41  * generate_v2_networkstatus */
42 
43 /** Any router with an uptime of at least this value is stable. */
44 static uint32_t stable_uptime = 0; /* start at a safe value */
45 /** Any router with an mtbf of at least this value is stable. */
46 static double stable_mtbf = 0.0;
47 /** If true, we have measured enough mtbf info to look at stable_mtbf rather
48  * than stable_uptime. */
49 static int enough_mtbf_info = 0;
50 /** Any router with a weighted fractional uptime of at least this much might
51  * be good as a guard. */
52 static double guard_wfu = 0.0;
53 /** Don't call a router a guard unless we've known about it for at least this
54  * many seconds. */
55 static long guard_tk = 0;
56 /** Any router with a bandwidth at least this high is "Fast" */
57 static uint32_t fast_bandwidth_kb = 0;
58 /** If exits can be guards, then all guards must have a bandwidth this
59  * high. */
61 /** If exits can't be guards, then all guards must have a bandwidth this
62  * high. */
64 
65 /** Helper: estimate the uptime of a router given its stated uptime and the
66  * amount of time since it last stated its stated uptime. */
67 static inline long
68 real_uptime(const routerinfo_t *router, time_t now)
69 {
70  if (now < router->cache_info.published_on)
71  return router->uptime;
72  else
73  return router->uptime + (now - router->cache_info.published_on);
74 }
75 
76 /** Return 1 if <b>router</b> is not suitable for these parameters, else 0.
77  * If <b>need_uptime</b> is non-zero, we require a minimum uptime.
78  * If <b>need_capacity</b> is non-zero, we require a minimum advertised
79  * bandwidth.
80  */
81 static int
83  const routerinfo_t *router,
84  int need_uptime, int need_capacity)
85 {
86  if (need_uptime) {
87  if (!enough_mtbf_info) {
88  /* XXXX We should change the rule from
89  * "use uptime if we don't have mtbf data" to "don't advertise Stable on
90  * v3 if we don't have enough mtbf data." Or maybe not, since if we ever
91  * hit a point where we need to reset a lot of authorities at once,
92  * none of them would be in a position to declare Stable.
93  */
94  long uptime = real_uptime(router, now);
95  if ((unsigned)uptime < stable_uptime &&
96  uptime < dirauth_get_options()->AuthDirVoteStableGuaranteeMinUptime)
97  return 1;
98  } else {
99  double mtbf =
100  rep_hist_get_stability(router->cache_info.identity_digest, now);
101  if (mtbf < stable_mtbf &&
102  mtbf < dirauth_get_options()->AuthDirVoteStableGuaranteeMTBF)
103  return 1;
104  }
105  }
106  if (need_capacity) {
107  uint32_t bw_kb = dirserv_get_credible_bandwidth_kb(router);
108  if (bw_kb < fast_bandwidth_kb)
109  return 1;
110  }
111  return 0;
112 }
113 
114 /** Return 1 if <b>ri</b>'s descriptor is "active" -- running, valid,
115  * not hibernating, having observed bw greater 0, and not too old. Else
116  * return 0.
117  */
118 static int
119 router_is_active(const routerinfo_t *ri, const node_t *node, time_t now)
120 {
121  time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
122  if (ri->cache_info.published_on < cutoff) {
123  return 0;
124  }
125  if (!node->is_running || !node->is_valid || ri->is_hibernating) {
126  return 0;
127  }
128  /* Only require bandwidth capacity in non-test networks, or
129  * if TestingTorNetwork, and TestingMinExitFlagThreshold is non-zero */
130  if (!ri->bandwidthcapacity) {
131  if (get_options()->TestingTorNetwork) {
132  if (dirauth_get_options()->TestingMinExitFlagThreshold > 0) {
133  /* If we're in a TestingTorNetwork, and TestingMinExitFlagThreshold is,
134  * then require bandwidthcapacity */
135  return 0;
136  }
137  } else {
138  /* If we're not in a TestingTorNetwork, then require bandwidthcapacity */
139  return 0;
140  }
141  }
142  return 1;
143 }
144 
145 /** Return true iff <b>router</b> should be assigned the "HSDir" flag.
146  *
147  * Right now this means it advertises support for it, it has a high uptime,
148  * it's a directory cache, it has the Stable and Fast flags, and it's currently
149  * considered Running.
150  *
151  * This function needs to be called after router->is_running has
152  * been set.
153  */
154 static int
156  const node_t *node, time_t now)
157 {
158 
159  long uptime;
160 
161  /* If we haven't been running for at least
162  * MinUptimeHidServDirectoryV2 seconds, we can't
163  * have accurate data telling us a relay has been up for at least
164  * that long. We also want to allow a bit of slack: Reachability
165  * tests aren't instant. If we haven't been running long enough,
166  * trust the relay. */
167 
168  if (get_uptime() >
169  dirauth_get_options()->MinUptimeHidServDirectoryV2 * 1.1)
170  uptime = MIN(rep_hist_get_uptime(router->cache_info.identity_digest, now),
171  real_uptime(router, now));
172  else
173  uptime = real_uptime(router, now);
174 
175  return (router->wants_to_be_hs_dir &&
177  node->is_stable && node->is_fast &&
178  uptime >= dirauth_get_options()->MinUptimeHidServDirectoryV2 &&
179  router_is_active(router, node, now));
180 }
181 
182 /** Don't consider routers with less bandwidth than this when computing
183  * thresholds. */
184 #define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB 4
185 
186 /** Helper for dirserv_compute_performance_thresholds(): Decide whether to
187  * include a router in our calculations, and return true iff we should; the
188  * require_mbw parameter is passed in by
189  * dirserv_compute_performance_thresholds() and controls whether we ever
190  * count routers with only advertised bandwidths */
191 static int
192 router_counts_toward_thresholds(const node_t *node, time_t now,
193  const digestmap_t *omit_as_sybil,
194  int require_mbw)
195 {
196  /* Have measured bw? */
197  int have_mbw =
199  uint64_t min_bw_kb = ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB;
200  const or_options_t *options = get_options();
201  const dirauth_options_t *dirauth_options = dirauth_get_options();
202 
203  if (options->TestingTorNetwork) {
204  min_bw_kb = (int64_t)dirauth_options->TestingMinExitFlagThreshold / 1000;
205  }
206 
207  return node->ri && router_is_active(node->ri, node, now) &&
208  !digestmap_get(omit_as_sybil, node->identity) &&
209  (dirserv_get_credible_bandwidth_kb(node->ri) >= min_bw_kb) &&
210  (have_mbw || !require_mbw);
211 }
212 
213 /** Look through the routerlist, the Mean Time Between Failure history, and
214  * the Weighted Fractional Uptime history, and use them to set thresholds for
215  * the Stable, Fast, and Guard flags. Update the fields stable_uptime,
216  * stable_mtbf, enough_mtbf_info, guard_wfu, guard_tk, fast_bandwidth,
217  * guard_bandwidth_including_exits, and guard_bandwidth_excluding_exits.
218  *
219  * Also, set the is_exit flag of each router appropriately. */
220 void
221 dirserv_compute_performance_thresholds(digestmap_t *omit_as_sybil)
222 {
223  int n_active, n_active_nonexit, n_familiar;
224  uint32_t *uptimes, *bandwidths_kb, *bandwidths_excluding_exits_kb;
225  long *tks;
226  double *mtbfs, *wfus;
227  const smartlist_t *nodelist;
228  time_t now = time(NULL);
229  const or_options_t *options = get_options();
230  const dirauth_options_t *dirauth_options = dirauth_get_options();
231 
232  /* Require mbw? */
233  int require_mbw =
235  dirauth_options->MinMeasuredBWsForAuthToIgnoreAdvertised) ? 1 : 0;
236 
237  /* initialize these all here, in case there are no routers */
238  stable_uptime = 0;
239  stable_mtbf = 0;
240  fast_bandwidth_kb = 0;
243  guard_tk = 0;
244  guard_wfu = 0;
245 
247  nodelist = nodelist_get_list();
248 
249  /* Initialize arrays that will hold values for each router. We'll
250  * sort them and use that to compute thresholds. */
251  n_active = n_active_nonexit = 0;
252  /* Uptime for every active router. */
253  uptimes = tor_calloc(smartlist_len(nodelist), sizeof(uint32_t));
254  /* Bandwidth for every active router. */
255  bandwidths_kb = tor_calloc(smartlist_len(nodelist), sizeof(uint32_t));
256  /* Bandwidth for every active non-exit router. */
257  bandwidths_excluding_exits_kb =
258  tor_calloc(smartlist_len(nodelist), sizeof(uint32_t));
259  /* Weighted mean time between failure for each active router. */
260  mtbfs = tor_calloc(smartlist_len(nodelist), sizeof(double));
261  /* Time-known for each active router. */
262  tks = tor_calloc(smartlist_len(nodelist), sizeof(long));
263  /* Weighted fractional uptime for each active router. */
264  wfus = tor_calloc(smartlist_len(nodelist), sizeof(double));
265 
266  /* Now, fill in the arrays. */
267  SMARTLIST_FOREACH_BEGIN(nodelist, node_t *, node) {
268  if (options->BridgeAuthoritativeDir &&
269  node->ri &&
270  node->ri->purpose != ROUTER_PURPOSE_BRIDGE)
271  continue;
272 
273  routerinfo_t *ri = node->ri;
274  if (ri) {
275  node->is_exit = (!router_exit_policy_rejects_all(ri) &&
277  }
278 
279  if (router_counts_toward_thresholds(node, now, omit_as_sybil,
280  require_mbw)) {
281  const char *id = node->identity;
282  uint32_t bw_kb;
283 
284  /* resolve spurious clang shallow analysis null pointer errors */
285  tor_assert(ri);
286 
287  uptimes[n_active] = (uint32_t)real_uptime(ri, now);
288  mtbfs[n_active] = rep_hist_get_stability(id, now);
289  tks [n_active] = rep_hist_get_weighted_time_known(id, now);
290  bandwidths_kb[n_active] = bw_kb = dirserv_get_credible_bandwidth_kb(ri);
291  if (!node->is_exit || node->is_bad_exit) {
292  bandwidths_excluding_exits_kb[n_active_nonexit] = bw_kb;
293  ++n_active_nonexit;
294  }
295  ++n_active;
296  }
297  } SMARTLIST_FOREACH_END(node);
298 
299  /* Now, compute thresholds. */
300  if (n_active) {
301  /* The median uptime is stable. */
302  stable_uptime = median_uint32(uptimes, n_active);
303  /* The median mtbf is stable, if we have enough mtbf info */
304  stable_mtbf = median_double(mtbfs, n_active);
305  /* The 12.5th percentile bandwidth is fast. */
306  fast_bandwidth_kb = find_nth_uint32(bandwidths_kb, n_active, n_active/8);
307  /* (Now bandwidths is sorted.) */
308  if (fast_bandwidth_kb < RELAY_REQUIRED_MIN_BANDWIDTH/(2 * 1000))
309  fast_bandwidth_kb = bandwidths_kb[n_active/4];
310  int nth = (int)(n_active *
311  dirauth_options->AuthDirVoteGuardBwThresholdFraction);
313  find_nth_uint32(bandwidths_kb, n_active, nth);
314  guard_tk = find_nth_long(tks, n_active, n_active/8);
315  }
316 
317  if (guard_tk > dirauth_options->AuthDirVoteGuardGuaranteeTimeKnown)
318  guard_tk = dirauth_options->AuthDirVoteGuardGuaranteeTimeKnown;
319 
320  {
321  /* We can vote on a parameter for the minimum and maximum. */
322 #define ABSOLUTE_MIN_VALUE_FOR_FAST_FLAG 4
323  int32_t min_fast_kb, max_fast_kb, min_fast, max_fast;
324  min_fast = networkstatus_get_param(NULL, "FastFlagMinThreshold",
325  ABSOLUTE_MIN_VALUE_FOR_FAST_FLAG,
326  ABSOLUTE_MIN_VALUE_FOR_FAST_FLAG,
327  INT32_MAX);
328  if (options->TestingTorNetwork) {
329  min_fast = (int32_t)dirauth_options->TestingMinFastFlagThreshold;
330  }
331  max_fast = networkstatus_get_param(NULL, "FastFlagMaxThreshold",
332  INT32_MAX, min_fast, INT32_MAX);
333  min_fast_kb = min_fast / 1000;
334  max_fast_kb = max_fast / 1000;
335 
336  if (fast_bandwidth_kb < (uint32_t)min_fast_kb)
337  fast_bandwidth_kb = min_fast_kb;
338  if (fast_bandwidth_kb > (uint32_t)max_fast_kb)
339  fast_bandwidth_kb = max_fast_kb;
340  }
341  /* Protect sufficiently fast nodes from being pushed out of the set
342  * of Fast nodes. */
343  {
344  const uint64_t fast_opt = dirauth_get_options()->AuthDirFastGuarantee;
345  if (fast_opt && fast_bandwidth_kb > fast_opt / 1000)
346  fast_bandwidth_kb = (uint32_t)(fast_opt / 1000);
347  }
348 
349  /* Now that we have a time-known that 7/8 routers are known longer than,
350  * fill wfus with the wfu of every such "familiar" router. */
351  n_familiar = 0;
352 
353  SMARTLIST_FOREACH_BEGIN(nodelist, node_t *, node) {
354  if (router_counts_toward_thresholds(node, now,
355  omit_as_sybil, require_mbw)) {
356  routerinfo_t *ri = node->ri;
357  const char *id = ri->cache_info.identity_digest;
358  long tk = rep_hist_get_weighted_time_known(id, now);
359  if (tk < guard_tk)
360  continue;
361  wfus[n_familiar++] = rep_hist_get_weighted_fractional_uptime(id, now);
362  }
363  } SMARTLIST_FOREACH_END(node);
364  if (n_familiar)
365  guard_wfu = median_double(wfus, n_familiar);
366  if (guard_wfu > dirauth_options->AuthDirVoteGuardGuaranteeWFU)
367  guard_wfu = dirauth_options->AuthDirVoteGuardGuaranteeWFU;
368 
370 
371  if (n_active_nonexit) {
372  int nth = (int)(n_active_nonexit *
373  dirauth_options->AuthDirVoteGuardBwThresholdFraction);
375  find_nth_uint32(bandwidths_excluding_exits_kb, n_active_nonexit, nth);
376  }
377 
378  log_info(LD_DIRSERV,
379  "Cutoffs: For Stable, %lu sec uptime, %lu sec MTBF. "
380  "For Fast: %lu kilobytes/sec. "
381  "For Guard: WFU %.03f%%, time-known %lu sec, "
382  "and bandwidth %lu or %lu kilobytes/sec. "
383  "We%s have enough stability data.",
384  (unsigned long)stable_uptime,
385  (unsigned long)stable_mtbf,
386  (unsigned long)fast_bandwidth_kb,
387  guard_wfu*100,
388  (unsigned long)guard_tk,
389  (unsigned long)guard_bandwidth_including_exits_kb,
390  (unsigned long)guard_bandwidth_excluding_exits_kb,
391  enough_mtbf_info ? "" : " don't");
392 
393  tor_free(uptimes);
394  tor_free(mtbfs);
395  tor_free(bandwidths_kb);
396  tor_free(bandwidths_excluding_exits_kb);
397  tor_free(tks);
398  tor_free(wfus);
399 }
400 
401 /* Use dirserv_compute_performance_thresholds() to compute the thresholds
402  * for the status flags, specifically for bridges.
403  *
404  * This is only called by a Bridge Authority from
405  * networkstatus_getinfo_by_purpose().
406  */
407 void
408 dirserv_compute_bridge_flag_thresholds(void)
409 {
410  digestmap_t *omit_as_sybil = digestmap_new();
412  digestmap_free(omit_as_sybil, NULL);
413 }
414 
415 /** Give a statement of our current performance thresholds for inclusion
416  * in a vote document. */
417 char *
419 {
420  char *result=NULL;
421  const int measured_threshold =
422  dirauth_get_options()->MinMeasuredBWsForAuthToIgnoreAdvertised;
423  const int enough_measured_bw =
424  dirserv_get_last_n_measured_bws() > measured_threshold;
425 
426  tor_asprintf(&result,
427  "stable-uptime=%lu stable-mtbf=%lu "
428  "fast-speed=%lu "
429  "guard-wfu=%.03f%% guard-tk=%lu "
430  "guard-bw-inc-exits=%lu guard-bw-exc-exits=%lu "
431  "enough-mtbf=%d ignoring-advertised-bws=%d",
432  (unsigned long)stable_uptime,
433  (unsigned long)stable_mtbf,
434  (unsigned long)fast_bandwidth_kb*1000,
435  guard_wfu*100,
436  (unsigned long)guard_tk,
437  (unsigned long)guard_bandwidth_including_exits_kb*1000,
438  (unsigned long)guard_bandwidth_excluding_exits_kb*1000,
439  enough_mtbf_info ? 1 : 0,
440  enough_measured_bw ? 1 : 0);
441 
442  return result;
443 }
444 
445 /** Directory authorities should avoid expressing an opinion on the
446  * Running flag if their own uptime is too low for the opinion to be
447  * accurate. They implement this step by not listing Running on the
448  * "known-flags" line in their vote.
449  *
450  * The default threshold is 30 minutes, because authorities do a full
451  * reachability sweep of the ID space every 10*128=1280 seconds
452  * (see REACHABILITY_TEST_CYCLE_PERIOD).
453  *
454  * For v3 dir auths, as long as some authorities express an opinion about
455  * Running, it's fine if a few authorities don't. There's an explicit
456  * check, when making the consensus, to abort if *no* authorities list
457  * Running as a known-flag.
458  *
459  * For the bridge authority, if it doesn't vote about Running, the
460  * resulting networkstatus file simply won't list any bridges as Running.
461  * That means the supporting tools, like bridgedb/rdsys and onionoo, need
462  * to be able to handle getting a bridge networkstatus document with no
463  * Running flags. For more details, see
464  * https://bugs.torproject.org/tpo/anti-censorship/rdsys/102 */
465 int
467 {
468  const dirauth_options_t *opts = dirauth_get_options();
469  return time_of_process_start +
471 }
472 
473 /** Each server needs to have passed a reachability test no more
474  * than this number of seconds ago, or it is listed as down in
475  * the directory. */
476 #define REACHABLE_TIMEOUT (45*60)
477 
478 /** If we tested a router and found it reachable _at least this long_ after it
479  * declared itself hibernating, it is probably done hibernating and we just
480  * missed a descriptor from it. */
481 #define HIBERNATION_PUBLICATION_SKEW (60*60)
482 
483 /** Treat a router as alive if
484  * - It's me, and I'm not hibernating.
485  * or - We've found it reachable recently. */
486 void
488 {
489  /*XXXX This function is a mess. Separate out the part that calculates
490  whether it's reachable and the part that tells rephist that the router was
491  unreachable.
492  */
493  int answer;
494  const dirauth_options_t *dirauth_options = dirauth_get_options();
495  node_t *node = node_get_mutable_by_id(router->cache_info.identity_digest);
496  tor_assert(node);
497 
498  if (router_is_me(router)) {
499  /* We always know if we are shutting down or hibernating ourselves. */
500  answer = ! we_are_hibernating();
501  } else if (router->is_hibernating &&
502  (router->cache_info.published_on +
504  /* A hibernating router is down unless we (somehow) had contact with it
505  * since it declared itself to be hibernating. */
506  answer = 0;
507  } else if (! dirauth_options->AuthDirTestReachability) {
508  /* If we aren't testing reachability, then everybody is up unless they say
509  * they are down. */
510  answer = 1;
511  } else {
512  /* Otherwise, a router counts as up if we found all announced OR
513  ports reachable in the last REACHABLE_TIMEOUT seconds.
514 
515  XXX prop186 For now there's always one IPv4 and at most one
516  IPv6 OR port.
517 
518  If we're not on IPv6, don't consider reachability of potential
519  IPv6 OR port since that'd kill all dual stack relays until a
520  majority of the dir auths have IPv6 connectivity. */
521  answer = (now < node->last_reachable + REACHABLE_TIMEOUT &&
522  (dirauth_options->AuthDirHasIPv6Connectivity != 1 ||
523  tor_addr_is_null(&router->ipv6_addr) ||
524  now < node->last_reachable6 + REACHABLE_TIMEOUT));
525  }
526 
528  /* Not considered reachable. tell rephist about that.
529 
530  Because we launch a reachability test for each router every
531  REACHABILITY_TEST_CYCLE_PERIOD seconds, then the router has probably
532  been down since at least that time after we last successfully reached
533  it.
534 
535  XXX ipv6
536  */
537  time_t when = now;
538  if (node->last_reachable &&
541  rep_hist_note_router_unreachable(router->cache_info.identity_digest, when);
542  }
543 
544  node->is_running = answer;
545 }
546 
547 /* Check <b>node</b> and <b>ri</b> on whether or not we should publish a
548  * relay's IPv6 addresses. */
549 static int
550 should_publish_node_ipv6(const node_t *node, const routerinfo_t *ri,
551  time_t now)
552 {
553  const dirauth_options_t *options = dirauth_get_options();
554 
555  return options->AuthDirHasIPv6Connectivity == 1 &&
556  !tor_addr_is_null(&ri->ipv6_addr) &&
557  ((node->last_reachable6 >= now - REACHABLE_TIMEOUT) ||
558  router_is_me(ri));
559 }
560 
561 /** Set routerstatus flags based on the authority options. Same as the testing
562  * function but for the main network. */
563 static void
565 {
566  const dirauth_options_t *options = dirauth_get_options();
567 
568  tor_assert(rs);
569 
570  /* Assign Guard flag to relays that can get it unconditionnaly. */
571  if (routerset_contains_routerstatus(options->AuthDirVoteGuard, rs, 0)) {
572  rs->is_possible_guard = 1;
573  }
574 }
575 
576 /**
577  * Extract status information from <b>ri</b> and from other authority
578  * functions and store it in <b>rs</b>, as per
579  * <b>set_routerstatus_from_routerinfo</b>. Additionally, sets information
580  * in from the authority subsystem.
581  */
582 void
584  node_t *node,
585  const routerinfo_t *ri,
586  time_t now,
587  int listbadexits,
588  int listmiddleonly)
589 {
590  const or_options_t *options = get_options();
591  uint32_t routerbw_kb = dirserv_get_credible_bandwidth_kb(ri);
592 
593  /* Set these flags so that set_routerstatus_from_routerinfo can copy them.
594  */
595  node->is_stable = !dirserv_thinks_router_is_unreliable(now, ri, 1, 0);
596  node->is_fast = !dirserv_thinks_router_is_unreliable(now, ri, 0, 1);
597  node->is_hs_dir = dirserv_thinks_router_is_hs_dir(ri, node, now);
598 
599  set_routerstatus_from_routerinfo(rs, node, ri);
600 
601  /* Override rs->is_possible_guard. */
602  const uint64_t bw_opt = dirauth_get_options()->AuthDirGuardBWGuarantee;
603  if (node->is_fast && node->is_stable &&
605  ((bw_opt && routerbw_kb >= bw_opt / 1000) ||
606  routerbw_kb >= MIN(guard_bandwidth_including_exits_kb,
609  node->identity, now);
611  node->identity, now);
612  rs->is_possible_guard = (wfu >= guard_wfu && tk >= guard_tk) ? 1 : 0;
613  } else {
614  rs->is_possible_guard = 0;
615  }
616 
617  /* Override rs->is_bad_exit */
618  rs->is_bad_exit = listbadexits && node->is_bad_exit;
619 
620  /* Override rs->is_middle_only and related flags. */
621  rs->is_middle_only = listmiddleonly && node->is_middle_only;
622  if (rs->is_middle_only) {
623  if (listbadexits)
624  rs->is_bad_exit = 1;
625  rs->is_exit = rs->is_possible_guard = rs->is_hs_dir = rs->is_v2_dir = 0;
626  }
627 
628  /* Set rs->is_staledesc. */
629  rs->is_staledesc =
630  (ri->cache_info.published_on + DESC_IS_STALE_INTERVAL) < now;
631 
632  if (! should_publish_node_ipv6(node, ri, now)) {
633  /* We're not configured as having IPv6 connectivity or the node isn't:
634  * zero its IPv6 information. */
635  tor_addr_make_null(&rs->ipv6_addr, AF_INET6);
636  rs->ipv6_orport = 0;
637  }
638 
639  if (options->TestingTorNetwork) {
641  } else {
643  }
644 }
645 
646 /** Use TestingDirAuthVoteExit, TestingDirAuthVoteGuard, and
647  * TestingDirAuthVoteHSDir to give out the Exit, Guard, and HSDir flags,
648  * respectively. But don't set the corresponding node flags.
649  * Should only be called if TestingTorNetwork is set. */
650 STATIC void
652 {
653  const dirauth_options_t *options = dirauth_get_options();
654 
655  tor_assert(get_options()->TestingTorNetwork);
656 
658  rs, 0)) {
659  rs->is_exit = 1;
660  } else if (options->TestingDirAuthVoteExitIsStrict) {
661  rs->is_exit = 0;
662  }
663 
665  rs, 0)) {
666  rs->is_possible_guard = 1;
667  } else if (options->TestingDirAuthVoteGuardIsStrict) {
668  rs->is_possible_guard = 0;
669  }
670 
672  rs, 0)) {
673  rs->is_hs_dir = 1;
674  } else if (options->TestingDirAuthVoteHSDirIsStrict) {
675  rs->is_hs_dir = 0;
676  }
677 }
678 
679 /** Use dirserv_set_router_is_running() to set bridges as running if they're
680  * reachable.
681  *
682  * This function is called from set_bridge_running_callback() when running as
683  * a bridge authority.
684  */
685 void
687 {
689 
691  if (ri->purpose == ROUTER_PURPOSE_BRIDGE)
693  } SMARTLIST_FOREACH_END(ri);
694 }
void tor_addr_make_null(tor_addr_t *a, sa_family_t family)
Definition: address.c:235
int tor_addr_is_null(const tor_addr_t *addr)
Definition: address.c:780
time_t approx_time(void)
Definition: approx_time.c:32
uint32_t dirserv_get_credible_bandwidth_kb(const routerinfo_t *ri)
Definition: bwauth.c:177
int dirserv_get_last_n_measured_bws(void)
Definition: bwauth.c:55
int dirserv_has_measured_bw(const char *node_id)
Definition: bwauth.c:159
Header file for bwauth.c.
const or_options_t * get_options(void)
Definition: config.c:926
Header file for config.c.
Structure dirauth_options_t to hold directory authority options.
Header for dirauth_sys.c.
Header file for dirlist.c.
int we_are_hibernating(void)
Definition: hibernate.c:937
Header file for hibernate.c.
#define LD_DIRSERV
Definition: log.h:90
long get_uptime(void)
Definition: mainloop.c:2547
time_t time_of_process_start
Definition: mainloop.c:142
Header file for mainloop.c.
#define tor_free(p)
Definition: malloc.h:56
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
void set_routerstatus_from_routerinfo(routerstatus_t *rs, const node_t *node, const routerinfo_t *ri)
Header file for networkstatus.c.
Node information structure.
node_t * node_get_mutable_by_id(const char *identity_digest)
Definition: nodelist.c:197
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:1047
void nodelist_assert_ok(void)
Definition: nodelist.c:949
Header file for nodelist.c.
Master header file for Tor-specific functionality.
#define ROUTER_MAX_AGE_TO_PUBLISH
Definition: or.h:161
Header for order.c.
int exit_policy_is_general_exit(smartlist_t *policy)
Definition: policies.c:2250
Header file for policies.c.
int tor_asprintf(char **strp, const char *fmt,...)
Definition: printf.c:75
Header file for reachability.c.
#define REACHABILITY_TEST_CYCLE_PERIOD
Definition: reachability.h:24
double rep_hist_get_stability(const char *id, time_t when)
Definition: rephist.c:892
double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when)
Definition: rephist.c:904
long rep_hist_get_uptime(const char *id, time_t when)
Definition: rephist.c:879
long rep_hist_get_weighted_time_known(const char *id, time_t when)
Definition: rephist.c:920
void rep_hist_note_router_unreachable(const char *id, time_t when)
Definition: rephist.c:703
int rep_hist_have_measured_enough_stability(void)
Definition: rephist.c:932
Header file for rephist.c.
int router_is_me(const routerinfo_t *router)
Definition: router.c:1768
Header file for router.c.
Router descriptor structure.
#define ROUTER_PURPOSE_BRIDGE
int router_exit_policy_rejects_all(const routerinfo_t *router)
Definition: routerlist.c:2357
routerlist_t * router_get_routerlist(void)
Definition: routerlist.c:893
Header file for routerlist.c.
Router descriptor list structure.
int routerset_contains_routerstatus(const routerset_t *set, const routerstatus_t *rs, country_t country)
Definition: routerset.c:339
Header file for routerset.c.
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
MEMUNIT AuthDirGuardBWGuarantee
ROUTERSET TestingDirAuthVoteGuard
DOUBLE AuthDirVoteGuardBwThresholdFraction
ROUTERSET AuthDirVoteGuard
INTERVAL TestingAuthDirTimeToLearnReachability
MEMUNIT TestingMinExitFlagThreshold
ROUTERSET TestingDirAuthVoteExit
INTERVAL AuthDirVoteGuardGuaranteeTimeKnown
ROUTERSET TestingDirAuthVoteHSDir
MEMUNIT TestingMinFastFlagThreshold
INT MinMeasuredBWsForAuthToIgnoreAdvertised
DOUBLE AuthDirVoteGuardGuaranteeWFU
Definition: node_st.h:34
unsigned int is_bad_exit
Definition: node_st.h:71
unsigned int is_running
Definition: node_st.h:63
unsigned int is_hs_dir
Definition: node_st.h:75
unsigned int is_valid
Definition: node_st.h:65
char identity[DIGEST_LEN]
Definition: node_st.h:46
unsigned int is_stable
Definition: node_st.h:68
unsigned int is_middle_only
Definition: node_st.h:74
time_t last_reachable
Definition: node_st.h:100
int BridgeAuthoritativeDir
tor_addr_t ipv6_addr
Definition: routerinfo_st.h:30
smartlist_t * exit_policy
Definition: routerinfo_st.h:59
unsigned int wants_to_be_hs_dir
Definition: routerinfo_st.h:75
unsigned int is_hibernating
Definition: routerinfo_st.h:68
uint8_t purpose
unsigned int supports_tunnelled_dir_requests
Definition: routerinfo_st.h:86
uint32_t bandwidthcapacity
Definition: routerinfo_st.h:58
smartlist_t * routers
Definition: routerlist_st.h:32
unsigned int is_bad_exit
uint16_t ipv6_orport
tor_addr_t ipv6_addr
unsigned int is_staledesc
unsigned int is_hs_dir
unsigned int is_possible_guard
unsigned int is_exit
unsigned int is_middle_only
char identity_digest[DIGEST_LEN]
#define STATIC
Definition: testsupport.h:32
#define tor_assert(expr)
Definition: util_bug.h:102
Routerstatus (vote entry) structure.
STATIC void dirserv_set_routerstatus_testing(routerstatus_t *rs)
Definition: voteflags.c:651
int running_long_enough_to_decide_unreachable(void)
Definition: voteflags.c:466
#define HIBERNATION_PUBLICATION_SKEW
Definition: voteflags.c:481
#define ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB
Definition: voteflags.c:184
static void dirserv_set_routerstatus_flags(routerstatus_t *rs)
Definition: voteflags.c:564
static int router_counts_toward_thresholds(const node_t *node, time_t now, const digestmap_t *omit_as_sybil, int require_mbw)
Definition: voteflags.c:192
static uint32_t stable_uptime
Definition: voteflags.c:44
static long real_uptime(const routerinfo_t *router, time_t now)
Definition: voteflags.c:68
#define REACHABLE_TIMEOUT
Definition: voteflags.c:476
static double stable_mtbf
Definition: voteflags.c:46
char * dirserv_get_flag_thresholds_line(void)
Definition: voteflags.c:418
void dirserv_compute_performance_thresholds(digestmap_t *omit_as_sybil)
Definition: voteflags.c:221
static int dirserv_thinks_router_is_hs_dir(const routerinfo_t *router, const node_t *node, time_t now)
Definition: voteflags.c:155
static int dirserv_thinks_router_is_unreliable(time_t now, const routerinfo_t *router, int need_uptime, int need_capacity)
Definition: voteflags.c:82
static int router_is_active(const routerinfo_t *ri, const node_t *node, time_t now)
Definition: voteflags.c:119
void dirauth_set_routerstatus_from_routerinfo(routerstatus_t *rs, node_t *node, const routerinfo_t *ri, time_t now, int listbadexits, int listmiddleonly)
Definition: voteflags.c:583
static double guard_wfu
Definition: voteflags.c:52
static uint32_t fast_bandwidth_kb
Definition: voteflags.c:57
void dirserv_set_router_is_running(routerinfo_t *router, time_t now)
Definition: voteflags.c:487
void dirserv_set_bridges_running(time_t now)
Definition: voteflags.c:686
static long guard_tk
Definition: voteflags.c:55
static int enough_mtbf_info
Definition: voteflags.c:49
static uint32_t guard_bandwidth_excluding_exits_kb
Definition: voteflags.c:63
static uint32_t guard_bandwidth_including_exits_kb
Definition: voteflags.c:60
Header file for voteflags.c.