Tor  0.4.6.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  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 }
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.
or_options_t::BridgeRelay
int BridgeRelay
Definition: or_options_st.h:271
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:1801
dirclient_fetches_dir_info_later
int dirclient_fetches_dir_info_later(const or_options_t *options)
Definition: dirclient_modes.c:76
router_my_exit_policy_is_reject_star
int router_my_exit_policy_is_reject_star(void)
Definition: router.c:1727
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:64
should_refuse_unknown_exits
int should_refuse_unknown_exits(const or_options_t *options)
Definition: router.c:1380
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:593
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:256
or_options_t::FetchUselessDescriptors
int FetchUselessDescriptors
Definition: or_options_st.h:312
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:86
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:64
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