mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Extract all the "am I a server" functions from router.c
This commit is contained in:
parent
70539e3d5e
commit
fcd0f76134
@ -106,6 +106,7 @@
|
|||||||
#include "feature/hs/hs_config.h"
|
#include "feature/hs/hs_config.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "lib/sandbox/sandbox.h"
|
#include "lib/sandbox/sandbox.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "feature/hibernate/hibernate.h"
|
#include "feature/hibernate/hibernate.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "lib/sandbox/sandbox.h"
|
#include "lib/sandbox/sandbox.h"
|
||||||
#include "app/config/statefile.h"
|
#include "app/config/statefile.h"
|
||||||
#include "lib/encoding/confline.h"
|
#include "lib/encoding/confline.h"
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "feature/dirauth/bwauth.h"
|
#include "feature/dirauth/bwauth.h"
|
||||||
#include "feature/dirauth/process_descs.h"
|
#include "feature/dirauth/process_descs.h"
|
||||||
#include "feature/relay/dns.h"
|
#include "feature/relay/dns.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/client/entrynodes.h"
|
#include "feature/client/entrynodes.h"
|
||||||
#include "feature/stats/geoip.h"
|
#include "feature/stats/geoip.h"
|
||||||
#include "feature/hibernate/hibernate.h"
|
#include "feature/hibernate/hibernate.h"
|
||||||
|
@ -105,6 +105,7 @@ LIBTOR_APP_A_SOURCES = \
|
|||||||
src/feature/relay/onion_queue.c \
|
src/feature/relay/onion_queue.c \
|
||||||
src/feature/relay/router.c \
|
src/feature/relay/router.c \
|
||||||
src/feature/relay/routerkeys.c \
|
src/feature/relay/routerkeys.c \
|
||||||
|
src/feature/relay/routermode.c \
|
||||||
src/feature/relay/selftest.c \
|
src/feature/relay/selftest.c \
|
||||||
src/feature/rend/rendcache.c \
|
src/feature/rend/rendcache.c \
|
||||||
src/feature/rend/rendclient.c \
|
src/feature/rend/rendclient.c \
|
||||||
@ -326,6 +327,7 @@ noinst_HEADERS += \
|
|||||||
src/feature/relay/onion_queue.h \
|
src/feature/relay/onion_queue.h \
|
||||||
src/feature/relay/router.h \
|
src/feature/relay/router.h \
|
||||||
src/feature/relay/routerkeys.h \
|
src/feature/relay/routerkeys.h \
|
||||||
|
src/feature/relay/routermode.h \
|
||||||
src/feature/relay/selftest.h \
|
src/feature/relay/selftest.h \
|
||||||
src/feature/rend/rend_authorized_client_st.h \
|
src/feature/rend/rend_authorized_client_st.h \
|
||||||
src/feature/rend/rend_encoded_v2_service_descriptor_st.h \
|
src/feature/rend/rend_encoded_v2_service_descriptor_st.h \
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
#include "feature/dircommon/directory.h"
|
#include "feature/dircommon/directory.h"
|
||||||
#include "feature/dircache/dirserv.h"
|
#include "feature/dircache/dirserv.h"
|
||||||
#include "feature/relay/dns.h"
|
#include "feature/relay/dns.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/client/dnsserv.h"
|
#include "feature/client/dnsserv.h"
|
||||||
#include "core/or/dos.h"
|
#include "core/or/dos.h"
|
||||||
#include "feature/client/entrynodes.h"
|
#include "feature/client/entrynodes.h"
|
||||||
|
@ -92,6 +92,7 @@
|
|||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/routerkeys.h"
|
#include "feature/relay/routerkeys.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "core/mainloop/mainloop.h"
|
#include "core/mainloop/mainloop.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "lib/time/compat_time.h"
|
#include "lib/time/compat_time.h"
|
||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "lib/evloop/timers.h"
|
#include "lib/evloop/timers.h"
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "core/or/scheduler.h"
|
#include "core/or/scheduler.h"
|
||||||
#include "feature/nodelist/torcert.h"
|
#include "feature/nodelist/torcert.h"
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
#include "feature/rend/rendcommon.h"
|
#include "feature/rend/rendcommon.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/node_select.h"
|
#include "feature/nodelist/node_select.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "lib/math/fp.h"
|
#include "lib/math/fp.h"
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
|
|
||||||
#include "core/or/cell_st.h"
|
#include "core/or/cell_st.h"
|
||||||
|
@ -93,6 +93,7 @@
|
|||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
#include "core/or/circuitbuild.h"
|
#include "core/or/circuitbuild.h"
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
#include "feature/relay/routerkeys.h"
|
#include "feature/relay/routerkeys.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/relay/ext_orport.h"
|
#include "feature/relay/ext_orport.h"
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#include "feature/nodelist/networkstatus.h"
|
#include "feature/nodelist/networkstatus.h"
|
||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
|
|
||||||
#include "core/or/dos.h"
|
#include "core/or/dos.h"
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "core/or/policies.h"
|
#include "core/or/policies.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/routerparse.h"
|
#include "feature/nodelist/routerparse.h"
|
||||||
#include "feature/stats/geoip.h"
|
#include "feature/stats/geoip.h"
|
||||||
#include "ht.h"
|
#include "ht.h"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "core/or/circuitlist.h"
|
#include "core/or/circuitlist.h"
|
||||||
#include "core/mainloop/mainloop.h"
|
#include "core/mainloop/mainloop.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/authcert.h"
|
#include "feature/nodelist/authcert.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "feature/nodelist/authcert.h"
|
#include "feature/nodelist/authcert.h"
|
||||||
#include "feature/nodelist/networkstatus.h"
|
#include "feature/nodelist/networkstatus.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/rend/rendcache.h"
|
#include "feature/rend/rendcache.h"
|
||||||
#include "feature/stats/geoip.h"
|
#include "feature/stats/geoip.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "feature/nodelist/microdesc.h"
|
#include "feature/nodelist/microdesc.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
|
|
||||||
#include "feature/dircache/cached_dir_st.h"
|
#include "feature/dircache/cached_dir_st.h"
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/rend/rendcache.h"
|
#include "feature/rend/rendcache.h"
|
||||||
#include "feature/rend/rendclient.h"
|
#include "feature/rend/rendclient.h"
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "feature/client/entrynodes.h"
|
#include "feature/client/entrynodes.h"
|
||||||
#include "feature/dirclient/dlstatus.h"
|
#include "feature/dirclient/dlstatus.h"
|
||||||
#include "feature/nodelist/networkstatus.h"
|
#include "feature/nodelist/networkstatus.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
#include "lib/crypt_ops/crypto_rand.h"
|
#include "lib/crypt_ops/crypto_rand.h"
|
||||||
|
|
||||||
#include "feature/dirclient/download_status_st.h"
|
#include "feature/dirclient/download_status_st.h"
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/nodelist/routerparse.h"
|
#include "feature/nodelist/routerparse.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
|
|
||||||
#include "core/or/connection_st.h"
|
#include "core/or/connection_st.h"
|
||||||
#include "feature/dirclient/dir_server_st.h"
|
#include "feature/dirclient/dir_server_st.h"
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "core/or/protover.h"
|
#include "core/or/protover.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/authcert.h"
|
#include "feature/nodelist/authcert.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "feature/nodelist/node_select.h"
|
#include "feature/nodelist/node_select.h"
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "lib/crypt_ops/crypto_rand.h"
|
#include "lib/crypt_ops/crypto_rand.h"
|
||||||
#include "lib/math/fp.h"
|
#include "lib/math/fp.h"
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
#include "feature/nodelist/routerparse.h"
|
#include "feature/nodelist/routerparse.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
#include "feature/nodelist/torcert.h"
|
#include "feature/nodelist/torcert.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "lib/crypt_ops/crypto_format.h"
|
#include "lib/crypt_ops/crypto_format.h"
|
||||||
#include "lib/crypt_ops/crypto_rand.h"
|
#include "lib/crypt_ops/crypto_rand.h"
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
#include "core/or/policies.h"
|
#include "core/or/policies.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "ht.h"
|
#include "ht.h"
|
||||||
#include "lib/sandbox/sandbox.h"
|
#include "lib/sandbox/sandbox.h"
|
||||||
#include "lib/evloop/compat_libevent.h"
|
#include "lib/evloop/compat_libevent.h"
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
#include "feature/relay/routerkeys.h"
|
#include "feature/relay/routerkeys.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/authcert.h"
|
#include "feature/nodelist/authcert.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
@ -1178,7 +1179,7 @@ init_keys(void)
|
|||||||
/** Return true iff we have enough configured bandwidth to advertise or
|
/** Return true iff we have enough configured bandwidth to advertise or
|
||||||
* automatically provide directory services from cache directory
|
* automatically provide directory services from cache directory
|
||||||
* information. */
|
* information. */
|
||||||
static int
|
int
|
||||||
router_has_bandwidth_to_be_dirserver(const or_options_t *options)
|
router_has_bandwidth_to_be_dirserver(const or_options_t *options)
|
||||||
{
|
{
|
||||||
if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
|
if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRSERVER) {
|
||||||
@ -1258,19 +1259,6 @@ router_should_be_dirserver(const or_options_t *options, int dir_port)
|
|||||||
return advertising;
|
return advertising;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return 1 if we are configured to accept either relay or directory requests
|
|
||||||
* from clients and we aren't at risk of exceeding our bandwidth limits, thus
|
|
||||||
* we should be a directory server. If not, return 0.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
dir_server_mode(const or_options_t *options)
|
|
||||||
{
|
|
||||||
if (!options->DirCache)
|
|
||||||
return 0;
|
|
||||||
return options->DirPort_set ||
|
|
||||||
(server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Look at a variety of factors, and return 0 if we don't want to
|
/** Look at a variety of factors, and return 0 if we don't want to
|
||||||
* advertise the fact that we have a DirPort open or begindir support, else
|
* advertise the fact that we have a DirPort open or begindir support, else
|
||||||
* return 1.
|
* return 1.
|
||||||
@ -1348,24 +1336,6 @@ net_is_completely_disabled(void)
|
|||||||
return get_options()->DisableNetwork || we_are_fully_hibernating();
|
return get_options()->DisableNetwork || we_are_fully_hibernating();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return true iff we are trying to be a server.
|
|
||||||
*/
|
|
||||||
MOCK_IMPL(int,
|
|
||||||
server_mode,(const or_options_t *options))
|
|
||||||
{
|
|
||||||
if (options->ClientOnly) return 0;
|
|
||||||
return (options->ORPort_set);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true iff we are trying to be a non-bridge server.
|
|
||||||
*/
|
|
||||||
MOCK_IMPL(int,
|
|
||||||
public_server_mode,(const or_options_t *options))
|
|
||||||
{
|
|
||||||
if (!server_mode(options)) return 0;
|
|
||||||
return (!options->BridgeRelay);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true iff the combination of options in <b>options</b> and parameters
|
/** Return true iff the combination of options in <b>options</b> and parameters
|
||||||
* in the consensus mean that we don't want to allow exits from circuits
|
* in the consensus mean that we don't want to allow exits from circuits
|
||||||
* we got from addresses not known to be servers. */
|
* we got from addresses not known to be servers. */
|
||||||
@ -1379,42 +1349,6 @@ should_refuse_unknown_exits(const or_options_t *options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remember if we've advertised ourselves to the dirservers. */
|
|
||||||
static int server_is_advertised=0;
|
|
||||||
|
|
||||||
/** Return true iff we have published our descriptor lately.
|
|
||||||
*/
|
|
||||||
MOCK_IMPL(int,
|
|
||||||
advertised_server_mode,(void))
|
|
||||||
{
|
|
||||||
return server_is_advertised;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called with a boolean: set whether we have recently published our
|
|
||||||
* descriptor.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
set_server_advertised(int s)
|
|
||||||
{
|
|
||||||
server_is_advertised = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true iff we are trying to proxy client connections. */
|
|
||||||
int
|
|
||||||
proxy_mode(const or_options_t *options)
|
|
||||||
{
|
|
||||||
(void)options;
|
|
||||||
SMARTLIST_FOREACH_BEGIN(get_configured_ports(), const port_cfg_t *, p) {
|
|
||||||
if (p->type == CONN_TYPE_AP_LISTENER ||
|
|
||||||
p->type == CONN_TYPE_AP_TRANS_LISTENER ||
|
|
||||||
p->type == CONN_TYPE_AP_DNS_LISTENER ||
|
|
||||||
p->type == CONN_TYPE_AP_NATD_LISTENER)
|
|
||||||
return 1;
|
|
||||||
} SMARTLIST_FOREACH_END(p);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Decide if we're a publishable server. We are a publishable server if:
|
/** Decide if we're a publishable server. We are a publishable server if:
|
||||||
* - We don't have the ClientOnly option set
|
* - We don't have the ClientOnly option set
|
||||||
* and
|
* and
|
||||||
|
@ -56,8 +56,6 @@ int router_initialize_tls_context(void);
|
|||||||
int init_keys(void);
|
int init_keys(void);
|
||||||
int init_keys_client(void);
|
int init_keys_client(void);
|
||||||
|
|
||||||
int dir_server_mode(const or_options_t *options);
|
|
||||||
|
|
||||||
int net_is_disabled(void);
|
int net_is_disabled(void);
|
||||||
int net_is_completely_disabled(void);
|
int net_is_completely_disabled(void);
|
||||||
|
|
||||||
@ -72,10 +70,6 @@ uint16_t router_get_advertised_dir_port(const or_options_t *options,
|
|||||||
int router_should_advertise_dirport(const or_options_t *options,
|
int router_should_advertise_dirport(const or_options_t *options,
|
||||||
uint16_t dir_port);
|
uint16_t dir_port);
|
||||||
|
|
||||||
MOCK_DECL(int, server_mode, (const or_options_t *options));
|
|
||||||
MOCK_DECL(int, public_server_mode, (const or_options_t *options));
|
|
||||||
MOCK_DECL(int, advertised_server_mode, (void));
|
|
||||||
int proxy_mode(const or_options_t *options);
|
|
||||||
void consider_publishable_server(int force);
|
void consider_publishable_server(int force);
|
||||||
int should_refuse_unknown_exits(const or_options_t *options);
|
int should_refuse_unknown_exits(const or_options_t *options);
|
||||||
|
|
||||||
@ -84,6 +78,7 @@ void mark_my_descriptor_dirty_if_too_old(time_t now);
|
|||||||
void mark_my_descriptor_dirty(const char *reason);
|
void mark_my_descriptor_dirty(const char *reason);
|
||||||
void check_descriptor_bandwidth_changed(time_t now);
|
void check_descriptor_bandwidth_changed(time_t now);
|
||||||
void check_descriptor_ipaddress_changed(time_t now);
|
void check_descriptor_ipaddress_changed(time_t now);
|
||||||
|
int router_has_bandwidth_to_be_dirserver(const or_options_t *options);
|
||||||
void router_new_address_suggestion(const char *suggestion,
|
void router_new_address_suggestion(const char *suggestion,
|
||||||
const dir_connection_t *d_conn);
|
const dir_connection_t *d_conn);
|
||||||
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
|
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "app/config/config.h"
|
#include "app/config/config.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
#include "feature/relay/routerkeys.h"
|
#include "feature/relay/routerkeys.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/keymgt/loadkey.h"
|
#include "feature/keymgt/loadkey.h"
|
||||||
#include "feature/nodelist/torcert.h"
|
#include "feature/nodelist/torcert.h"
|
||||||
|
|
||||||
|
80
src/feature/relay/routermode.c
Normal file
80
src/feature/relay/routermode.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/* Copyright (c) 2001 Matej Pfajfar.
|
||||||
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
||||||
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||||
|
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
#include "core/or/or.h"
|
||||||
|
|
||||||
|
#include "app/config/config.h"
|
||||||
|
#include "core/mainloop/connection.h"
|
||||||
|
#include "core/or/port_cfg_st.h"
|
||||||
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
|
|
||||||
|
/** Return 1 if we are configured to accept either relay or directory requests
|
||||||
|
* from clients and we aren't at risk of exceeding our bandwidth limits, thus
|
||||||
|
* we should be a directory server. If not, return 0.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dir_server_mode(const or_options_t *options)
|
||||||
|
{
|
||||||
|
if (!options->DirCache)
|
||||||
|
return 0;
|
||||||
|
return options->DirPort_set ||
|
||||||
|
(server_mode(options) && router_has_bandwidth_to_be_dirserver(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true iff we are trying to proxy client connections. */
|
||||||
|
int
|
||||||
|
proxy_mode(const or_options_t *options)
|
||||||
|
{
|
||||||
|
(void)options;
|
||||||
|
SMARTLIST_FOREACH_BEGIN(get_configured_ports(), const port_cfg_t *, p) {
|
||||||
|
if (p->type == CONN_TYPE_AP_LISTENER ||
|
||||||
|
p->type == CONN_TYPE_AP_TRANS_LISTENER ||
|
||||||
|
p->type == CONN_TYPE_AP_DNS_LISTENER ||
|
||||||
|
p->type == CONN_TYPE_AP_NATD_LISTENER)
|
||||||
|
return 1;
|
||||||
|
} SMARTLIST_FOREACH_END(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true iff we are trying to be a server.
|
||||||
|
*/
|
||||||
|
MOCK_IMPL(int,
|
||||||
|
server_mode,(const or_options_t *options))
|
||||||
|
{
|
||||||
|
if (options->ClientOnly) return 0;
|
||||||
|
return (options->ORPort_set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true iff we are trying to be a non-bridge server.
|
||||||
|
*/
|
||||||
|
MOCK_IMPL(int,
|
||||||
|
public_server_mode,(const or_options_t *options))
|
||||||
|
{
|
||||||
|
if (!server_mode(options)) return 0;
|
||||||
|
return (!options->BridgeRelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remember if we've advertised ourselves to the dirservers. */
|
||||||
|
static int server_is_advertised=0;
|
||||||
|
|
||||||
|
/** Return true iff we have published our descriptor lately.
|
||||||
|
*/
|
||||||
|
MOCK_IMPL(int,
|
||||||
|
advertised_server_mode,(void))
|
||||||
|
{
|
||||||
|
return server_is_advertised;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called with a boolean: set whether we have recently published our
|
||||||
|
* descriptor.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
set_server_advertised(int s)
|
||||||
|
{
|
||||||
|
server_is_advertised = s;
|
||||||
|
}
|
24
src/feature/relay/routermode.h
Normal file
24
src/feature/relay/routermode.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright (c) 2001 Matej Pfajfar.
|
||||||
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
||||||
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
||||||
|
* Copyright (c) 2007-2018, The Tor Project, Inc. */
|
||||||
|
/* See LICENSE for licensing information */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file routermode.h
|
||||||
|
* \brief Header file for routermode.c.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef TOR_ROUTERMODE_H
|
||||||
|
#define TOR_ROUTERMODE_H
|
||||||
|
|
||||||
|
int dir_server_mode(const or_options_t *options);
|
||||||
|
|
||||||
|
MOCK_DECL(int, server_mode, (const or_options_t *options));
|
||||||
|
MOCK_DECL(int, public_server_mode, (const or_options_t *options));
|
||||||
|
MOCK_DECL(int, advertised_server_mode, (void));
|
||||||
|
int proxy_mode(const or_options_t *options);
|
||||||
|
|
||||||
|
void set_server_advertised(int s);
|
||||||
|
|
||||||
|
#endif /* !defined(TOR_ROUTERMODE_H) */
|
@ -83,7 +83,7 @@
|
|||||||
#include "feature/nodelist/networkstatus.h"
|
#include "feature/nodelist/networkstatus.h"
|
||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/relay/selftest.h"
|
#include "feature/relay/selftest.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "ht.h"
|
#include "ht.h"
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "feature/rend/rendclient.h"
|
#include "feature/rend/rendclient.h"
|
||||||
#include "feature/rend/rendservice.h"
|
#include "feature/rend/rendservice.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "feature/nodelist/routerlist.h"
|
#include "feature/nodelist/routerlist.h"
|
||||||
#include "feature/nodelist/routerset.h"
|
#include "feature/nodelist/routerset.h"
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include "feature/nodelist/networkstatus.h"
|
#include "feature/nodelist/networkstatus.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
#include "feature/relay/routerkeys.h"
|
#include "feature/relay/routerkeys.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "feature/nodelist/authcert.h"
|
#include "feature/nodelist/authcert.h"
|
||||||
#include "feature/nodelist/dirlist.h"
|
#include "feature/nodelist/dirlist.h"
|
||||||
#include "feature/nodelist/node_select.h"
|
#include "feature/nodelist/node_select.h"
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "feature/stats/rephist.h"
|
#include "feature/stats/rephist.h"
|
||||||
#include "core/or/relay.h"
|
#include "core/or/relay.h"
|
||||||
#include "feature/relay/router.h"
|
#include "feature/relay/router.h"
|
||||||
|
#include "feature/relay/routermode.h"
|
||||||
#include "core/mainloop/mainloop.h"
|
#include "core/mainloop/mainloop.h"
|
||||||
#include "feature/nodelist/nodelist.h"
|
#include "feature/nodelist/nodelist.h"
|
||||||
#include "app/config/statefile.h"
|
#include "app/config/statefile.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user