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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 #include "core/or/or.h"
9 #include "app/config/config.h"
10 #include "core/mainloop/connection.h"
11 #include "core/or/port_cfg_st.h"
12 #include "feature/relay/router.h"
13 #include "feature/relay/routermode.h"
15 /** Return 1 if we are configured to accept either relay or directory requests
16 * from clients and we aren't at risk of exceeding our bandwidth limits, thus
17 * we should be a directory server. If not, return 0.
20 dir_server_mode(const or_options_t
*options
)
22 if (!options
->DirCache
)
24 return options
->DirPort_set
||
25 (server_mode(options
) && router_has_bandwidth_to_be_dirserver(options
));
28 /** Return true iff we are trying to proxy client connections. */
30 proxy_mode(const or_options_t
*options
)
33 SMARTLIST_FOREACH_BEGIN(get_configured_ports(), const port_cfg_t
*, p
) {
34 if (p
->type
== CONN_TYPE_AP_LISTENER
||
35 p
->type
== CONN_TYPE_AP_TRANS_LISTENER
||
36 p
->type
== CONN_TYPE_AP_DNS_LISTENER
||
37 p
->type
== CONN_TYPE_AP_NATD_LISTENER
)
39 } SMARTLIST_FOREACH_END(p
);
43 /** Return true iff we are trying to be a server.
46 server_mode
,(const or_options_t
*options
))
48 if (options
->ClientOnly
) return 0;
49 return (options
->ORPort_set
);
52 /** Return true iff we are trying to be a non-bridge server.
55 public_server_mode
,(const or_options_t
*options
))
57 if (!server_mode(options
)) return 0;
58 return (!options
->BridgeRelay
);
61 /** Remember if we've advertised ourselves to the dirservers. */
62 static int server_is_advertised
=0;
64 /** Return true iff we have published our descriptor lately.
67 advertised_server_mode
,(void))
69 return server_is_advertised
;
73 * Called with a boolean: set whether we have recently published our
77 set_server_advertised(int s
)
79 server_is_advertised
= s
;