Tor  0.4.5.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-2020, 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  /* We don't know our IP address; ask an authority. IPv4 is still mandatory
49  * to have thus if we don't have it, we ought to learn it from an authority
50  * through the NETINFO cell or the HTTP header it sends us back.
51  *
52  * Note that at the moment, relay do a direct connection so no NETINFO cell
53  * for now. */
54  if (server_mode(options) && !relay_has_address_set(AF_INET))
55  return 1;
56  refuseunknown = ! router_my_exit_policy_is_reject_star() &&
58  if (!dir_server_mode(options) && !refuseunknown)
59  return 0;
60  if (!server_mode(options) || !advertised_server_mode())
61  return 0;
63  if (!me || (!me->supports_tunnelled_dir_requests && !refuseunknown))
64  return 0; /* if we don't service directory requests, return 0 too */
65  return 1;
66 }
67 
68 /** Return 1 if we should fetch new networkstatuses, descriptors, etc
69  * on the "mirror" schedule rather than the "client" schedule.
70  */
71 int
73 {
74  return dirclient_fetches_from_authorities(options);
75 }
76 
77 /** Return 1 if we should fetch new networkstatuses, descriptors, etc
78  * on a very passive schedule -- waiting long enough for ordinary clients
79  * to probably have the info we want. These would include bridge users,
80  * and maybe others in the future e.g. if a Tor client uses another Tor
81  * client as a directory guard.
82  */
83 int
85 {
86  return options->UseBridges != 0;
87 }
88 
89 /** Return 1 if we have no need to fetch new descriptors. This generally
90  * happens when we're not a dir cache and we haven't built any circuits
91  * lately.
92  */
93 int
95  time_t now)
96 {
97  return !directory_caches_dir_info(options) &&
98  !options->FetchUselessDescriptors &&
100 }
routermode.h
Header file for routermode.c.
routerinfo_t
Definition: routerinfo_st.h:20
or_options_st.h
The or_options_t structure, which represents Tor's configuration.
relay_has_address_set
bool relay_has_address_set(int family)
Definition: relay_find_addr.c:148
or_options_t::BridgeRelay
int BridgeRelay
Definition: or_options_st.h:248
relay_find_addr.h
Header file for relay_find_addr.c.
router.h
Header file for router.c.
router_get_my_routerinfo
const routerinfo_t * router_get_my_routerinfo(void)
Definition: router.c:1760
dirclient_fetches_dir_info_later
int dirclient_fetches_dir_info_later(const or_options_t *options)
Definition: dirclient_modes.c:84
router_my_exit_policy_is_reject_star
int router_my_exit_policy_is_reject_star(void)
Definition: router.c:1686
advertised_server_mode
int advertised_server_mode(void)
Definition: routermode.c:55
dirclient_fetches_dir_info_early
int dirclient_fetches_dir_info_early(const or_options_t *options)
Definition: dirclient_modes.c:72
should_refuse_unknown_exits
int should_refuse_unknown_exits(const or_options_t *options)
Definition: router.c:1342
routerinfo_t::supports_tunnelled_dir_requests
unsigned int supports_tunnelled_dir_requests
Definition: routerinfo_st.h:86
predict_ports.h
Header file for predict_ports.c.
routerinfo_st.h
Router descriptor structure.
dir_server_mode
int dir_server_mode(const or_options_t *options)
Definition: routermode.c:23
directory_caches_dir_info
int directory_caches_dir_info(const or_options_t *options)
Definition: dirserv.c:94
or_options_t::FetchDirInfoEarly
int FetchDirInfoEarly
Definition: or_options_st.h:573
dirserv.h
Header file for dirserv.c.
server_mode
int server_mode(const or_options_t *options)
Definition: routermode.c:34
public_server_mode
int public_server_mode(const or_options_t *options)
Definition: routermode.c:43
or_options_t::UseBridges
int UseBridges
Definition: or_options_st.h:233
or_options_t::FetchUselessDescriptors
int FetchUselessDescriptors
Definition: or_options_st.h:289
dirclient_too_idle_to_fetch_descriptors
int dirclient_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
Definition: dirclient_modes.c:94
dirclient_fetches_from_authorities
int dirclient_fetches_from_authorities(const or_options_t *options)
Definition: dirclient_modes.c:40
or_options_t
Definition: or_options_st.h:45
dirclient_modes.h
Header for feature/dirclient/dirclient_modes.c.
or.h
Master header file for Tor-specific functionality.
rep_hist_circbuilding_dormant
int rep_hist_circbuilding_dormant(time_t now)
Definition: predict_ports.c:264