aboutsummaryrefslogtreecommitdiff
path: root/src/feature/relay
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-09-25 16:00:50 -0400
committerNick Mathewson <nickm@torproject.org>2018-09-25 16:00:50 -0400
commitfcd0f76134c2e1e420b1379906955d41e8a6df66 (patch)
treefbd6c587332809a461f50271bd4c8bdd12bdfeef /src/feature/relay
parent70539e3d5e357521616a083a69712605b7b98c23 (diff)
downloadtor-fcd0f76134c2e1e420b1379906955d41e8a6df66.tar.gz
tor-fcd0f76134c2e1e420b1379906955d41e8a6df66.zip
Extract all the "am I a server" functions from router.c
Diffstat (limited to 'src/feature/relay')
-rw-r--r--src/feature/relay/dns.c1
-rw-r--r--src/feature/relay/router.c70
-rw-r--r--src/feature/relay/router.h7
-rw-r--r--src/feature/relay/routerkeys.c1
-rw-r--r--src/feature/relay/routermode.c80
-rw-r--r--src/feature/relay/routermode.h24
6 files changed, 109 insertions, 74 deletions
diff --git a/src/feature/relay/dns.c b/src/feature/relay/dns.c
index 6e9be5e2e7..52488ff94d 100644
--- a/src/feature/relay/dns.c
+++ b/src/feature/relay/dns.c
@@ -62,6 +62,7 @@
#include "core/or/policies.h"
#include "core/or/relay.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "ht.h"
#include "lib/sandbox/sandbox.h"
#include "lib/evloop/compat_libevent.h"
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index cc5c424fec..e145a8e411 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -34,6 +34,7 @@
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
@@ -1178,7 +1179,7 @@ init_keys(void)
/** Return true iff we have enough configured bandwidth to advertise or
* automatically provide directory services from cache directory
* information. */
-static int
+int
router_has_bandwidth_to_be_dirserver(const or_options_t *options)
{
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 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
* advertise the fact that we have a DirPort open or begindir support, else
* return 1.
@@ -1348,24 +1336,6 @@ net_is_completely_disabled(void)
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
* in the consensus mean that we don't want to allow exits from circuits
* 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:
* - We don't have the ClientOnly option set
* and
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index 7b33069aac..5e342cc491 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -56,8 +56,6 @@ int router_initialize_tls_context(void);
int init_keys(void);
int init_keys_client(void);
-int dir_server_mode(const or_options_t *options);
-
int net_is_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,
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);
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 check_descriptor_bandwidth_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,
const dir_connection_t *d_conn);
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
diff --git a/src/feature/relay/routerkeys.c b/src/feature/relay/routerkeys.c
index c133597954..2499d7c8ff 100644
--- a/src/feature/relay/routerkeys.c
+++ b/src/feature/relay/routerkeys.c
@@ -18,6 +18,7 @@
#include "app/config/config.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "feature/keymgt/loadkey.h"
#include "feature/nodelist/torcert.h"
diff --git a/src/feature/relay/routermode.c b/src/feature/relay/routermode.c
new file mode 100644
index 0000000000..3f87cda505
--- /dev/null
+++ b/src/feature/relay/routermode.c
@@ -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;
+}
diff --git a/src/feature/relay/routermode.h b/src/feature/relay/routermode.h
new file mode 100644
index 0000000000..1442d706dd
--- /dev/null
+++ b/src/feature/relay/routermode.h
@@ -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) */