Tor  0.4.7.0-alpha-dev
dirclient_modes.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file dirclient_modes.c
9  * @brief Functions to answer questions about how we'd like to behave
10  * as a directory client
11  **/
12 
13 #include "orconfig.h"
14 
15 #include "core/or/or.h"
16 
20 #include "feature/relay/router.h"
23 
26 
27 /* Should this tor instance only use begindir for all its directory requests?
28  */
29 int
30 dirclient_must_use_begindir(const or_options_t *options)
31 {
32  /* Clients, onion services, and bridges must use begindir,
33  * relays and authorities do not have to */
34  return !public_server_mode(options);
35 }
36 
37 /** Return 1 if we fetch our directory material directly from the
38  * authorities, rather than from a mirror. */
39 int
41 {
42  const routerinfo_t *me;
43  int refuseunknown;
44  if (options->FetchDirInfoEarly)
45  return 1;
46  if (options->BridgeRelay == 1)
47  return 0;
48  refuseunknown = ! router_my_exit_policy_is_reject_star() &&
50  if (!dir_server_mode(options) && !refuseunknown)
51  return 0;
52  if (!server_mode(options) || !advertised_server_mode())
53  return 0;
55  if (!me || (!me->supports_tunnelled_dir_requests && !refuseunknown))
56  return 0; /* if we don't service directory requests, return 0 too */
57  return 1;
58 }
59 
60 /** Return 1 if we should fetch new networkstatuses, descriptors, etc
61  * on the "mirror" schedule rather than the "client" schedule.
62  */
63 int
65 {
66  return dirclient_fetches_from_authorities(options);
67 }
68 
69 /** Return 1 if we should fetch new networkstatuses, descriptors, etc
70  * on a very passive schedule -- waiting long enough for ordinary clients
71  * to probably have the info we want. These would include bridge users,
72  * and maybe others in the future e.g. if a Tor client uses another Tor
73  * client as a directory guard.
74  */
75 int
77 {
78  return options->UseBridges != 0;
79 }
80 
81 /** Return 1 if we have no need to fetch new descriptors. This generally
82  * happens when we're not a dir cache and we haven't built any circuits
83  * lately.
84  */
85 int
87  time_t now)
88 {
89  return !directory_caches_dir_info(options) &&
90  !options->FetchUselessDescriptors &&
92 }
int dirclient_fetches_dir_info_later(const or_options_t *options)
int dirclient_fetches_dir_info_early(const or_options_t *options)
int dirclient_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
int dirclient_fetches_from_authorities(const or_options_t *options)
Header for feature/dirclient/dirclient_modes.c.
int directory_caches_dir_info(const or_options_t *options)
Definition: dirserv.c:94
Header file for dirserv.c.
Master header file for Tor-specific functionality.
The or_options_t structure, which represents Tor's configuration.
int rep_hist_circbuilding_dormant(time_t now)
Header file for predict_ports.c.
Header file for relay_find_addr.c.
const routerinfo_t * router_get_my_routerinfo(void)
Definition: router.c:1801
int router_my_exit_policy_is_reject_star(void)
Definition: router.c:1727
int should_refuse_unknown_exits(const or_options_t *options)
Definition: router.c:1380
Header file for router.c.
Router descriptor structure.
int public_server_mode(const or_options_t *options)
Definition: routermode.c:43
int advertised_server_mode(void)
Definition: routermode.c:55
int dir_server_mode(const or_options_t *options)
Definition: routermode.c:23
int server_mode(const or_options_t *options)
Definition: routermode.c:34
Header file for routermode.c.
int FetchUselessDescriptors
unsigned int supports_tunnelled_dir_requests
Definition: routerinfo_st.h:86