tor-commits
Threads by month
- ----- 2025 -----
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
September 2018
- 17 participants
- 3230 discussions

[tor/master] Move the various _describe() functions out of router.c
by nickm@torproject.org 26 Sep '18
by nickm@torproject.org 26 Sep '18
26 Sep '18
commit 5c86f3c297229515f125c0e06abdc689c90768f4
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 16:13:47 2018 -0400
Move the various _describe() functions out of router.c
Note that I haven't separated the headers yet (there's still an
---
src/core/include.am | 2 +
src/feature/nodelist/describe.c | 178 ++++++++++++++++++++++++++++++++++++++++
src/feature/nodelist/describe.h | 25 ++++++
src/feature/relay/router.c | 171 --------------------------------------
src/feature/relay/router.h | 6 +-
5 files changed, 206 insertions(+), 176 deletions(-)
diff --git a/src/core/include.am b/src/core/include.am
index ae37bef99..d4671bf6c 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -89,6 +89,7 @@ LIBTOR_APP_A_SOURCES = \
src/feature/keymgt/loadkey.c \
src/feature/dirauth/keypin.c \
src/feature/nodelist/authcert.c \
+ src/feature/nodelist/describe.c \
src/feature/nodelist/dirlist.c \
src/feature/nodelist/microdesc.c \
src/feature/nodelist/networkstatus.c \
@@ -297,6 +298,7 @@ noinst_HEADERS += \
src/feature/keymgt/loadkey.h \
src/feature/nodelist/authcert.h \
src/feature/nodelist/authority_cert_st.h \
+ src/feature/nodelist/describe.h \
src/feature/nodelist/desc_store_st.h \
src/feature/nodelist/dirlist.h \
src/feature/nodelist/document_signature_st.h \
diff --git a/src/feature/nodelist/describe.c b/src/feature/nodelist/describe.c
new file mode 100644
index 000000000..ccf27e02d
--- /dev/null
+++ b/src/feature/nodelist/describe.c
@@ -0,0 +1,178 @@
+/* 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 "feature/nodelist/describe.h"
+#include "feature/relay/router.h"
+
+#include "core/or/extend_info_st.h"
+#include "feature/nodelist/node_st.h"
+#include "feature/nodelist/routerinfo_st.h"
+#include "feature/nodelist/routerstatus_st.h"
+
+/**
+ * Longest allowed output of format_node_description, plus 1 character for
+ * NUL. This allows space for:
+ * "$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF~xxxxxxxxxxxxxxxxxxx at"
+ * " [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]"
+ * plus a terminating NUL.
+ */
+#define NODE_DESC_BUF_LEN (MAX_VERBOSE_NICKNAME_LEN+4+TOR_ADDR_BUF_LEN)
+
+/** Use <b>buf</b> (which must be at least NODE_DESC_BUF_LEN bytes long) to
+ * hold a human-readable description of a node with identity digest
+ * <b>id_digest</b>, named-status <b>is_named</b>, nickname <b>nickname</b>,
+ * and address <b>addr</b> or <b>addr32h</b>.
+ *
+ * The <b>nickname</b> and <b>addr</b> fields are optional and may be set to
+ * NULL. The <b>addr32h</b> field is optional and may be set to 0.
+ *
+ * Return a pointer to the front of <b>buf</b>.
+ */
+static const char *
+format_node_description(char *buf,
+ const char *id_digest,
+ int is_named,
+ const char *nickname,
+ const tor_addr_t *addr,
+ uint32_t addr32h)
+{
+ char *cp;
+
+ if (!buf)
+ return "<NULL BUFFER>";
+
+ buf[0] = '$';
+ base16_encode(buf+1, HEX_DIGEST_LEN+1, id_digest, DIGEST_LEN);
+ cp = buf+1+HEX_DIGEST_LEN;
+ if (nickname) {
+ buf[1+HEX_DIGEST_LEN] = is_named ? '=' : '~';
+ strlcpy(buf+1+HEX_DIGEST_LEN+1, nickname, MAX_NICKNAME_LEN+1);
+ cp += strlen(cp);
+ }
+ if (addr32h || addr) {
+ memcpy(cp, " at ", 4);
+ cp += 4;
+ if (addr) {
+ tor_addr_to_str(cp, addr, TOR_ADDR_BUF_LEN, 0);
+ } else {
+ struct in_addr in;
+ in.s_addr = htonl(addr32h);
+ tor_inet_ntoa(&in, cp, INET_NTOA_BUF_LEN);
+ }
+ }
+ return buf;
+}
+
+/** Return a human-readable description of the routerinfo_t <b>ri</b>.
+ *
+ * This function is not thread-safe. Each call to this function invalidates
+ * previous values returned by this function.
+ */
+const char *
+router_describe(const routerinfo_t *ri)
+{
+ static char buf[NODE_DESC_BUF_LEN];
+
+ if (!ri)
+ return "<null>";
+ return format_node_description(buf,
+ ri->cache_info.identity_digest,
+ 0,
+ ri->nickname,
+ NULL,
+ ri->addr);
+}
+
+/** Return a human-readable description of the node_t <b>node</b>.
+ *
+ * This function is not thread-safe. Each call to this function invalidates
+ * previous values returned by this function.
+ */
+const char *
+node_describe(const node_t *node)
+{
+ static char buf[NODE_DESC_BUF_LEN];
+ const char *nickname = NULL;
+ uint32_t addr32h = 0;
+ int is_named = 0;
+
+ if (!node)
+ return "<null>";
+
+ if (node->rs) {
+ nickname = node->rs->nickname;
+ is_named = node->rs->is_named;
+ addr32h = node->rs->addr;
+ } else if (node->ri) {
+ nickname = node->ri->nickname;
+ addr32h = node->ri->addr;
+ }
+
+ return format_node_description(buf,
+ node->identity,
+ is_named,
+ nickname,
+ NULL,
+ addr32h);
+}
+
+/** Return a human-readable description of the routerstatus_t <b>rs</b>.
+ *
+ * This function is not thread-safe. Each call to this function invalidates
+ * previous values returned by this function.
+ */
+const char *
+routerstatus_describe(const routerstatus_t *rs)
+{
+ static char buf[NODE_DESC_BUF_LEN];
+
+ if (!rs)
+ return "<null>";
+ return format_node_description(buf,
+ rs->identity_digest,
+ rs->is_named,
+ rs->nickname,
+ NULL,
+ rs->addr);
+}
+
+/** Return a human-readable description of the extend_info_t <b>ei</b>.
+ *
+ * This function is not thread-safe. Each call to this function invalidates
+ * previous values returned by this function.
+ */
+const char *
+extend_info_describe(const extend_info_t *ei)
+{
+ static char buf[NODE_DESC_BUF_LEN];
+
+ if (!ei)
+ return "<null>";
+ return format_node_description(buf,
+ ei->identity_digest,
+ 0,
+ ei->nickname,
+ &ei->addr,
+ 0);
+}
+
+/** Set <b>buf</b> (which must have MAX_VERBOSE_NICKNAME_LEN+1 bytes) to the
+ * verbose representation of the identity of <b>router</b>. The format is:
+ * A dollar sign.
+ * The upper-case hexadecimal encoding of the SHA1 hash of router's identity.
+ * A "=" if the router is named (no longer implemented); a "~" if it is not.
+ * The router's nickname.
+ **/
+void
+router_get_verbose_nickname(char *buf, const routerinfo_t *router)
+{
+ buf[0] = '$';
+ base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
+ DIGEST_LEN);
+ buf[1+HEX_DIGEST_LEN] = '~';
+ strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
+}
diff --git a/src/feature/nodelist/describe.h b/src/feature/nodelist/describe.h
new file mode 100644
index 000000000..e5723bb93
--- /dev/null
+++ b/src/feature/nodelist/describe.h
@@ -0,0 +1,25 @@
+/* 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 describe.h
+ * \brief Header file for describe.c.
+ **/
+
+#ifndef TOR_DESCRIBE_H
+#define TOR_DESCRIBE_H
+
+struct extend_info_t;
+struct node_t;
+struct routerinfo_t;
+struct routerstatus_t;
+
+const char *extend_info_describe(const struct extend_info_t *ei);
+const char *node_describe(const struct node_t *node);
+const char *router_describe(const struct routerinfo_t *ri);
+const char *routerstatus_describe(const struct routerstatus_t *ri);
+
+#endif
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index e145a8e41..494609b5b 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -133,13 +133,6 @@ static authority_cert_t *legacy_key_certificate = NULL;
* used by tor-gencert to sign new signing keys and make new key
* certificates. */
-const char *format_node_description(char *buf,
- const char *id_digest,
- int is_named,
- const char *nickname,
- const tor_addr_t *addr,
- uint32_t addr32h);
-
/** Return a readonly string with human readable description
* of <b>err</b>.
*/
@@ -3160,170 +3153,6 @@ is_legal_hexdigest(const char *s)
strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN);
}
-/**
- * Longest allowed output of format_node_description, plus 1 character for
- * NUL. This allows space for:
- * "$FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF~xxxxxxxxxxxxxxxxxxx at"
- * " [ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]"
- * plus a terminating NUL.
- */
-#define NODE_DESC_BUF_LEN (MAX_VERBOSE_NICKNAME_LEN+4+TOR_ADDR_BUF_LEN)
-
-/** Use <b>buf</b> (which must be at least NODE_DESC_BUF_LEN bytes long) to
- * hold a human-readable description of a node with identity digest
- * <b>id_digest</b>, named-status <b>is_named</b>, nickname <b>nickname</b>,
- * and address <b>addr</b> or <b>addr32h</b>.
- *
- * The <b>nickname</b> and <b>addr</b> fields are optional and may be set to
- * NULL. The <b>addr32h</b> field is optional and may be set to 0.
- *
- * Return a pointer to the front of <b>buf</b>.
- */
-const char *
-format_node_description(char *buf,
- const char *id_digest,
- int is_named,
- const char *nickname,
- const tor_addr_t *addr,
- uint32_t addr32h)
-{
- char *cp;
-
- if (!buf)
- return "<NULL BUFFER>";
-
- buf[0] = '$';
- base16_encode(buf+1, HEX_DIGEST_LEN+1, id_digest, DIGEST_LEN);
- cp = buf+1+HEX_DIGEST_LEN;
- if (nickname) {
- buf[1+HEX_DIGEST_LEN] = is_named ? '=' : '~';
- strlcpy(buf+1+HEX_DIGEST_LEN+1, nickname, MAX_NICKNAME_LEN+1);
- cp += strlen(cp);
- }
- if (addr32h || addr) {
- memcpy(cp, " at ", 4);
- cp += 4;
- if (addr) {
- tor_addr_to_str(cp, addr, TOR_ADDR_BUF_LEN, 0);
- } else {
- struct in_addr in;
- in.s_addr = htonl(addr32h);
- tor_inet_ntoa(&in, cp, INET_NTOA_BUF_LEN);
- }
- }
- return buf;
-}
-
-/** Return a human-readable description of the routerinfo_t <b>ri</b>.
- *
- * This function is not thread-safe. Each call to this function invalidates
- * previous values returned by this function.
- */
-const char *
-router_describe(const routerinfo_t *ri)
-{
- static char buf[NODE_DESC_BUF_LEN];
-
- if (!ri)
- return "<null>";
- return format_node_description(buf,
- ri->cache_info.identity_digest,
- 0,
- ri->nickname,
- NULL,
- ri->addr);
-}
-
-/** Return a human-readable description of the node_t <b>node</b>.
- *
- * This function is not thread-safe. Each call to this function invalidates
- * previous values returned by this function.
- */
-const char *
-node_describe(const node_t *node)
-{
- static char buf[NODE_DESC_BUF_LEN];
- const char *nickname = NULL;
- uint32_t addr32h = 0;
- int is_named = 0;
-
- if (!node)
- return "<null>";
-
- if (node->rs) {
- nickname = node->rs->nickname;
- is_named = node->rs->is_named;
- addr32h = node->rs->addr;
- } else if (node->ri) {
- nickname = node->ri->nickname;
- addr32h = node->ri->addr;
- }
-
- return format_node_description(buf,
- node->identity,
- is_named,
- nickname,
- NULL,
- addr32h);
-}
-
-/** Return a human-readable description of the routerstatus_t <b>rs</b>.
- *
- * This function is not thread-safe. Each call to this function invalidates
- * previous values returned by this function.
- */
-const char *
-routerstatus_describe(const routerstatus_t *rs)
-{
- static char buf[NODE_DESC_BUF_LEN];
-
- if (!rs)
- return "<null>";
- return format_node_description(buf,
- rs->identity_digest,
- rs->is_named,
- rs->nickname,
- NULL,
- rs->addr);
-}
-
-/** Return a human-readable description of the extend_info_t <b>ei</b>.
- *
- * This function is not thread-safe. Each call to this function invalidates
- * previous values returned by this function.
- */
-const char *
-extend_info_describe(const extend_info_t *ei)
-{
- static char buf[NODE_DESC_BUF_LEN];
-
- if (!ei)
- return "<null>";
- return format_node_description(buf,
- ei->identity_digest,
- 0,
- ei->nickname,
- &ei->addr,
- 0);
-}
-
-/** Set <b>buf</b> (which must have MAX_VERBOSE_NICKNAME_LEN+1 bytes) to the
- * verbose representation of the identity of <b>router</b>. The format is:
- * A dollar sign.
- * The upper-case hexadecimal encoding of the SHA1 hash of router's identity.
- * A "=" if the router is named (no longer implemented); a "~" if it is not.
- * The router's nickname.
- **/
-void
-router_get_verbose_nickname(char *buf, const routerinfo_t *router)
-{
- buf[0] = '$';
- base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest,
- DIGEST_LEN);
- buf[1+HEX_DIGEST_LEN] = '~';
- strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1);
-}
-
/** Forget that we have issued any router-related warnings, so that we'll
* warn again if we see the same errors. */
void
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index 5e342cc49..d56ddc8a1 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -13,6 +13,7 @@
#define TOR_ROUTER_H
#include "lib/testsupport/testsupport.h"
+#include "feature/nodelist/describe.h"
struct curve25519_keypair_t;
struct ed25519_keypair_t;
@@ -122,11 +123,6 @@ int is_legal_nickname(const char *s);
int is_legal_nickname_or_hexdigest(const char *s);
int is_legal_hexdigest(const char *s);
-const char *router_describe(const routerinfo_t *ri);
-const char *node_describe(const node_t *node);
-const char *routerstatus_describe(const routerstatus_t *ri);
-const char *extend_info_describe(const extend_info_t *ei);
-
const char *routerinfo_err_to_string(int err);
int routerinfo_err_is_transient(int err);
1
0

[tor/master] Move the "is the network disabled?" functions out of router.c
by nickm@torproject.org 26 Sep '18
by nickm@torproject.org 26 Sep '18
26 Sep '18
commit 3ff58e47d211d8649202c093f00934011effed1b
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 17:22:14 2018 -0400
Move the "is the network disabled?" functions out of router.c
Since this is completely core functionality, I'm putting it in
core/mainloop, even though it depends on feature/hibernate. We'll
have to sort that out in the future.
---
src/core/include.am | 2 ++
src/core/mainloop/netstatus.c | 28 ++++++++++++++++++++++++++++
src/core/mainloop/netstatus.h | 13 +++++++++++++
src/feature/relay/router.c | 18 ------------------
src/feature/relay/router.h | 4 +---
5 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/src/core/include.am b/src/core/include.am
index 21cad6dc2..64a593ca5 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -20,6 +20,7 @@ LIBTOR_APP_A_SOURCES = \
src/core/mainloop/connection.c \
src/core/mainloop/cpuworker.c \
src/core/mainloop/mainloop.c \
+ src/core/mainloop/netstatus.c \
src/core/mainloop/periodic.c \
src/core/or/address_set.c \
src/core/or/channel.c \
@@ -187,6 +188,7 @@ noinst_HEADERS += \
src/core/mainloop/connection.h \
src/core/mainloop/cpuworker.h \
src/core/mainloop/mainloop.h \
+ src/core/mainloop/netstatus.h \
src/core/mainloop/periodic.h \
src/core/or/addr_policy_st.h \
src/core/or/address_set.h \
diff --git a/src/core/mainloop/netstatus.c b/src/core/mainloop/netstatus.c
new file mode 100644
index 000000000..f02647449
--- /dev/null
+++ b/src/core/mainloop/netstatus.c
@@ -0,0 +1,28 @@
+/* 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 "core/mainloop/netstatus.h"
+#include "app/config/config.h"
+#include "feature/hibernate/hibernate.h"
+
+/** Return true iff our network is in some sense disabled or shutting down:
+ * either we're hibernating, entering hibernation, or the network is turned
+ * off with DisableNetwork. */
+int
+net_is_disabled(void)
+{
+ return get_options()->DisableNetwork || we_are_hibernating();
+}
+
+/** Return true iff our network is in some sense "completely disabled" either
+ * we're fully hibernating or the network is turned off with
+ * DisableNetwork. */
+int
+net_is_completely_disabled(void)
+{
+ return get_options()->DisableNetwork || we_are_fully_hibernating();
+}
diff --git a/src/core/mainloop/netstatus.h b/src/core/mainloop/netstatus.h
new file mode 100644
index 000000000..e9310c292
--- /dev/null
+++ b/src/core/mainloop/netstatus.h
@@ -0,0 +1,13 @@
+/* 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 */
+
+#ifndef TOR_NETSTATUS_H
+#define TOR_NETSTATUS_H
+
+int net_is_disabled(void);
+int net_is_completely_disabled(void);
+
+#endif
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index b3cfb6d8d..05e3fb3b2 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -1311,24 +1311,6 @@ router_should_advertise_begindir(const or_options_t *options,
supports_tunnelled_dir_requests);
}
-/** Return true iff our network is in some sense disabled or shutting down:
- * either we're hibernating, entering hibernation, or the network is turned
- * off with DisableNetwork. */
-int
-net_is_disabled(void)
-{
- return get_options()->DisableNetwork || we_are_hibernating();
-}
-
-/** Return true iff our network is in some sense "completely disabled" either
- * we're fully hibernating or the network is turned off with
- * DisableNetwork. */
-int
-net_is_completely_disabled(void)
-{
- return get_options()->DisableNetwork || we_are_fully_hibernating();
-}
-
/** 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. */
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index 90cc5abaf..a9c7ac3fd 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -16,6 +16,7 @@
#include "feature/nodelist/describe.h"
#include "feature/nodelist/nickname.h"
#include "feature/nodelist/routerinfo.h"
+#include "core/mainloop/netstatus.h"
struct curve25519_keypair_t;
struct ed25519_keypair_t;
@@ -59,9 +60,6 @@ int router_initialize_tls_context(void);
int init_keys(void);
int init_keys_client(void);
-int net_is_disabled(void);
-int net_is_completely_disabled(void);
-
uint16_t router_get_active_listener_port_by_type_af(int listener_type,
sa_family_t family);
uint16_t router_get_advertised_or_port(const or_options_t *options);
1
0

26 Sep '18
commit efa978124f067bf75c33c4ff9bba8dbf2f54a4ef
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 16:22:11 2018 -0400
Extract nickname-checking functions from router.c
---
src/core/include.am | 2 ++
src/feature/nodelist/describe.c | 5 ++++
src/feature/nodelist/nickname.c | 62 +++++++++++++++++++++++++++++++++++++++++
src/feature/nodelist/nickname.h | 19 +++++++++++++
src/feature/relay/router.c | 49 --------------------------------
src/feature/relay/router.h | 4 +--
6 files changed, 89 insertions(+), 52 deletions(-)
diff --git a/src/core/include.am b/src/core/include.am
index d4671bf6c..39eed0ab5 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -93,6 +93,7 @@ LIBTOR_APP_A_SOURCES = \
src/feature/nodelist/dirlist.c \
src/feature/nodelist/microdesc.c \
src/feature/nodelist/networkstatus.c \
+ src/feature/nodelist/nickname.c \
src/feature/nodelist/nodelist.c \
src/feature/nodelist/node_select.c \
src/feature/nodelist/parsecommon.c \
@@ -309,6 +310,7 @@ noinst_HEADERS += \
src/feature/nodelist/networkstatus_sr_info_st.h \
src/feature/nodelist/networkstatus_st.h \
src/feature/nodelist/networkstatus_voter_info_st.h \
+ src/feature/nodelist/nickname.h \
src/feature/nodelist/node_st.h \
src/feature/nodelist/nodelist.h \
src/feature/nodelist/node_select.h \
diff --git a/src/feature/nodelist/describe.c b/src/feature/nodelist/describe.c
index ccf27e02d..0ef9e3e7f 100644
--- a/src/feature/nodelist/describe.c
+++ b/src/feature/nodelist/describe.c
@@ -4,6 +4,11 @@
* Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */
+/**
+ * \file describe.c
+ * \brief Format short descriptions of relays.
+ */
+
#include "core/or/or.h"
#include "feature/nodelist/describe.h"
#include "feature/relay/router.h"
diff --git a/src/feature/nodelist/nickname.c b/src/feature/nodelist/nickname.c
new file mode 100644
index 000000000..7b0b29a93
--- /dev/null
+++ b/src/feature/nodelist/nickname.c
@@ -0,0 +1,62 @@
+/* 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 nickname.c
+ * \brief Check and manipulate relay nicknames.
+ */
+
+#include "core/or/or.h"
+#include "feature/nodelist/nickname.h"
+
+/** Return true iff <b>s</b> is a valid server nickname. (That is, a string
+ * containing between 1 and MAX_NICKNAME_LEN characters from
+ * LEGAL_NICKNAME_CHARACTERS.) */
+int
+is_legal_nickname(const char *s)
+{
+ size_t len;
+ tor_assert(s);
+ len = strlen(s);
+ return len > 0 && len <= MAX_NICKNAME_LEN &&
+ strspn(s,LEGAL_NICKNAME_CHARACTERS) == len;
+}
+
+/** Return true iff <b>s</b> is a valid server nickname or
+ * hex-encoded identity-key digest. */
+int
+is_legal_nickname_or_hexdigest(const char *s)
+{
+ if (*s!='$')
+ return is_legal_nickname(s);
+ else
+ return is_legal_hexdigest(s);
+}
+
+/** Return true iff <b>s</b> is a valid hex-encoded identity-key
+ * digest. (That is, an optional $, followed by 40 hex characters,
+ * followed by either nothing, or = or ~ followed by a nickname, or
+ * a character other than =, ~, or a hex character.)
+ */
+int
+is_legal_hexdigest(const char *s)
+{
+ size_t len;
+ tor_assert(s);
+ if (s[0] == '$') s++;
+ len = strlen(s);
+ if (len > HEX_DIGEST_LEN) {
+ if (s[HEX_DIGEST_LEN] == '=' ||
+ s[HEX_DIGEST_LEN] == '~') {
+ if (!is_legal_nickname(s+HEX_DIGEST_LEN+1))
+ return 0;
+ } else {
+ return 0;
+ }
+ }
+ return (len >= HEX_DIGEST_LEN &&
+ strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN);
+}
diff --git a/src/feature/nodelist/nickname.h b/src/feature/nodelist/nickname.h
new file mode 100644
index 000000000..86d430991
--- /dev/null
+++ b/src/feature/nodelist/nickname.h
@@ -0,0 +1,19 @@
+/* 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 nickname.h
+ * \brief Header file for nickname.c.
+ **/
+
+#ifndef TOR_NICKNAME_H
+#define TOR_NICKNAME_H
+
+int is_legal_nickname(const char *s);
+int is_legal_nickname_or_hexdigest(const char *s);
+int is_legal_hexdigest(const char *s);
+
+#endif
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 494609b5b..3db7bcf25 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -3104,55 +3104,6 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
return result;
}
-/** Return true iff <b>s</b> is a valid server nickname. (That is, a string
- * containing between 1 and MAX_NICKNAME_LEN characters from
- * LEGAL_NICKNAME_CHARACTERS.) */
-int
-is_legal_nickname(const char *s)
-{
- size_t len;
- tor_assert(s);
- len = strlen(s);
- return len > 0 && len <= MAX_NICKNAME_LEN &&
- strspn(s,LEGAL_NICKNAME_CHARACTERS) == len;
-}
-
-/** Return true iff <b>s</b> is a valid server nickname or
- * hex-encoded identity-key digest. */
-int
-is_legal_nickname_or_hexdigest(const char *s)
-{
- if (*s!='$')
- return is_legal_nickname(s);
- else
- return is_legal_hexdigest(s);
-}
-
-/** Return true iff <b>s</b> is a valid hex-encoded identity-key
- * digest. (That is, an optional $, followed by 40 hex characters,
- * followed by either nothing, or = or ~ followed by a nickname, or
- * a character other than =, ~, or a hex character.)
- */
-int
-is_legal_hexdigest(const char *s)
-{
- size_t len;
- tor_assert(s);
- if (s[0] == '$') s++;
- len = strlen(s);
- if (len > HEX_DIGEST_LEN) {
- if (s[HEX_DIGEST_LEN] == '=' ||
- s[HEX_DIGEST_LEN] == '~') {
- if (!is_legal_nickname(s+HEX_DIGEST_LEN+1))
- return 0;
- } else {
- return 0;
- }
- }
- return (len >= HEX_DIGEST_LEN &&
- strspn(s,HEX_CHARACTERS)==HEX_DIGEST_LEN);
-}
-
/** Forget that we have issued any router-related warnings, so that we'll
* warn again if we see the same errors. */
void
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index d56ddc8a1..54b57cf7c 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -14,6 +14,7 @@
#include "lib/testsupport/testsupport.h"
#include "feature/nodelist/describe.h"
+#include "feature/nodelist/nickname.h"
struct curve25519_keypair_t;
struct ed25519_keypair_t;
@@ -119,9 +120,6 @@ int router_has_orport(const routerinfo_t *router,
int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
crypto_pk_t *ident_key,
const struct ed25519_keypair_t *signing_keypair);
-int is_legal_nickname(const char *s);
-int is_legal_nickname_or_hexdigest(const char *s);
-int is_legal_hexdigest(const char *s);
const char *routerinfo_err_to_string(int err);
int routerinfo_err_is_transient(int err);
1
0

26 Sep '18
commit 4f0bc0c8f56f4179482c21bf3122b67ee2fe26d1
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 17:57:58 2018 -0400
Revise things that had included router.h before
Make them only include the headers that they needed, and sort their
headers while we're at it.
---
src/app/config/config.c | 79 ++++++++++++++++++----------------
src/app/main/main.c | 73 +++++++++++++++----------------
src/core/mainloop/connection.c | 46 ++++++++++----------
src/core/mainloop/mainloop.c | 59 ++++++++++++-------------
src/core/or/circuitbuild.c | 49 ++++++++++-----------
src/core/or/circuituse.c | 28 ++++++------
src/core/or/command.c | 22 +++++-----
src/core/or/connection_edge.c | 45 +++++++++----------
src/core/or/relay.c | 2 +-
src/feature/client/bridges.c | 18 ++++----
src/feature/client/entrynodes.c | 35 +++++++--------
src/feature/control/control.c | 57 ++++++++++++------------
src/feature/control/fmt_serverstatus.c | 2 +-
src/feature/dirauth/process_descs.c | 2 +
src/feature/dirauth/reachability.c | 3 +-
src/feature/dirclient/dirclient.c | 4 +-
src/feature/hs/hs_circuit.c | 23 +++++-----
src/feature/hs/hs_client.c | 22 +++++-----
src/feature/hs/hs_common.c | 22 +++++-----
src/feature/hs/hs_service.c | 32 +++++++-------
src/feature/nodelist/describe.c | 2 +-
src/feature/nodelist/networkstatus.c | 48 +++++++++++----------
src/feature/nodelist/node_select.c | 3 +-
src/feature/nodelist/nodelist.c | 27 ++++++------
src/feature/nodelist/routerlist.c | 12 +++---
src/feature/nodelist/routerparse.c | 33 +++++++-------
src/feature/nodelist/routerset.c | 6 +--
src/feature/relay/dns.c | 18 ++++----
src/feature/relay/router.c | 63 ++++++++++++++-------------
src/feature/relay/router.h | 4 --
src/feature/relay/selftest.c | 2 +
src/feature/rend/rendclient.c | 24 +++++------
src/feature/rend/rendservice.c | 32 +++++++-------
src/test/test_dir.c | 53 ++++++++++++-----------
34 files changed, 489 insertions(+), 461 deletions(-)
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 65899b640..91e275865 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -60,62 +60,65 @@
#define CONFIG_PRIVATE
#include "core/or/or.h"
-#include "feature/client/bridges.h"
-#include "feature/client/addressmap.h"
+#include "app/config/config.h"
+#include "app/config/confparse.h"
+#include "app/config/statefile.h"
+#include "app/main/main.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/cpuworker.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitmux.h"
#include "core/or/circuitmux_ewma.h"
#include "core/or/circuitstats.h"
-#include "lib/compress/compress.h"
-#include "app/config/config.h"
-#include "lib/encoding/confline.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
-#include "feature/dircache/consdiffmgr.h"
+#include "core/or/dos.h"
+#include "core/or/policies.h"
+#include "core/or/relay.h"
+#include "core/or/scheduler.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/bridges.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "app/config/confparse.h"
-#include "core/mainloop/cpuworker.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/crypt_ops/crypto_init.h"
-#ifdef ENABLE_NSS
-#include "lib/crypt_ops/crypto_nss_mgt.h"
-#else
-#include "lib/crypt_ops/crypto_openssl_mgt.h"
-#endif
#include "feature/dirauth/bwauth.h"
-#include "feature/dircache/dirserv.h"
#include "feature/dirauth/guardfraction.h"
-#include "feature/relay/dns.h"
-#include "core/or/dos.h"
-#include "feature/client/entrynodes.h"
-#include "lib/log/git_revision.h"
-#include "feature/stats/geoip.h"
+#include "feature/dircache/consdiffmgr.h"
+#include "feature/dircache/dirserv.h"
+#include "feature/dircommon/voting_schedule.h"
#include "feature/hibernate/hibernate.h"
-#include "app/main/main.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/hs/hs_config.h"
+#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "core/or/relay.h"
+#include "feature/nodelist/routerset.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/ext_orport.h"
+#include "feature/relay/routermode.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
-#include "feature/hs/hs_config.h"
+#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "lib/sandbox/sandbox.h"
-#include "feature/nodelist/dirlist.h"
-#include "feature/nodelist/routerset.h"
-#include "core/or/scheduler.h"
-#include "app/config/statefile.h"
-#include "feature/client/transports.h"
-#include "feature/relay/ext_orport.h"
-#include "feature/dircommon/voting_schedule.h"
+#include "lib/compress/compress.h"
+#include "lib/crypt_ops/crypto_init.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
+#include "lib/encoding/confline.h"
+#include "lib/log/git_revision.h"
#include "lib/net/resolve.h"
+#include "lib/sandbox/sandbox.h"
+
+#ifdef ENABLE_NSS
+#include "lib/crypt_ops/crypto_nss_mgt.h"
+#else
+#include "lib/crypt_ops/crypto_openssl_mgt.h"
+#endif
+
#ifdef _WIN32
#include <shlobj.h>
#endif
diff --git a/src/app/main/main.c b/src/app/main/main.c
index 6c7312f67..90bc8c510 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -11,63 +11,64 @@
#include "core/or/or.h"
-#include "feature/client/addressmap.h"
-#include "lib/err/backtrace.h"
-#include "feature/client/bridges.h"
-#include "lib/container/buffers.h"
+#include "app/config/config.h"
+#include "app/config/statefile.h"
+#include "app/main/main.h"
+#include "app/main/ntmain.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/cpuworker.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
-#include "core/or/channeltls.h"
#include "core/or/channelpadding.h"
+#include "core/or/channeltls.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitmux_ewma.h"
#include "core/or/command.h"
-#include "lib/compress/compress.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
-#include "feature/dircache/consdiffmgr.h"
+#include "core/or/policies.h"
+#include "core/or/protover.h"
+#include "core/or/relay.h"
+#include "core/or/scheduler.h"
+#include "core/or/status.h"
+#include "feature/api/tor_api.h"
+#include "feature/api/tor_api_internal.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/bridges.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "core/mainloop/cpuworker.h"
-#include "lib/crypt_ops/crypto_s2k.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "feature/dircache/dirserv.h"
#include "feature/dirauth/bwauth.h"
+#include "feature/dirauth/keypin.h"
#include "feature/dirauth/process_descs.h"
-#include "feature/relay/dns.h"
-#include "feature/relay/routermode.h"
-#include "feature/client/entrynodes.h"
-#include "feature/stats/geoip.h"
+#include "feature/dircache/consdiffmgr.h"
+#include "feature/dircache/dirserv.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
-#include "feature/dirauth/keypin.h"
-#include "app/main/main.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/nodelist/authcert.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "app/main/ntmain.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/nodelist/routerparse.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/ext_orport.h"
#include "feature/relay/onion_queue.h"
-#include "core/or/policies.h"
-#include "core/or/protover.h"
-#include "feature/client/transports.h"
-#include "core/or/relay.h"
+#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
+#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routerkeys.h"
-#include "feature/nodelist/authcert.h"
-#include "feature/nodelist/routerlist.h"
-#include "feature/nodelist/routerparse.h"
-#include "core/or/scheduler.h"
-#include "app/config/statefile.h"
-#include "core/or/status.h"
-#include "feature/api/tor_api.h"
-#include "feature/api/tor_api_internal.h"
+#include "lib/compress/compress.h"
+#include "lib/container/buffers.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_s2k.h"
+#include "lib/err/backtrace.h"
#include "lib/process/waitpid.h"
-#include "feature/relay/ext_orport.h"
+
#include "lib/meminfo/meminfo.h"
#include "lib/osinfo/uname.h"
#include "lib/sandbox/sandbox.h"
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 699e7f710..18863fc04 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -59,51 +59,53 @@
#include "feature/client/bridges.h"
#include "lib/container/buffers.h"
#include "lib/tls/buffers_tls.h"
+#include "lib/err/backtrace.h"
+
/*
* Define this so we get channel internal functions, since we're implementing
* part of a subclass (channel_tls_t).
*/
#define TOR_CHANNEL_INTERNAL_
#define CONNECTION_PRIVATE
-#include "lib/err/backtrace.h"
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
#include "core/or/channeltls.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
+#include "core/or/dos.h"
+#include "core/or/policies.h"
+#include "core/or/reasons.h"
+#include "core/or/relay.h"
+#include "core/proto/proto_http.h"
+#include "core/proto/proto_socks.h"
+#include "feature/client/dnsserv.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_util.h"
#include "feature/dirauth/authmode.h"
-#include "feature/dircommon/directory.h"
#include "feature/dircache/dirserv.h"
-#include "feature/relay/dns.h"
-#include "feature/relay/routermode.h"
-#include "feature/client/dnsserv.h"
-#include "core/or/dos.h"
-#include "feature/client/entrynodes.h"
-#include "feature/relay/ext_orport.h"
-#include "feature/stats/geoip.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_ident.h"
#include "feature/nodelist/nodelist.h"
-#include "core/proto/proto_http.h"
-#include "core/proto/proto_socks.h"
-#include "core/or/policies.h"
-#include "core/or/reasons.h"
-#include "core/or/relay.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/nodelist/routerparse.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/ext_orport.h"
+#include "feature/relay/routermode.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
+#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/nodelist/routerlist.h"
-#include "feature/client/transports.h"
-#include "feature/nodelist/routerparse.h"
+#include "lib/crypt_ops/crypto_util.h"
+
#include "lib/sandbox/sandbox.h"
#include "lib/net/buffers_net.h"
#include "lib/tls/tortls.h"
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index fb405817d..4a9da43c9 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -49,55 +49,56 @@
#define MAINLOOP_PRIVATE
#include "core/or/or.h"
-#include "feature/client/addressmap.h"
-#include "lib/err/backtrace.h"
-#include "feature/client/bridges.h"
-#include "lib/container/buffers.h"
-#include "lib/tls/buffers_tls.h"
+#include "app/config/config.h"
+#include "app/config/statefile.h"
+#include "app/main/ntmain.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/cpuworker.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
+#include "core/mainloop/periodic.h"
#include "core/or/channel.h"
-#include "core/or/channeltls.h"
#include "core/or/channelpadding.h"
+#include "core/or/channeltls.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
-#include "feature/dircache/consdiffmgr.h"
+#include "core/or/dos.h"
+#include "core/or/status.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/bridges.h"
+#include "feature/client/dnsserv.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "core/mainloop/cpuworker.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "feature/dircommon/directory.h"
-#include "feature/dircache/dirserv.h"
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/reachability.h"
-#include "feature/relay/dns.h"
-#include "feature/client/dnsserv.h"
-#include "core/or/dos.h"
-#include "feature/client/entrynodes.h"
-#include "feature/stats/geoip.h"
+#include "feature/dircache/consdiffmgr.h"
+#include "feature/dircache/dirserv.h"
+#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_service.h"
-#include "core/mainloop/mainloop.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "app/main/ntmain.h"
-#include "core/mainloop/periodic.h"
-#include "feature/client/transports.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
+#include "feature/relay/selftest.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendservice.h"
+#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "feature/relay/routerkeys.h"
-#include "feature/relay/selftest.h"
-#include "feature/nodelist/routerlist.h"
-#include "app/config/statefile.h"
-#include "core/or/status.h"
+#include "lib/container/buffers.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/err/backtrace.h"
+#include "lib/tls/buffers_tls.h"
+
#include "lib/net/buffers_net.h"
#include "lib/evloop/compat_libevent.h"
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index f4e0776be..26f0fc4d4 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -28,46 +28,47 @@
#define CIRCUITBUILD_PRIVATE
#include "core/or/or.h"
-#include "feature/client/bridges.h"
+#include "app/config/config.h"
+#include "app/config/confparse.h"
+#include "core/crypto/hs_ntor.h"
+#include "core/crypto/onion_crypto.h"
+#include "core/crypto/onion_fast.h"
+#include "core/crypto/onion_tap.h"
+#include "core/crypto/relay_crypto.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
-#include "feature/client/circpathbias.h"
-#define CIRCUITBUILD_PRIVATE
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitstats.h"
#include "core/or/circuituse.h"
#include "core/or/command.h"
-#include "app/config/config.h"
-#include "app/config/confparse.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
+#include "core/or/onion.h"
+#include "core/or/policies.h"
+#include "core/or/relay.h"
+#include "feature/client/bridges.h"
+#include "feature/client/circpathbias.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_rand.h"
#include "feature/dircommon/directory.h"
-#include "feature/client/entrynodes.h"
-#include "core/crypto/hs_ntor.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
-#include "core/or/onion.h"
-#include "core/crypto/onion_crypto.h"
-#include "core/crypto/onion_tap.h"
-#include "core/crypto/onion_fast.h"
-#include "core/or/policies.h"
-#include "core/or/relay.h"
-#include "core/crypto/relay_crypto.h"
-#include "feature/rend/rendcommon.h"
-#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "feature/relay/selftest.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/node_select.h"
+#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
-#include "feature/client/transports.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
+#include "feature/relay/selftest.h"
+#include "feature/rend/rendcommon.h"
+#include "feature/stats/rephist.h"
+#include "lib/crypt_ops/crypto_rand.h"
#include "core/or/cell_st.h"
#include "core/or/cpath_build_state_st.h"
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 34b51a502..d035d66ea 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -28,36 +28,36 @@
**/
#include "core/or/or.h"
-#include "feature/client/addressmap.h"
-#include "feature/client/bridges.h"
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
#include "core/or/channel.h"
-#include "feature/client/circpathbias.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitstats.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
+#include "core/or/policies.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/bridges.h"
+#include "feature/client/circpathbias.h"
+#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/dircommon/directory.h"
-#include "feature/client/entrynodes.h"
-#include "feature/hs/hs_common.h"
-#include "feature/hs/hs_client.h"
#include "feature/hs/hs_circuit.h"
+#include "feature/hs/hs_client.h"
+#include "feature/hs/hs_common.h"
#include "feature/hs/hs_ident.h"
#include "feature/hs/hs_stats.h"
-#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
-#include "core/or/policies.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/relay/routermode.h"
+#include "feature/relay/selftest.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "feature/relay/selftest.h"
-#include "feature/nodelist/routerlist.h"
#include "lib/math/fp.h"
#include "lib/time/tvdiff.h"
diff --git a/src/core/or/command.c b/src/core/or/command.c
index 9e19d28c7..cbe7f622e 100644
--- a/src/core/or/command.c
+++ b/src/core/or/command.c
@@ -37,26 +37,26 @@
* called when channels are created in circuitbuild.c
*/
#include "core/or/or.h"
+#include "app/config/config.h"
+#include "core/crypto/onion_crypto.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/cpuworker.h"
#include "core/or/channel.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/command.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_or.h"
-#include "app/config/config.h"
-#include "feature/control/control.h"
-#include "core/mainloop/cpuworker.h"
-#include "lib/crypt_ops/crypto_util.h"
#include "core/or/dos.h"
-#include "feature/hibernate/hibernate.h"
-#include "feature/nodelist/nodelist.h"
#include "core/or/onion.h"
-#include "core/crypto/onion_crypto.h"
-#include "feature/stats/rephist.h"
#include "core/or/relay.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
+#include "feature/control/control.h"
+#include "feature/hibernate/hibernate.h"
+#include "feature/nodelist/describe.h"
+#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
+#include "feature/relay/routermode.h"
+#include "feature/stats/rephist.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "core/or/cell_st.h"
#include "core/or/or_circuit_st.h"
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index 6dc0814b1..d8b45fe35 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -59,44 +59,45 @@
#include "lib/err/backtrace.h"
-#include "feature/client/addressmap.h"
-#include "lib/container/buffers.h"
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
-#include "feature/client/circpathbias.h"
+#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
-#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/relay/dns.h"
+#include "core/or/policies.h"
+#include "core/or/reasons.h"
+#include "core/or/relay.h"
+#include "core/proto/proto_http.h"
+#include "core/proto/proto_socks.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/circpathbias.h"
#include "feature/client/dnsserv.h"
-#include "feature/dircommon/directory.h"
+#include "feature/control/control.h"
#include "feature/dircache/dirserv.h"
+#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
-#include "feature/hs/hs_common.h"
#include "feature/hs/hs_cache.h"
-#include "feature/hs/hs_client.h"
#include "feature/hs/hs_circuit.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/hs/hs_client.h"
+#include "feature/hs/hs_common.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "core/proto/proto_http.h"
-#include "core/proto/proto_socks.h"
-#include "core/or/reasons.h"
-#include "core/or/relay.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/nodelist/routerset.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "feature/nodelist/routerlist.h"
-#include "feature/nodelist/routerset.h"
-#include "core/or/circuitbuild.h"
+#include "lib/container/buffers.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "core/or/cell_st.h"
#include "core/or/cpath_build_state_st.h"
diff --git a/src/core/or/relay.c b/src/core/or/relay.c
index 47be0f403..88bcdf070 100644
--- a/src/core/or/relay.c
+++ b/src/core/or/relay.c
@@ -77,7 +77,7 @@
#include "core/crypto/relay_crypto.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendcommon.h"
-#include "feature/relay/router.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "core/or/scheduler.h"
diff --git a/src/feature/client/bridges.c b/src/feature/client/bridges.c
index e8afb5a92..47a424955 100644
--- a/src/feature/client/bridges.c
+++ b/src/feature/client/bridges.c
@@ -14,22 +14,22 @@
#define TOR_BRIDGES_PRIVATE
#include "core/or/or.h"
-#include "feature/client/bridges.h"
-#include "core/or/circuitbuild.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
-#include "feature/dircommon/directory.h"
+#include "core/or/circuitbuild.h"
+#include "core/or/policies.h"
+#include "feature/client/bridges.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
-#include "feature/client/entrynodes.h"
-#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "feature/relay/router.h"
+#include "feature/dircommon/directory.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
-
#include "feature/nodelist/routerset.h"
-#include "feature/client/transports.h"
#include "core/or/extend_info_st.h"
#include "feature/nodelist/node_st.h"
diff --git a/src/feature/client/entrynodes.c b/src/feature/client/entrynodes.c
index 521bf33b5..8ad16af6d 100644
--- a/src/feature/client/entrynodes.c
+++ b/src/feature/client/entrynodes.c
@@ -113,40 +113,41 @@
#define ENTRYNODES_PRIVATE
#include "core/or/or.h"
+#include "app/config/config.h"
+#include "app/config/confparse.h"
+#include "app/config/statefile.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
-#include "feature/client/bridges.h"
-#include "feature/client/circpathbias.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
-#include "core/or/circuituse.h"
#include "core/or/circuitstats.h"
-#include "app/config/config.h"
-#include "app/config/confparse.h"
-#include "core/mainloop/connection.h"
+#include "core/or/circuituse.h"
+#include "core/or/policies.h"
+#include "feature/client/bridges.h"
+#include "feature/client/circpathbias.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_rand.h"
#include "feature/dircommon/directory.h"
-#include "feature/client/entrynodes.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "feature/relay/router.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/node_select.h"
+#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
-#include "feature/client/transports.h"
-#include "app/config/statefile.h"
-#include "lib/math/fp.h"
+#include "feature/relay/router.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/digestset.h"
#include "lib/encoding/confline.h"
+#include "lib/math/fp.h"
#include "feature/nodelist/node_st.h"
#include "core/or/origin_circuit_st.h"
#include "app/config/or_state_st.h"
-#include "lib/crypt_ops/digestset.h"
-
/** A list of existing guard selection contexts. */
static smartlist_t *guard_contexts = NULL;
/** The currently enabled guard selection context. */
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index 43ec0bd8b..d8d08f2c8 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -36,9 +36,11 @@
#define CONTROL_PRIVATE
#include "core/or/or.h"
-#include "feature/client/addressmap.h"
-#include "feature/client/bridges.h"
-#include "lib/container/buffers.h"
+#include "app/config/config.h"
+#include "app/config/confparse.h"
+#include "app/main/main.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
#include "core/or/channeltls.h"
#include "core/or/circuitbuild.h"
@@ -46,49 +48,48 @@
#include "core/or/circuitstats.h"
#include "core/or/circuituse.h"
#include "core/or/command.h"
-#include "lib/evloop/compat_libevent.h"
-#include "app/config/config.h"
-#include "app/config/confparse.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
+#include "core/or/policies.h"
+#include "core/or/reasons.h"
+#include "core/proto/proto_control0.h"
+#include "core/proto/proto_http.h"
+#include "feature/client/addressmap.h"
+#include "feature/client/bridges.h"
+#include "feature/client/dnsserv.h"
+#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/control/fmt_serverstatus.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dircommon/directory.h"
+#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
-#include "feature/dircache/dirserv.h"
-#include "feature/client/dnsserv.h"
-#include "feature/client/entrynodes.h"
-#include "feature/stats/geoip.h"
+#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_control.h"
-#include "app/main/main.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/hs_common/shared_random_client.h"
+#include "feature/nodelist/authcert.h"
+#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "core/proto/proto_control0.h"
-#include "core/proto/proto_http.h"
-#include "core/or/reasons.h"
+#include "feature/nodelist/routerinfo.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/nodelist/routerparse.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
+#include "feature/relay/selftest.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendservice.h"
+#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routermode.h"
-#include "feature/relay/selftest.h"
-#include "feature/nodelist/authcert.h"
-#include "feature/nodelist/dirlist.h"
-#include "feature/nodelist/routerlist.h"
-#include "feature/nodelist/routerparse.h"
-#include "feature/hs_common/shared_random_client.h"
+#include "lib/container/buffers.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
+#include "lib/evloop/compat_libevent.h"
#include "feature/dircache/cached_dir_st.h"
#include "feature/control/control_connection_st.h"
diff --git a/src/feature/control/fmt_serverstatus.c b/src/feature/control/fmt_serverstatus.c
index ed9f14ab3..eef85d356 100644
--- a/src/feature/control/fmt_serverstatus.c
+++ b/src/feature/control/fmt_serverstatus.c
@@ -10,7 +10,7 @@
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/voteflags.h"// XXXX remove
#include "feature/nodelist/nodelist.h"
-#include "feature/relay/router.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/node_st.h"
#include "feature/nodelist/routerinfo_st.h"
diff --git a/src/feature/dirauth/process_descs.c b/src/feature/dirauth/process_descs.c
index 1cf31f85c..823a1b879 100644
--- a/src/feature/dirauth/process_descs.c
+++ b/src/feature/dirauth/process_descs.c
@@ -21,8 +21,10 @@
#include "feature/dirauth/reachability.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/dircommon/directory.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/torcert.h"
diff --git a/src/feature/dirauth/reachability.c b/src/feature/dirauth/reachability.c
index 79c98d3ee..122c239f9 100644
--- a/src/feature/dirauth/reachability.c
+++ b/src/feature/dirauth/reachability.c
@@ -17,10 +17,11 @@
#include "core/or/channeltls.h"
#include "core/or/command.h"
#include "feature/dirauth/authmode.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/torcert.h"
-#include "feature/relay/router.h"
#include "feature/stats/rephist.h"
#include "feature/nodelist/node_st.h"
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index 16d2e03b4..4b86e96eb 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -15,8 +15,8 @@
#include "feature/client/bridges.h"
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
-#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/authmode.h"
+#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/shared_random.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
@@ -28,11 +28,13 @@
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_control.h"
#include "feature/nodelist/authcert.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/relay/routermode.h"
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index 70760e013..092781d7e 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -8,27 +8,26 @@
#define HS_CIRCUIT_PRIVATE
#include "core/or/or.h"
-#include "feature/client/circpathbias.h"
+#include "app/config/config.h"
+#include "core/crypto/hs_ntor.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "lib/crypt_ops/crypto_dh.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/nodelist/nodelist.h"
#include "core/or/policies.h"
#include "core/or/relay.h"
-#include "feature/rend/rendservice.h"
-#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-
+#include "feature/client/circpathbias.h"
#include "feature/hs/hs_cell.h"
+#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_circuitmap.h"
#include "feature/hs/hs_ident.h"
-#include "core/crypto/hs_ntor.h"
#include "feature/hs/hs_service.h"
-#include "feature/hs/hs_circuit.h"
+#include "feature/nodelist/describe.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/rend/rendservice.h"
+#include "feature/stats/rephist.h"
+#include "lib/crypt_ops/crypto_dh.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
/* Trunnel. */
#include "trunnel/ed25519_cert.h"
diff --git a/src/feature/hs/hs_client.c b/src/feature/hs/hs_client.c
index 0d382f9c8..3fd6d1f01 100644
--- a/src/feature/hs/hs_client.c
+++ b/src/feature/hs/hs_client.c
@@ -9,18 +9,17 @@
#define HS_CLIENT_PRIVATE
#include "core/or/or.h"
-#include "feature/client/circpathbias.h"
+#include "app/config/config.h"
+#include "core/crypto/hs_ntor.h"
+#include "core/mainloop/connection.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dircommon/directory.h"
+#include "core/or/reasons.h"
+#include "feature/client/circpathbias.h"
#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_cell.h"
#include "feature/hs/hs_circuit.h"
@@ -29,13 +28,14 @@
#include "feature/hs/hs_control.h"
#include "feature/hs/hs_descriptor.h"
#include "feature/hs/hs_ident.h"
-#include "core/crypto/hs_ntor.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/reasons.h"
-#include "feature/rend/rendclient.h"
-#include "feature/relay/router.h"
#include "feature/nodelist/routerset.h"
+#include "feature/rend/rendclient.h"
+#include "lib/crypt_ops/crypto_format.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "core/or/cpath_build_state_st.h"
#include "feature/dircommon/dir_connection_st.h"
diff --git a/src/feature/hs/hs_common.c b/src/feature/hs/hs_common.c
index c36892e0f..4bad4ae6e 100644
--- a/src/feature/hs/hs_common.c
+++ b/src/feature/hs/hs_common.c
@@ -15,23 +15,23 @@
#include "app/config/config.h"
#include "core/or/circuitbuild.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
+#include "core/or/policies.h"
+#include "feature/dirauth/shared_random_state.h"
#include "feature/hs/hs_cache.h"
-#include "feature/hs/hs_common.h"
+#include "feature/hs/hs_circuitmap.h"
#include "feature/hs/hs_client.h"
+#include "feature/hs/hs_common.h"
#include "feature/hs/hs_ident.h"
#include "feature/hs/hs_service.h"
-#include "feature/hs/hs_circuitmap.h"
-#include "core/or/policies.h"
+#include "feature/hs_common/shared_random_client.h"
+#include "feature/nodelist/describe.h"
+#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerset.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendservice.h"
-#include "feature/nodelist/routerset.h"
-#include "feature/relay/router.h"
-#include "feature/hs_common/shared_random_client.h"
-#include "feature/dirauth/shared_random_state.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "core/or/edge_connection_st.h"
#include "feature/nodelist/networkstatus_st.h"
diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c
index aa031bd70..78654bfb2 100644
--- a/src/feature/hs/hs_service.c
+++ b/src/feature/hs/hs_service.c
@@ -9,29 +9,29 @@
#define HS_SERVICE_PRIVATE
#include "core/or/or.h"
-#include "feature/client/circpathbias.h"
+#include "app/config/config.h"
+#include "app/config/statefile.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/crypt_ops/crypto_ope.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "feature/dircommon/directory.h"
+#include "core/or/relay.h"
+#include "feature/client/circpathbias.h"
#include "feature/dirclient/dirclient.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/dircommon/directory.h"
+#include "feature/hs_common/shared_random_client.h"
+#include "feature/keymgt/loadkey.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
+#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/relay.h"
#include "feature/rend/rendservice.h"
-#include "feature/relay/router.h"
-#include "feature/keymgt/loadkey.h"
-//#include "feature/relay/routerkeys.h"
-#include "feature/nodelist/node_select.h"
-#include "feature/hs_common/shared_random_client.h"
-#include "app/config/statefile.h"
+#include "lib/crypt_ops/crypto_ope.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_common.h"
diff --git a/src/feature/nodelist/describe.c b/src/feature/nodelist/describe.c
index 0ef9e3e7f..6df3da196 100644
--- a/src/feature/nodelist/describe.c
+++ b/src/feature/nodelist/describe.c
@@ -11,7 +11,7 @@
#include "core/or/or.h"
#include "feature/nodelist/describe.h"
-#include "feature/relay/router.h"
+#include "feature/nodelist/routerinfo.h"
#include "core/or/extend_info_st.h"
#include "feature/nodelist/node_st.h"
diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c
index 40457ef68..67b5a1d04 100644
--- a/src/feature/nodelist/networkstatus.c
+++ b/src/feature/nodelist/networkstatus.c
@@ -38,45 +38,47 @@
#define NETWORKSTATUS_PRIVATE
#include "core/or/or.h"
-#include "feature/client/bridges.h"
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/channel.h"
+#include "core/or/channelpadding.h"
#include "core/or/circuitmux.h"
#include "core/or/circuitmux_ewma.h"
#include "core/or/circuitstats.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
-#include "feature/dircache/consdiffmgr.h"
+#include "core/or/dos.h"
+#include "core/or/protover.h"
+#include "core/or/relay.h"
+#include "core/or/scheduler.h"
+#include "feature/client/bridges.h"
+#include "feature/client/entrynodes.h"
+#include "feature/client/transports.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dircommon/directory.h"
+#include "feature/dirauth/reachability.h"
+#include "feature/dircache/consdiffmgr.h"
+#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
-#include "feature/dircache/dirserv.h"
-#include "feature/dirauth/reachability.h"
-#include "core/or/dos.h"
-#include "feature/client/entrynodes.h"
+#include "feature/dircommon/directory.h"
+#include "feature/dircommon/voting_schedule.h"
#include "feature/hibernate/hibernate.h"
-#include "core/mainloop/mainloop.h"
-#include "feature/nodelist/microdesc.h"
-#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
-#include "core/or/protover.h"
-#include "core/or/relay.h"
-#include "feature/relay/routermode.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
+#include "feature/nodelist/fmt_routerstatus.h"
+#include "feature/nodelist/microdesc.h"
+#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/node_select.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
-#include "core/or/scheduler.h"
-#include "feature/client/transports.h"
#include "feature/nodelist/torcert.h"
-#include "core/or/channelpadding.h"
-#include "feature/dircommon/voting_schedule.h"
-#include "feature/nodelist/fmt_routerstatus.h"
+#include "feature/relay/routermode.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/authmode.h"
diff --git a/src/feature/nodelist/node_select.c b/src/feature/nodelist/node_select.c
index 6d58705cc..04a24de9a 100644
--- a/src/feature/nodelist/node_select.c
+++ b/src/feature/nodelist/node_select.c
@@ -18,8 +18,9 @@
#include "core/or/policies.h"
#include "core/or/reasons.h"
#include "feature/client/entrynodes.h"
-#include "feature/dircommon/directory.h"
#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index b5ded356b..e3b77d562 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -41,31 +41,32 @@
#define NODELIST_PRIVATE
#include "core/or/or.h"
-#include "lib/net/address.h"
+#include "app/config/config.h"
+#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/address_set.h"
+#include "core/or/policies.h"
+#include "core/or/protover.h"
#include "feature/client/bridges.h"
-#include "app/config/config.h"
+#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
-#include "feature/dircache/dirserv.h"
#include "feature/dirauth/process_descs.h"
-#include "feature/client/entrynodes.h"
-#include "feature/stats/geoip.h"
-#include "feature/hs/hs_common.h"
+#include "feature/dircache/dirserv.h"
#include "feature/hs/hs_client.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/hs/hs_common.h"
+#include "feature/nodelist/describe.h"
+#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "core/or/protover.h"
-#include "feature/rend/rendservice.h"
-#include "feature/relay/router.h"
-#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/node_select.h"
+#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
+#include "feature/rend/rendservice.h"
+#include "feature/stats/geoip.h"
+#include "lib/net/address.h"
#include <string.h>
diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c
index 2bd6e5c6f..20956d8cc 100644
--- a/src/feature/nodelist/routerlist.c
+++ b/src/feature/nodelist/routerlist.c
@@ -69,18 +69,20 @@
#include "feature/client/bridges.h"
#include "feature/control/control.h"
#include "feature/dirauth/authmode.h"
-#include "feature/dircommon/directory.h"
-#include "feature/dirclient/dirclient.h"
+#include "feature/dirauth/process_descs.h"
+#include "feature/dirauth/reachability.h"
#include "feature/dircache/dirserv.h"
+#include "feature/dirclient/dirclient.h"
#include "feature/dirclient/dlstatus.h"
-#include "feature/dirauth/reachability.h"
-#include "feature/dirauth/process_descs.h"
+#include "feature/dircommon/directory.h"
#include "feature/nodelist/authcert.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/node_select.h"
+#include "feature/nodelist/nodelist.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
diff --git a/src/feature/nodelist/routerparse.c b/src/feature/nodelist/routerparse.c
index a72cf98f5..c12f411e8 100644
--- a/src/feature/nodelist/routerparse.c
+++ b/src/feature/nodelist/routerparse.c
@@ -56,29 +56,32 @@
#define ROUTERPARSE_PRIVATE
#include "core/or/or.h"
-#include "core/or/circuitstats.h"
#include "app/config/config.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dirauth/shared_random.h"
+#include "core/or/circuitstats.h"
+#include "core/or/policies.h"
+#include "core/or/protover.h"
#include "feature/client/entrynodes.h"
-#include "lib/memarea/memarea.h"
+#include "feature/dirauth/shared_random.h"
+#include "feature/dircommon/voting_schedule.h"
+#include "feature/hs_common/shared_random_client.h"
+#include "feature/nodelist/authcert.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/parsecommon.h"
-#include "core/or/policies.h"
-#include "core/or/protover.h"
-#include "feature/rend/rendcommon.h"
-#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routerkeys.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
-#include "feature/nodelist/authcert.h"
-#include "lib/sandbox/sandbox.h"
-#include "feature/hs_common/shared_random_client.h"
#include "feature/nodelist/torcert.h"
-#include "feature/dircommon/voting_schedule.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routerkeys.h"
+#include "feature/rend/rendcommon.h"
+#include "feature/stats/rephist.h"
+#include "lib/crypt_ops/crypto_format.h"
+#include "lib/crypt_ops/crypto_util.h"
+#include "lib/memarea/memarea.h"
+#include "lib/sandbox/sandbox.h"
#include "feature/dirauth/dirvote.h"
diff --git a/src/feature/nodelist/routerset.c b/src/feature/nodelist/routerset.c
index cd4269774..08124835a 100644
--- a/src/feature/nodelist/routerset.c
+++ b/src/feature/nodelist/routerset.c
@@ -28,13 +28,13 @@ n * Copyright (c) 2001-2004, Roger Dingledine.
#define ROUTERSET_PRIVATE
#include "core/or/or.h"
+#include "core/or/policies.h"
#include "feature/client/bridges.h"
-#include "feature/stats/geoip.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
-#include "feature/relay/router.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
+#include "feature/stats/geoip.h"
#include "core/or/addr_policy_st.h"
#include "core/or/extend_info_st.h"
diff --git a/src/feature/relay/dns.c b/src/feature/relay/dns.c
index 52488ff94..bc507d47f 100644
--- a/src/feature/relay/dns.c
+++ b/src/feature/relay/dns.c
@@ -50,26 +50,28 @@
#define DNS_PRIVATE
#include "core/or/or.h"
-#include "core/or/circuitlist.h"
-#include "core/or/circuituse.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
-#include "core/or/connection_edge.h"
-#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "feature/relay/dns.h"
#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
+#include "core/or/circuitlist.h"
+#include "core/or/circuituse.h"
+#include "core/or/connection_edge.h"
#include "core/or/policies.h"
#include "core/or/relay.h"
+#include "feature/control/control.h"
+#include "feature/relay/dns.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
-#include "ht.h"
-#include "lib/sandbox/sandbox.h"
+#include "lib/crypt_ops/crypto_rand.h"
#include "lib/evloop/compat_libevent.h"
+#include "lib/sandbox/sandbox.h"
#include "core/or/edge_connection_st.h"
#include "core/or/or_circuit_st.h"
+#include "ht.h"
+
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 05e3fb3b2..adec40e54 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -7,43 +7,50 @@
#define ROUTER_PRIVATE
#include "core/or/or.h"
-#include "core/or/circuitbuild.h"
-#include "core/or/circuitlist.h"
-#include "core/or/circuituse.h"
#include "app/config/config.h"
-#include "core/mainloop/connection.h"
-#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "lib/crypt_ops/crypto_curve25519.h"
-#include "feature/dircommon/directory.h"
-#include "feature/dirclient/dirclient.h"
-#include "feature/dircache/dirserv.h"
-#include "feature/dirauth/process_descs.h"
-#include "feature/relay/dns.h"
-#include "feature/stats/geoip.h"
-#include "feature/hibernate/hibernate.h"
+#include "app/config/statefile.h"
#include "app/main/main.h"
+#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
-#include "feature/nodelist/networkstatus.h"
-#include "feature/nodelist/nodelist.h"
+#include "core/mainloop/netstatus.h"
+#include "core/or/circuitbuild.h"
+#include "core/or/circuitlist.h"
+#include "core/or/circuituse.h"
#include "core/or/policies.h"
#include "core/or/protover.h"
#include "core/or/relay.h"
+#include "feature/client/transports.h"
+#include "feature/control/control.h"
+#include "feature/dirauth/process_descs.h"
+#include "feature/dircache/dirserv.h"
+#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
+#include "feature/hibernate/hibernate.h"
#include "feature/keymgt/loadkey.h"
-#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"
+#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
+#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
-#include "app/config/statefile.h"
-#include "feature/nodelist/torcert.h"
-#include "feature/client/transports.h"
#include "feature/nodelist/routerset.h"
+#include "feature/nodelist/torcert.h"
+#include "feature/relay/dns.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
+#include "feature/relay/selftest.h"
+#include "feature/stats/geoip.h"
+#include "feature/stats/rephist.h"
+#include "lib/crypt_ops/crypto_curve25519.h"
+#include "lib/crypt_ops/crypto_format.h"
+#include "lib/crypt_ops/crypto_init.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
+#include "lib/encoding/confline.h"
+#include "lib/osinfo/uname.h"
+#include "lib/tls/tortls.h"
#include "feature/dirauth/authmode.h"
@@ -59,12 +66,6 @@
#include "core/or/port_cfg_st.h"
#include "feature/nodelist/routerinfo_st.h"
-#include "lib/osinfo/uname.h"
-#include "lib/tls/tortls.h"
-#include "lib/encoding/confline.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_init.h"
-
/**
* \file router.c
* \brief Miscellaneous relay functionality, including RSA key maintenance,
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index a9c7ac3fd..4575172af 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -13,10 +13,6 @@
#define TOR_ROUTER_H
#include "lib/testsupport/testsupport.h"
-#include "feature/nodelist/describe.h"
-#include "feature/nodelist/nickname.h"
-#include "feature/nodelist/routerinfo.h"
-#include "core/mainloop/netstatus.h"
struct curve25519_keypair_t;
struct ed25519_keypair_t;
diff --git a/src/feature/relay/selftest.c b/src/feature/relay/selftest.c
index 789870d29..26205aad0 100644
--- a/src/feature/relay/selftest.c
+++ b/src/feature/relay/selftest.c
@@ -19,6 +19,7 @@
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
+#include "core/mainloop/netstatus.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
@@ -29,6 +30,7 @@
#include "feature/dirclient/dirclient.h"
#include "feature/dircommon/directory.h"
#include "feature/nodelist/authority_cert_st.h"
+#include "feature/nodelist/routerinfo.h"
#include "feature/nodelist/routerinfo_st.h"
#include "feature/nodelist/routerlist.h" // but...
#include "feature/nodelist/routerset.h"
diff --git a/src/feature/rend/rendclient.c b/src/feature/rend/rendclient.c
index d1310699f..10b67ceda 100644
--- a/src/feature/rend/rendclient.c
+++ b/src/feature/rend/rendclient.c
@@ -8,32 +8,32 @@
**/
#include "core/or/or.h"
-#include "feature/client/circpathbias.h"
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
-#include "core/mainloop/connection.h"
#include "core/or/connection_edge.h"
+#include "core/or/relay.h"
+#include "feature/client/circpathbias.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_dh.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dircommon/directory.h"
#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
#include "feature/hs/hs_circuit.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_common.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/relay.h"
+#include "feature/nodelist/routerlist.h"
+#include "feature/nodelist/routerset.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
-#include "feature/nodelist/routerlist.h"
-#include "feature/nodelist/routerset.h"
+#include "lib/crypt_ops/crypto_dh.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "core/or/cpath_build_state_st.h"
diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c
index b16574003..8257919ac 100644
--- a/src/feature/rend/rendservice.c
+++ b/src/feature/rend/rendservice.c
@@ -10,34 +10,36 @@
#define RENDSERVICE_PRIVATE
#include "core/or/or.h"
-#include "feature/client/circpathbias.h"
+
+#include "app/config/config.h"
+#include "core/mainloop/mainloop.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
-#include "app/config/config.h"
+#include "core/or/policies.h"
+#include "core/or/relay.h"
+#include "feature/client/circpathbias.h"
#include "feature/control/control.h"
-#include "lib/crypt_ops/crypto_dh.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "lib/crypt_ops/crypto_util.h"
-#include "feature/dircommon/directory.h"
#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_config.h"
-#include "core/mainloop/mainloop.h"
+#include "feature/hs_common/replaycache.h"
+#include "feature/keymgt/loadkey.h"
+#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
+#include "feature/nodelist/node_select.h"
#include "feature/nodelist/nodelist.h"
-#include "core/or/policies.h"
+#include "feature/nodelist/routerparse.h"
+#include "feature/nodelist/routerset.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
#include "feature/rend/rendservice.h"
-#include "feature/relay/router.h"
-#include "feature/keymgt/loadkey.h"
-#include "core/or/relay.h"
#include "feature/stats/rephist.h"
-#include "feature/hs_common/replaycache.h"
-#include "feature/nodelist/node_select.h"
-#include "feature/nodelist/routerparse.h"
-#include "feature/nodelist/routerset.h"
+#include "lib/crypt_ops/crypto_dh.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/crypt_ops/crypto_util.h"
#include "lib/encoding/confline.h"
#include "lib/net/resolve.h"
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 58070766a..aa1c706b1 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -24,48 +24,49 @@
#define VOTEFLAGS_PRIVATE
#include "core/or/or.h"
-#include "feature/client/bridges.h"
-#include "core/mainloop/connection.h"
-#include "app/config/confparse.h"
#include "app/config/config.h"
+#include "app/config/confparse.h"
+#include "core/mainloop/connection.h"
+#include "core/or/relay.h"
+#include "feature/client/bridges.h"
+#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
-#include "lib/encoding/confline.h"
-#include "lib/crypt_ops/crypto_ed25519.h"
-#include "lib/crypt_ops/crypto_format.h"
-#include "lib/crypt_ops/crypto_rand.h"
-#include "feature/dircommon/directory.h"
-#include "feature/dirclient/dirclient.h"
-#include "feature/dirclient/dlstatus.h"
#include "feature/dirauth/bwauth.h"
-#include "feature/dircache/dircache.h"
-#include "feature/dircache/dirserv.h"
-#include "feature/dirauth/process_descs.h"
#include "feature/dirauth/dirvote.h"
+#include "feature/dirauth/process_descs.h"
#include "feature/dirauth/recommend_pkg.h"
+#include "feature/dirauth/shared_random_state.h"
#include "feature/dirauth/voteflags.h"
-#include "feature/client/entrynodes.h"
+#include "feature/dircache/dircache.h"
+#include "feature/dircache/dirserv.h"
+#include "feature/dirclient/dirclient.h"
+#include "feature/dirclient/dlstatus.h"
+#include "feature/dircommon/directory.h"
#include "feature/dircommon/fp_pair.h"
+#include "feature/dircommon/voting_schedule.h"
#include "feature/hibernate/hibernate.h"
-#include "lib/memarea/memarea.h"
-#include "lib/osinfo/uname.h"
-#include "feature/nodelist/networkstatus.h"
-#include "feature/relay/router.h"
-#include "feature/relay/routerkeys.h"
-#include "feature/relay/routermode.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
+#include "feature/nodelist/networkstatus.h"
+#include "feature/nodelist/nickname.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
-#include "feature/dirauth/shared_random_state.h"
-#include "test/test.h"
-#include "test/test_dir_common.h"
#include "feature/nodelist/torcert.h"
-#include "core/or/relay.h"
-#include "test/log_test_helpers.h"
-#include "feature/dircommon/voting_schedule.h"
+#include "feature/relay/router.h"
+#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "lib/compress/compress.h"
+#include "lib/crypt_ops/crypto_ed25519.h"
+#include "lib/crypt_ops/crypto_format.h"
+#include "lib/crypt_ops/crypto_rand.h"
+#include "lib/encoding/confline.h"
+#include "lib/memarea/memarea.h"
+#include "lib/osinfo/uname.h"
+#include "test/log_test_helpers.h"
+#include "test/test.h"
+#include "test/test_dir_common.h"
#include "core/or/addr_policy_st.h"
#include "feature/nodelist/authority_cert_st.h"
1
0
commit 3a643078c1eda04e5db3e366a881b4edcf29b00a
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 18:54:17 2018 -0400
Changes file for splitting router.c
---
changes/ticket_27864 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/changes/ticket_27864 b/changes/ticket_27864
new file mode 100644
index 000000000..cf144101d
--- /dev/null
+++ b/changes/ticket_27864
@@ -0,0 +1,3 @@
+ o Code simplification and refactoring:
+ - Split the router.c file into relay-only and shared components,
+ to help with future modularization. Closes ticket 27864.
1
0
commit 5fe05de4febc4b17a7f184932ea6cea3e766dbc8
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 18:33:13 2018 -0400
Remove extra includes from router.c
---
src/feature/relay/router.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index adec40e54..8629ad956 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -13,12 +13,8 @@
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
-#include "core/or/circuitbuild.h"
-#include "core/or/circuitlist.h"
-#include "core/or/circuituse.h"
#include "core/or/policies.h"
#include "core/or/protover.h"
-#include "core/or/relay.h"
#include "feature/client/transports.h"
#include "feature/control/control.h"
#include "feature/dirauth/process_descs.h"
@@ -34,7 +30,6 @@
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
-#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
#include "feature/relay/dns.h"
#include "feature/relay/router.h"
@@ -43,7 +38,7 @@
#include "feature/relay/selftest.h"
#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
-#include "lib/crypt_ops/crypto_curve25519.h"
+#include "lib/crypt_ops/crypto_ed25519.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/crypt_ops/crypto_init.h"
#include "lib/crypt_ops/crypto_rand.h"
@@ -54,17 +49,15 @@
#include "feature/dirauth/authmode.h"
-#include "feature/nodelist/authority_cert_st.h"
-#include "core/or/crypt_path_st.h"
-#include "feature/dircommon/dir_connection_st.h"
+#include "app/config/or_state_st.h"
+#include "core/or/port_cfg_st.h"
#include "feature/dirclient/dir_server_st.h"
-#include "core/or/extend_info_st.h"
+#include "feature/dircommon/dir_connection_st.h"
+#include "feature/nodelist/authority_cert_st.h"
#include "feature/nodelist/extrainfo_st.h"
#include "feature/nodelist/node_st.h"
-#include "core/or/origin_circuit_st.h"
-#include "app/config/or_state_st.h"
-#include "core/or/port_cfg_st.h"
#include "feature/nodelist/routerinfo_st.h"
+#include "feature/nodelist/routerstatus_st.h"
/**
* \file router.c
1
0
commit de0b07c634c45297bad794567cb44ab91988b0ca
Merge: 5e5e019b3 3a643078c
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Wed Sep 26 09:47:59 2018 -0400
Merge branch 'router_split'
changes/ticket_27864 | 3 +
src/app/config/config.c | 80 +--
src/app/config/statefile.c | 1 +
src/app/main/main.c | 74 +--
src/core/include.am | 18 +-
src/core/mainloop/connection.c | 46 +-
src/core/mainloop/mainloop.c | 60 +--
src/core/mainloop/netstatus.c | 28 ++
src/core/mainloop/netstatus.h | 13 +
src/core/or/channelpadding.c | 1 +
src/core/or/channeltls.c | 1 +
src/core/or/circuitbuild.c | 47 +-
src/core/or/circuitstats.c | 1 +
src/core/or/circuituse.c | 26 +-
src/core/or/command.c | 21 +-
src/core/or/connection_edge.c | 44 +-
src/core/or/connection_or.c | 2 +
src/core/or/dos.c | 2 +-
src/core/or/policies.c | 1 +
src/core/or/relay.c | 2 +-
src/core/or/status.c | 1 +
src/feature/client/bridges.c | 18 +-
src/feature/client/entrynodes.c | 35 +-
src/feature/control/control.c | 55 ++-
src/feature/control/fmt_serverstatus.c | 3 +-
src/feature/dirauth/authmode.c | 70 +++
src/feature/dirauth/authmode.h | 42 ++
src/feature/dirauth/dirvote.c | 2 +-
src/feature/dirauth/mode.h | 38 --
src/feature/dirauth/process_descs.c | 2 +
src/feature/dirauth/reachability.c | 4 +-
src/feature/dirauth/shared_random.c | 2 +-
src/feature/dircache/dircache.c | 4 +-
src/feature/dircache/dirserv.c | 1 +
src/feature/dirclient/dirclient.c | 7 +-
src/feature/dirclient/dlstatus.c | 2 +-
src/feature/hs/hs_circuit.c | 23 +-
src/feature/hs/hs_client.c | 22 +-
src/feature/hs/hs_common.c | 22 +-
src/feature/hs/hs_service.c | 31 +-
src/feature/keymgt/loadkey.c | 755 ++++++++++++++++++++++++++++
src/feature/keymgt/loadkey.h | 55 +++
src/feature/nodelist/authcert.c | 3 +-
src/feature/nodelist/describe.c | 183 +++++++
src/feature/nodelist/describe.h | 25 +
src/feature/nodelist/dirlist.c | 1 +
src/feature/nodelist/networkstatus.c | 50 +-
src/feature/nodelist/nickname.c | 62 +++
src/feature/nodelist/nickname.h | 19 +
src/feature/nodelist/node_select.c | 4 +-
src/feature/nodelist/nodelist.c | 29 +-
src/feature/nodelist/routerinfo.c | 79 +++
src/feature/nodelist/routerinfo.h | 27 +
src/feature/nodelist/routerlist.c | 16 +-
src/feature/nodelist/routerparse.c | 33 +-
src/feature/nodelist/routerset.c | 6 +-
src/feature/nodelist/torcert.c | 37 ++
src/feature/nodelist/torcert.h | 6 +
src/feature/relay/dns.c | 19 +-
src/feature/relay/router.c | 866 ++-------------------------------
src/feature/relay/router.h | 51 +-
src/feature/relay/routerkeys.c | 683 +-------------------------
src/feature/relay/routerkeys.h | 41 --
src/feature/relay/routermode.c | 80 +++
src/feature/relay/routermode.h | 24 +
src/feature/relay/selftest.c | 301 ++++++++++++
src/feature/relay/selftest.h | 24 +
src/feature/rend/rendclient.c | 24 +-
src/feature/rend/rendservice.c | 35 +-
src/feature/stats/rephist.c | 4 +-
src/test/fuzz/fuzz_descriptor.c | 4 +-
src/test/test_config.c | 1 +
src/test/test_dir.c | 52 +-
src/test/test_routerkeys.c | 1 +
src/test/test_status.c | 1 +
75 files changed, 2398 insertions(+), 2058 deletions(-)
1
0

26 Sep '18
commit 9385b7ec5f6effce97ae26aa6cda08df5b90309b
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 15:18:19 2018 -0400
Rename dirauth/mode.h to dirauth/authmode.h
This is preparation for having a routermode.h as well
---
src/app/config/config.c | 2 +-
src/app/main/main.c | 2 +-
src/core/include.am | 2 +-
src/core/mainloop/mainloop.c | 2 +-
src/feature/dirauth/{mode.h => authmode.h} | 0
src/feature/dirauth/dirvote.c | 2 +-
src/feature/dirauth/shared_random.c | 2 +-
src/feature/dircache/dircache.c | 2 +-
src/feature/dirclient/dirclient.c | 2 +-
src/feature/nodelist/networkstatus.c | 2 +-
src/feature/nodelist/nodelist.c | 2 +-
src/feature/nodelist/routerlist.c | 2 +-
src/feature/relay/router.c | 2 +-
13 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 01b48e3c5..68139a997 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -144,7 +144,7 @@
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/recommend_pkg.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "core/or/connection_st.h"
#include "core/or/port_cfg_st.h"
diff --git a/src/app/main/main.c b/src/app/main/main.c
index d71e1c7bf..c6d779275 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -81,7 +81,7 @@
#include <event2/event.h>
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirauth/shared_random.h"
#include "core/or/or_connection_st.h"
diff --git a/src/core/include.am b/src/core/include.am
index 2369480be..5e6e95da1 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -246,12 +246,12 @@ noinst_HEADERS += \
src/feature/control/control.h \
src/feature/control/control_connection_st.h \
src/feature/control/fmt_serverstatus.h \
+ src/feature/dirauth/authmode.h \
src/feature/dirauth/bwauth.h \
src/feature/dirauth/dircollate.h \
src/feature/dirauth/dirvote.h \
src/feature/dirauth/guardfraction.h \
src/feature/dirauth/keypin.h \
- src/feature/dirauth/mode.h \
src/feature/dirauth/ns_detached_signatures_st.h \
src/feature/dirauth/reachability.h \
src/feature/dirauth/recommend_pkg.h \
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index 5e435ad98..105638ffa 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -102,7 +102,7 @@
#include <event2/event.h>
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "core/or/cell_st.h"
#include "core/or/entry_connection_st.h"
diff --git a/src/feature/dirauth/mode.h b/src/feature/dirauth/authmode.h
similarity index 100%
rename from src/feature/dirauth/mode.h
rename to src/feature/dirauth/authmode.h
diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index a1fe0d423..edb0ad2ae 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -34,7 +34,7 @@
#include "feature/dircommon/voting_schedule.h"
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirauth/shared_random_state.h"
#include "feature/nodelist/authority_cert_st.h"
diff --git a/src/feature/dirauth/shared_random.c b/src/feature/dirauth/shared_random.c
index 85ec82ac0..db4f9d328 100644
--- a/src/feature/dirauth/shared_random.c
+++ b/src/feature/dirauth/shared_random.c
@@ -102,7 +102,7 @@
#include "feature/dircommon/voting_schedule.h"
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/nodelist/authority_cert_st.h"
#include "feature/nodelist/networkstatus_st.h"
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index 7bfc53982..c58512814 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -11,7 +11,7 @@
#include "core/mainloop/connection.h"
#include "core/or/relay.h"
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirauth/process_descs.h"
#include "feature/dircache/conscache.h"
#include "feature/dircache/consdiffmgr.h"
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index 89bc19f84..bd6800c74 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -16,7 +16,7 @@
#include "feature/client/entrynodes.h"
#include "feature/control/control.h"
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirauth/shared_random.h"
#include "feature/dircache/dirserv.h"
#include "feature/dirclient/dirclient.h"
diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c
index c6a51aefc..2ce38e204 100644
--- a/src/feature/nodelist/networkstatus.c
+++ b/src/feature/nodelist/networkstatus.c
@@ -79,7 +79,7 @@
#include "feature/nodelist/fmt_routerstatus.h"
#include "feature/dirauth/dirvote.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirauth/shared_random.h"
#include "feature/dirauth/voteflags.h"
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index ce77d71c6..b5ded356b 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -69,7 +69,7 @@
#include <string.h>
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dirclient/dir_server_st.h"
#include "feature/nodelist/microdesc_st.h"
diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c
index 5c6a10477..afecaa4fb 100644
--- a/src/feature/nodelist/routerlist.c
+++ b/src/feature/nodelist/routerlist.c
@@ -68,7 +68,7 @@
#include "core/or/policies.h"
#include "feature/client/bridges.h"
#include "feature/control/control.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/dircommon/directory.h"
#include "feature/dirclient/dirclient.h"
#include "feature/dircache/dirserv.h"
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 480f23a10..3e19c7b61 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -44,7 +44,7 @@
#include "feature/client/transports.h"
#include "feature/nodelist/routerset.h"
-#include "feature/dirauth/mode.h"
+#include "feature/dirauth/authmode.h"
#include "feature/nodelist/authority_cert_st.h"
#include "core/or/crypt_path_st.h"
1
0

26 Sep '18
commit 8a350e088bf59355f5e2fa3a05fa545923d4e74d
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 15:10:11 2018 -0400
Move self-test functionality into its own file.
---
src/core/include.am | 2 +
src/core/mainloop/mainloop.c | 1 +
src/core/or/circuitbuild.c | 1 +
src/core/or/circuituse.c | 1 +
src/feature/control/control.c | 1 +
src/feature/dirclient/dirclient.c | 2 +-
src/feature/relay/router.c | 269 +---------------------------------
src/feature/relay/router.h | 9 +-
src/feature/relay/selftest.c | 299 ++++++++++++++++++++++++++++++++++++++
src/feature/relay/selftest.h | 24 +++
src/feature/stats/rephist.c | 1 +
11 files changed, 336 insertions(+), 274 deletions(-)
diff --git a/src/core/include.am b/src/core/include.am
index 954b3bb55..2369480be 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -105,6 +105,7 @@ LIBTOR_APP_A_SOURCES = \
src/feature/relay/onion_queue.c \
src/feature/relay/router.c \
src/feature/relay/routerkeys.c \
+ src/feature/relay/selftest.c \
src/feature/rend/rendcache.c \
src/feature/rend/rendclient.c \
src/feature/rend/rendcommon.c \
@@ -324,6 +325,7 @@ noinst_HEADERS += \
src/feature/relay/onion_queue.h \
src/feature/relay/router.h \
src/feature/relay/routerkeys.h \
+ src/feature/relay/selftest.h \
src/feature/rend/rend_authorized_client_st.h \
src/feature/rend/rend_encoded_v2_service_descriptor_st.h \
src/feature/rend/rend_intro_point_st.h \
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index 06d6de9a2..5e435ad98 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -92,6 +92,7 @@
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
+#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
#include "app/config/statefile.h"
#include "core/or/status.h"
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index 2f404d179..b77a88f5f 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -61,6 +61,7 @@
#include "feature/rend/rendcommon.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 7b1f31559..f5919de5c 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -55,6 +55,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
#include "lib/math/fp.h"
#include "lib/time/tvdiff.h"
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index f307101ed..c1fb76812 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -81,6 +81,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/routerlist.h"
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index 0f5f87031..89bc19f84 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -35,7 +35,7 @@
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
-#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendclient.h"
#include "feature/rend/rendcommon.h"
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 7f72c7f35..480f23a10 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/selftest.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/routerlist.h"
@@ -1169,68 +1170,6 @@ init_keys(void)
return 0; /* success */
}
-/* Keep track of whether we should upload our server descriptor,
- * and what type of server we are.
- */
-
-/** Whether we can reach our ORPort from the outside. */
-static int can_reach_or_port = 0;
-/** Whether we can reach our DirPort from the outside. */
-static int can_reach_dir_port = 0;
-
-/** Forget what we have learned about our reachability status. */
-void
-router_reset_reachability(void)
-{
- can_reach_or_port = can_reach_dir_port = 0;
-}
-
-/** Return 1 if we won't do reachability checks, because:
- * - AssumeReachable is set, or
- * - the network is disabled.
- * Otherwise, return 0.
- */
-static int
-router_reachability_checks_disabled(const or_options_t *options)
-{
- return options->AssumeReachable ||
- net_is_disabled();
-}
-
-/** Return 0 if we need to do an ORPort reachability check, because:
- * - no reachability check has been done yet, or
- * - we've initiated reachability checks, but none have succeeded.
- * Return 1 if we don't need to do an ORPort reachability check, because:
- * - we've seen a successful reachability check, or
- * - AssumeReachable is set, or
- * - the network is disabled.
- */
-int
-check_whether_orport_reachable(const or_options_t *options)
-{
- int reach_checks_disabled = router_reachability_checks_disabled(options);
- return reach_checks_disabled ||
- can_reach_or_port;
-}
-
-/** Return 0 if we need to do a DirPort reachability check, because:
- * - no reachability check has been done yet, or
- * - we've initiated reachability checks, but none have succeeded.
- * Return 1 if we don't need to do a DirPort reachability check, because:
- * - we've seen a successful reachability check, or
- * - there is no DirPort set, or
- * - AssumeReachable is set, or
- * - the network is disabled.
- */
-int
-check_whether_dirport_reachable(const or_options_t *options)
-{
- int reach_checks_disabled = router_reachability_checks_disabled(options) ||
- !options->DirPort_set;
- return reach_checks_disabled ||
- can_reach_dir_port;
-}
-
/** The lower threshold of remaining bandwidth required to advertise (or
* automatically provide) directory services */
/* XXX Should this be increased? */
@@ -1372,7 +1311,7 @@ decide_to_advertise_dir_impl(const or_options_t *options,
* advertise the fact that we have a DirPort open, else return the
* DirPort we want to advertise.
*/
-static int
+int
router_should_advertise_dirport(const or_options_t *options, uint16_t dir_port)
{
/* supports_tunnelled_dir_requests is not relevant, pass 0 */
@@ -1391,210 +1330,6 @@ router_should_advertise_begindir(const or_options_t *options,
supports_tunnelled_dir_requests);
}
-/** Allocate and return a new extend_info_t that can be used to build
- * a circuit to or through the router <b>r</b>. Uses the primary
- * address of the router, so should only be called on a server. */
-static extend_info_t *
-extend_info_from_router(const routerinfo_t *r)
-{
- crypto_pk_t *rsa_pubkey;
- extend_info_t *info;
- tor_addr_port_t ap;
- tor_assert(r);
-
- /* Make sure we don't need to check address reachability */
- tor_assert_nonfatal(router_skip_or_reachability(get_options(), 0));
-
- const ed25519_public_key_t *ed_id_key;
- if (r->cache_info.signing_key_cert)
- ed_id_key = &r->cache_info.signing_key_cert->signing_key;
- else
- ed_id_key = NULL;
-
- router_get_prim_orport(r, &ap);
- rsa_pubkey = router_get_rsa_onion_pkey(r->onion_pkey, r->onion_pkey_len);
- info = extend_info_new(r->nickname, r->cache_info.identity_digest,
- ed_id_key,
- rsa_pubkey, r->onion_curve25519_pkey,
- &ap.addr, ap.port);
- crypto_pk_free(rsa_pubkey);
- return info;
-}
-
-/**See if we currently believe our ORPort or DirPort to be
- * unreachable. If so, return 1 else return 0.
- */
-static int
-router_should_check_reachability(int test_or, int test_dir)
-{
- const routerinfo_t *me = router_get_my_routerinfo();
- const or_options_t *options = get_options();
-
- if (!me)
- return 0;
-
- if (routerset_contains_router(options->ExcludeNodes, me, -1) &&
- options->StrictNodes) {
- /* If we've excluded ourself, and StrictNodes is set, we can't test
- * ourself. */
- if (test_or || test_dir) {
-#define SELF_EXCLUDED_WARN_INTERVAL 3600
- static ratelim_t warning_limit=RATELIM_INIT(SELF_EXCLUDED_WARN_INTERVAL);
- log_fn_ratelim(&warning_limit, LOG_WARN, LD_CIRC,
- "Can't peform self-tests for this relay: we have "
- "listed ourself in ExcludeNodes, and StrictNodes is set. "
- "We cannot learn whether we are usable, and will not "
- "be able to advertise ourself.");
- }
- return 0;
- }
- return 1;
-}
-
-/** Some time has passed, or we just got new directory information.
- * See if we currently believe our ORPort or DirPort to be
- * unreachable. If so, launch a new test for it.
- *
- * For ORPort, we simply try making a circuit that ends at ourselves.
- * Success is noticed in onionskin_answer().
- *
- * For DirPort, we make a connection via Tor to our DirPort and ask
- * for our own server descriptor.
- * Success is noticed in connection_dir_client_reached_eof().
- */
-void
-router_do_reachability_checks(int test_or, int test_dir)
-{
- const routerinfo_t *me = router_get_my_routerinfo();
- const or_options_t *options = get_options();
- int orport_reachable = check_whether_orport_reachable(options);
- tor_addr_t addr;
-
- if (router_should_check_reachability(test_or, test_dir)) {
- if (test_or && (!orport_reachable || !circuit_enough_testing_circs())) {
- extend_info_t *ei = extend_info_from_router(me);
- /* XXX IPv6 self testing */
- log_info(LD_CIRC, "Testing %s of my ORPort: %s:%d.",
- !orport_reachable ? "reachability" : "bandwidth",
- fmt_addr32(me->addr), me->or_port);
- circuit_launch_by_extend_info(CIRCUIT_PURPOSE_TESTING, ei,
- CIRCLAUNCH_NEED_CAPACITY|CIRCLAUNCH_IS_INTERNAL);
- extend_info_free(ei);
- }
-
- /* XXX IPv6 self testing */
- tor_addr_from_ipv4h(&addr, me->addr);
- if (test_dir && !check_whether_dirport_reachable(options) &&
- !connection_get_by_type_addr_port_purpose(
- CONN_TYPE_DIR, &addr, me->dir_port,
- DIR_PURPOSE_FETCH_SERVERDESC)) {
- tor_addr_port_t my_orport, my_dirport;
- memcpy(&my_orport.addr, &addr, sizeof(addr));
- memcpy(&my_dirport.addr, &addr, sizeof(addr));
- my_orport.port = me->or_port;
- my_dirport.port = me->dir_port;
- /* ask myself, via tor, for my server descriptor. */
- directory_request_t *req =
- directory_request_new(DIR_PURPOSE_FETCH_SERVERDESC);
- directory_request_set_or_addr_port(req, &my_orport);
- directory_request_set_dir_addr_port(req, &my_dirport);
- directory_request_set_directory_id_digest(req,
- me->cache_info.identity_digest);
- // ask via an anon circuit, connecting to our dirport.
- directory_request_set_indirection(req, DIRIND_ANON_DIRPORT);
- directory_request_set_resource(req, "authority.z");
- directory_initiate_request(req);
- directory_request_free(req);
- }
- }
-}
-
-/** Annotate that we found our ORPort reachable. */
-void
-router_orport_found_reachable(void)
-{
- const routerinfo_t *me = router_get_my_routerinfo();
- const or_options_t *options = get_options();
- if (!can_reach_or_port && me) {
- char *address = tor_dup_ip(me->addr);
- log_notice(LD_OR,"Self-testing indicates your ORPort is reachable from "
- "the outside. Excellent.%s",
- options->PublishServerDescriptor_ != NO_DIRINFO
- && check_whether_dirport_reachable(options) ?
- " Publishing server descriptor." : "");
- can_reach_or_port = 1;
- mark_my_descriptor_dirty("ORPort found reachable");
- /* This is a significant enough change to upload immediately,
- * at least in a test network */
- if (options->TestingTorNetwork == 1) {
- reschedule_descriptor_update_check();
- }
- control_event_server_status(LOG_NOTICE,
- "REACHABILITY_SUCCEEDED ORADDRESS=%s:%d",
- address, me->or_port);
- tor_free(address);
- }
-}
-
-/** Annotate that we found our DirPort reachable. */
-void
-router_dirport_found_reachable(void)
-{
- const routerinfo_t *me = router_get_my_routerinfo();
- const or_options_t *options = get_options();
- if (!can_reach_dir_port && me) {
- char *address = tor_dup_ip(me->addr);
- log_notice(LD_DIRSERV,"Self-testing indicates your DirPort is reachable "
- "from the outside. Excellent.%s",
- options->PublishServerDescriptor_ != NO_DIRINFO
- && check_whether_orport_reachable(options) ?
- " Publishing server descriptor." : "");
- can_reach_dir_port = 1;
- if (router_should_advertise_dirport(options, me->dir_port)) {
- mark_my_descriptor_dirty("DirPort found reachable");
- /* This is a significant enough change to upload immediately,
- * at least in a test network */
- if (options->TestingTorNetwork == 1) {
- reschedule_descriptor_update_check();
- }
- }
- control_event_server_status(LOG_NOTICE,
- "REACHABILITY_SUCCEEDED DIRADDRESS=%s:%d",
- address, me->dir_port);
- tor_free(address);
- }
-}
-
-/** We have enough testing circuits open. Send a bunch of "drop"
- * cells down each of them, to exercise our bandwidth. */
-void
-router_perform_bandwidth_test(int num_circs, time_t now)
-{
- int num_cells = (int)(get_options()->BandwidthRate * 10 /
- CELL_MAX_NETWORK_SIZE);
- int max_cells = num_cells < CIRCWINDOW_START ?
- num_cells : CIRCWINDOW_START;
- int cells_per_circuit = max_cells / num_circs;
- origin_circuit_t *circ = NULL;
-
- log_notice(LD_OR,"Performing bandwidth self-test...done.");
- while ((circ = circuit_get_next_by_pk_and_purpose(circ, NULL,
- CIRCUIT_PURPOSE_TESTING))) {
- /* dump cells_per_circuit drop cells onto this circ */
- int i = cells_per_circuit;
- if (circ->base_.state != CIRCUIT_STATE_OPEN)
- continue;
- circ->base_.timestamp_dirty = now;
- while (i-- > 0) {
- if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
- RELAY_COMMAND_DROP,
- NULL, 0, circ->cpath->prev)<0) {
- return; /* stop if error */
- }
- }
- }
-}
-
/** Return true iff our network is in some sense disabled or shutting down:
* either we're hibernating, entering hibernation, or the network is turned
* off with DisableNetwork. */
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index e6a163973..52c4ac0bd 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -56,13 +56,7 @@ int router_initialize_tls_context(void);
int init_keys(void);
int init_keys_client(void);
-int check_whether_orport_reachable(const or_options_t *options);
-int check_whether_dirport_reachable(const or_options_t *options);
int dir_server_mode(const or_options_t *options);
-void router_do_reachability_checks(int test_or, int test_dir);
-void router_orport_found_reachable(void);
-void router_dirport_found_reachable(void);
-void router_perform_bandwidth_test(int num_circs, time_t now);
int net_is_disabled(void);
int net_is_completely_disabled(void);
@@ -81,6 +75,9 @@ uint16_t router_get_advertised_or_port_by_af(const or_options_t *options,
uint16_t router_get_advertised_dir_port(const or_options_t *options,
uint16_t dirport);
+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));
diff --git a/src/feature/relay/selftest.c b/src/feature/relay/selftest.c
new file mode 100644
index 000000000..789870d29
--- /dev/null
+++ b/src/feature/relay/selftest.c
@@ -0,0 +1,299 @@
+/* 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 selftest.c
+ * \brief Relay self-testing
+ *
+ * Relays need to make sure that their own ports are reasonable, and estimate
+ * their own bandwidth, before publishing.
+ */
+
+#define SELFTEST_PRIVATE
+
+#include "core/or/or.h"
+
+#include "app/config/config.h"
+#include "core/mainloop/connection.h"
+#include "core/mainloop/mainloop.h"
+#include "core/or/circuitbuild.h"
+#include "core/or/circuitlist.h"
+#include "core/or/circuituse.h"
+#include "core/or/crypt_path_st.h"
+#include "core/or/origin_circuit_st.h"
+#include "core/or/relay.h"
+#include "feature/control/control.h"
+#include "feature/dirclient/dirclient.h"
+#include "feature/dircommon/directory.h"
+#include "feature/nodelist/authority_cert_st.h"
+#include "feature/nodelist/routerinfo_st.h"
+#include "feature/nodelist/routerlist.h" // but...
+#include "feature/nodelist/routerset.h"
+#include "feature/nodelist/torcert.h"
+#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
+
+/** Whether we can reach our ORPort from the outside. */
+static int can_reach_or_port = 0;
+/** Whether we can reach our DirPort from the outside. */
+static int can_reach_dir_port = 0;
+
+/** Forget what we have learned about our reachability status. */
+void
+router_reset_reachability(void)
+{
+ can_reach_or_port = can_reach_dir_port = 0;
+}
+
+/** Return 1 if we won't do reachability checks, because:
+ * - AssumeReachable is set, or
+ * - the network is disabled.
+ * Otherwise, return 0.
+ */
+static int
+router_reachability_checks_disabled(const or_options_t *options)
+{
+ return options->AssumeReachable ||
+ net_is_disabled();
+}
+
+/** Return 0 if we need to do an ORPort reachability check, because:
+ * - no reachability check has been done yet, or
+ * - we've initiated reachability checks, but none have succeeded.
+ * Return 1 if we don't need to do an ORPort reachability check, because:
+ * - we've seen a successful reachability check, or
+ * - AssumeReachable is set, or
+ * - the network is disabled.
+ */
+int
+check_whether_orport_reachable(const or_options_t *options)
+{
+ int reach_checks_disabled = router_reachability_checks_disabled(options);
+ return reach_checks_disabled ||
+ can_reach_or_port;
+}
+
+/** Return 0 if we need to do a DirPort reachability check, because:
+ * - no reachability check has been done yet, or
+ * - we've initiated reachability checks, but none have succeeded.
+ * Return 1 if we don't need to do a DirPort reachability check, because:
+ * - we've seen a successful reachability check, or
+ * - there is no DirPort set, or
+ * - AssumeReachable is set, or
+ * - the network is disabled.
+ */
+int
+check_whether_dirport_reachable(const or_options_t *options)
+{
+ int reach_checks_disabled = router_reachability_checks_disabled(options) ||
+ !options->DirPort_set;
+ return reach_checks_disabled ||
+ can_reach_dir_port;
+}
+
+/** See if we currently believe our ORPort or DirPort to be
+ * unreachable. If so, return 1 else return 0.
+ */
+static int
+router_should_check_reachability(int test_or, int test_dir)
+{
+ const routerinfo_t *me = router_get_my_routerinfo();
+ const or_options_t *options = get_options();
+
+ if (!me)
+ return 0;
+
+ if (routerset_contains_router(options->ExcludeNodes, me, -1) &&
+ options->StrictNodes) {
+ /* If we've excluded ourself, and StrictNodes is set, we can't test
+ * ourself. */
+ if (test_or || test_dir) {
+#define SELF_EXCLUDED_WARN_INTERVAL 3600
+ static ratelim_t warning_limit=RATELIM_INIT(SELF_EXCLUDED_WARN_INTERVAL);
+ log_fn_ratelim(&warning_limit, LOG_WARN, LD_CIRC,
+ "Can't peform self-tests for this relay: we have "
+ "listed ourself in ExcludeNodes, and StrictNodes is set. "
+ "We cannot learn whether we are usable, and will not "
+ "be able to advertise ourself.");
+ }
+ return 0;
+ }
+ return 1;
+}
+
+/** Allocate and return a new extend_info_t that can be used to build
+ * a circuit to or through the router <b>r</b>. Uses the primary
+ * address of the router, so should only be called on a server. */
+static extend_info_t *
+extend_info_from_router(const routerinfo_t *r)
+{
+ crypto_pk_t *rsa_pubkey;
+ extend_info_t *info;
+ tor_addr_port_t ap;
+ tor_assert(r);
+
+ /* Make sure we don't need to check address reachability */
+ tor_assert_nonfatal(router_skip_or_reachability(get_options(), 0));
+
+ const ed25519_public_key_t *ed_id_key;
+ if (r->cache_info.signing_key_cert)
+ ed_id_key = &r->cache_info.signing_key_cert->signing_key;
+ else
+ ed_id_key = NULL;
+
+ router_get_prim_orport(r, &ap);
+ rsa_pubkey = router_get_rsa_onion_pkey(r->onion_pkey, r->onion_pkey_len);
+ info = extend_info_new(r->nickname, r->cache_info.identity_digest,
+ ed_id_key,
+ rsa_pubkey, r->onion_curve25519_pkey,
+ &ap.addr, ap.port);
+ crypto_pk_free(rsa_pubkey);
+ return info;
+}
+
+/** Some time has passed, or we just got new directory information.
+ * See if we currently believe our ORPort or DirPort to be
+ * unreachable. If so, launch a new test for it.
+ *
+ * For ORPort, we simply try making a circuit that ends at ourselves.
+ * Success is noticed in onionskin_answer().
+ *
+ * For DirPort, we make a connection via Tor to our DirPort and ask
+ * for our own server descriptor.
+ * Success is noticed in connection_dir_client_reached_eof().
+ */
+void
+router_do_reachability_checks(int test_or, int test_dir)
+{
+ const routerinfo_t *me = router_get_my_routerinfo();
+ const or_options_t *options = get_options();
+ int orport_reachable = check_whether_orport_reachable(options);
+ tor_addr_t addr;
+
+ if (router_should_check_reachability(test_or, test_dir)) {
+ if (test_or && (!orport_reachable || !circuit_enough_testing_circs())) {
+ extend_info_t *ei = extend_info_from_router(me);
+ /* XXX IPv6 self testing */
+ log_info(LD_CIRC, "Testing %s of my ORPort: %s:%d.",
+ !orport_reachable ? "reachability" : "bandwidth",
+ fmt_addr32(me->addr), me->or_port);
+ circuit_launch_by_extend_info(CIRCUIT_PURPOSE_TESTING, ei,
+ CIRCLAUNCH_NEED_CAPACITY|CIRCLAUNCH_IS_INTERNAL);
+ extend_info_free(ei);
+ }
+
+ /* XXX IPv6 self testing */
+ tor_addr_from_ipv4h(&addr, me->addr);
+ if (test_dir && !check_whether_dirport_reachable(options) &&
+ !connection_get_by_type_addr_port_purpose(
+ CONN_TYPE_DIR, &addr, me->dir_port,
+ DIR_PURPOSE_FETCH_SERVERDESC)) {
+ tor_addr_port_t my_orport, my_dirport;
+ memcpy(&my_orport.addr, &addr, sizeof(addr));
+ memcpy(&my_dirport.addr, &addr, sizeof(addr));
+ my_orport.port = me->or_port;
+ my_dirport.port = me->dir_port;
+ /* ask myself, via tor, for my server descriptor. */
+ directory_request_t *req =
+ directory_request_new(DIR_PURPOSE_FETCH_SERVERDESC);
+ directory_request_set_or_addr_port(req, &my_orport);
+ directory_request_set_dir_addr_port(req, &my_dirport);
+ directory_request_set_directory_id_digest(req,
+ me->cache_info.identity_digest);
+ // ask via an anon circuit, connecting to our dirport.
+ directory_request_set_indirection(req, DIRIND_ANON_DIRPORT);
+ directory_request_set_resource(req, "authority.z");
+ directory_initiate_request(req);
+ directory_request_free(req);
+ }
+ }
+}
+
+/** Annotate that we found our ORPort reachable. */
+void
+router_orport_found_reachable(void)
+{
+ const routerinfo_t *me = router_get_my_routerinfo();
+ const or_options_t *options = get_options();
+ if (!can_reach_or_port && me) {
+ char *address = tor_dup_ip(me->addr);
+ log_notice(LD_OR,"Self-testing indicates your ORPort is reachable from "
+ "the outside. Excellent.%s",
+ options->PublishServerDescriptor_ != NO_DIRINFO
+ && check_whether_dirport_reachable(options) ?
+ " Publishing server descriptor." : "");
+ can_reach_or_port = 1;
+ mark_my_descriptor_dirty("ORPort found reachable");
+ /* This is a significant enough change to upload immediately,
+ * at least in a test network */
+ if (options->TestingTorNetwork == 1) {
+ reschedule_descriptor_update_check();
+ }
+ control_event_server_status(LOG_NOTICE,
+ "REACHABILITY_SUCCEEDED ORADDRESS=%s:%d",
+ address, me->or_port);
+ tor_free(address);
+ }
+}
+
+/** Annotate that we found our DirPort reachable. */
+void
+router_dirport_found_reachable(void)
+{
+ const routerinfo_t *me = router_get_my_routerinfo();
+ const or_options_t *options = get_options();
+ if (!can_reach_dir_port && me) {
+ char *address = tor_dup_ip(me->addr);
+ log_notice(LD_DIRSERV,"Self-testing indicates your DirPort is reachable "
+ "from the outside. Excellent.%s",
+ options->PublishServerDescriptor_ != NO_DIRINFO
+ && check_whether_orport_reachable(options) ?
+ " Publishing server descriptor." : "");
+ can_reach_dir_port = 1;
+ if (router_should_advertise_dirport(options, me->dir_port)) {
+ mark_my_descriptor_dirty("DirPort found reachable");
+ /* This is a significant enough change to upload immediately,
+ * at least in a test network */
+ if (options->TestingTorNetwork == 1) {
+ reschedule_descriptor_update_check();
+ }
+ }
+ control_event_server_status(LOG_NOTICE,
+ "REACHABILITY_SUCCEEDED DIRADDRESS=%s:%d",
+ address, me->dir_port);
+ tor_free(address);
+ }
+}
+
+/** We have enough testing circuits open. Send a bunch of "drop"
+ * cells down each of them, to exercise our bandwidth. */
+void
+router_perform_bandwidth_test(int num_circs, time_t now)
+{
+ int num_cells = (int)(get_options()->BandwidthRate * 10 /
+ CELL_MAX_NETWORK_SIZE);
+ int max_cells = num_cells < CIRCWINDOW_START ?
+ num_cells : CIRCWINDOW_START;
+ int cells_per_circuit = max_cells / num_circs;
+ origin_circuit_t *circ = NULL;
+
+ log_notice(LD_OR,"Performing bandwidth self-test...done.");
+ while ((circ = circuit_get_next_by_pk_and_purpose(circ, NULL,
+ CIRCUIT_PURPOSE_TESTING))) {
+ /* dump cells_per_circuit drop cells onto this circ */
+ int i = cells_per_circuit;
+ if (circ->base_.state != CIRCUIT_STATE_OPEN)
+ continue;
+ circ->base_.timestamp_dirty = now;
+ while (i-- > 0) {
+ if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
+ RELAY_COMMAND_DROP,
+ NULL, 0, circ->cpath->prev)<0) {
+ return; /* stop if error */
+ }
+ }
+ }
+}
diff --git a/src/feature/relay/selftest.h b/src/feature/relay/selftest.h
new file mode 100644
index 000000000..26034c9e8
--- /dev/null
+++ b/src/feature/relay/selftest.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 selftest.h
+ * \brief Header file for selftest.c.
+ **/
+
+#ifndef TOR_SELFTEST_H
+#define TOR_SELFTEST_H
+
+struct or_options_t;
+int check_whether_orport_reachable(const struct or_options_t *options);
+int check_whether_dirport_reachable(const struct or_options_t *options);
+
+void router_do_reachability_checks(int test_or, int test_dir);
+void router_orport_found_reachable(void);
+void router_dirport_found_reachable(void);
+void router_perform_bandwidth_test(int num_circs, time_t now);
+
+#endif
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c
index a2dbb0ff1..24c73554b 100644
--- a/src/feature/stats/rephist.c
+++ b/src/feature/stats/rephist.c
@@ -84,6 +84,7 @@
#include "feature/nodelist/nodelist.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
#include "ht.h"
#include "core/or/channelpadding.h"
1
0

[tor/master] Extract all the "am I a server" functions from router.c
by nickm@torproject.org 26 Sep '18
by nickm@torproject.org 26 Sep '18
26 Sep '18
commit fcd0f76134c2e1e420b1379906955d41e8a6df66
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Sep 25 16:00:50 2018 -0400
Extract all the "am I a server" functions from router.c
---
src/app/config/config.c | 1 +
src/app/config/statefile.c | 1 +
src/app/main/main.c | 1 +
src/core/include.am | 2 +
src/core/mainloop/connection.c | 1 +
src/core/mainloop/mainloop.c | 1 +
src/core/or/channelpadding.c | 1 +
src/core/or/channeltls.c | 1 +
src/core/or/circuitbuild.c | 1 +
src/core/or/circuituse.c | 1 +
src/core/or/command.c | 1 +
src/core/or/connection_edge.c | 1 +
src/core/or/connection_or.c | 1 +
src/core/or/dos.c | 2 +-
src/core/or/policies.c | 1 +
src/core/or/status.c | 1 +
src/feature/control/control.c | 1 +
src/feature/dircache/dircache.c | 2 +-
src/feature/dircache/dirserv.c | 1 +
src/feature/dirclient/dirclient.c | 1 +
src/feature/dirclient/dlstatus.c | 2 +-
src/feature/nodelist/authcert.c | 2 +-
src/feature/nodelist/networkstatus.c | 2 +-
src/feature/nodelist/node_select.c | 1 +
src/feature/nodelist/routerlist.c | 2 +-
src/feature/relay/dns.c | 1 +
src/feature/relay/router.c | 70 +------------------------------
src/feature/relay/router.h | 7 +---
src/feature/relay/routerkeys.c | 1 +
src/feature/relay/routermode.c | 80 ++++++++++++++++++++++++++++++++++++
src/feature/relay/routermode.h | 24 +++++++++++
src/feature/stats/rephist.c | 2 +-
src/test/test_config.c | 1 +
src/test/test_dir.c | 1 +
src/test/test_status.c | 1 +
35 files changed, 139 insertions(+), 81 deletions(-)
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 68139a997..65899b640 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -106,6 +106,7 @@
#include "feature/hs/hs_config.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "lib/sandbox/sandbox.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/routerset.h"
diff --git a/src/app/config/statefile.c b/src/app/config/statefile.c
index 208189db4..510b8964b 100644
--- a/src/app/config/statefile.c
+++ b/src/app/config/statefile.c
@@ -40,6 +40,7 @@
#include "feature/hibernate/hibernate.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "lib/sandbox/sandbox.h"
#include "app/config/statefile.h"
#include "lib/encoding/confline.h"
diff --git a/src/app/main/main.c b/src/app/main/main.c
index c6d779275..6c7312f67 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -35,6 +35,7 @@
#include "feature/dirauth/bwauth.h"
#include "feature/dirauth/process_descs.h"
#include "feature/relay/dns.h"
+#include "feature/relay/routermode.h"
#include "feature/client/entrynodes.h"
#include "feature/stats/geoip.h"
#include "feature/hibernate/hibernate.h"
diff --git a/src/core/include.am b/src/core/include.am
index abbf89f69..ae37bef99 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -105,6 +105,7 @@ LIBTOR_APP_A_SOURCES = \
src/feature/relay/onion_queue.c \
src/feature/relay/router.c \
src/feature/relay/routerkeys.c \
+ src/feature/relay/routermode.c \
src/feature/relay/selftest.c \
src/feature/rend/rendcache.c \
src/feature/rend/rendclient.c \
@@ -326,6 +327,7 @@ noinst_HEADERS += \
src/feature/relay/onion_queue.h \
src/feature/relay/router.h \
src/feature/relay/routerkeys.h \
+ src/feature/relay/routermode.h \
src/feature/relay/selftest.h \
src/feature/rend/rend_authorized_client_st.h \
src/feature/rend/rend_encoded_v2_service_descriptor_st.h \
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index b858b94cd..699e7f710 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -81,6 +81,7 @@
#include "feature/dircommon/directory.h"
#include "feature/dircache/dirserv.h"
#include "feature/relay/dns.h"
+#include "feature/relay/routermode.h"
#include "feature/client/dnsserv.h"
#include "core/or/dos.h"
#include "feature/client/entrynodes.h"
diff --git a/src/core/mainloop/mainloop.c b/src/core/mainloop/mainloop.c
index 6d60b779b..fb405817d 100644
--- a/src/core/mainloop/mainloop.c
+++ b/src/core/mainloop/mainloop.c
@@ -92,6 +92,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/routerkeys.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
diff --git a/src/core/or/channelpadding.c b/src/core/or/channelpadding.c
index 6a38d13e3..db34f0f02 100644
--- a/src/core/or/channelpadding.c
+++ b/src/core/or/channelpadding.c
@@ -20,6 +20,7 @@
#include "core/mainloop/mainloop.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "lib/time/compat_time.h"
#include "feature/rend/rendservice.h"
#include "lib/evloop/timers.h"
diff --git a/src/core/or/channeltls.c b/src/core/or/channeltls.c
index c81a00b49..883acacf3 100644
--- a/src/core/or/channeltls.c
+++ b/src/core/or/channeltls.c
@@ -53,6 +53,7 @@
#include "core/or/relay.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/dirlist.h"
#include "core/or/scheduler.h"
#include "feature/nodelist/torcert.h"
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index b77a88f5f..f4e0776be 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -61,6 +61,7 @@
#include "feature/rend/rendcommon.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/node_select.h"
#include "feature/nodelist/routerlist.h"
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index f5919de5c..34b51a502 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -55,6 +55,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
#include "lib/math/fp.h"
diff --git a/src/core/or/command.c b/src/core/or/command.c
index f93eb8d85..9e19d28c7 100644
--- a/src/core/or/command.c
+++ b/src/core/or/command.c
@@ -55,6 +55,7 @@
#include "feature/stats/rephist.h"
#include "core/or/relay.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/routerlist.h"
#include "core/or/cell_st.h"
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index daf978b99..6dc0814b1 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -93,6 +93,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "core/or/circuitbuild.h"
diff --git a/src/core/or/connection_or.c b/src/core/or/connection_or.c
index 7902b6c59..4a724a24d 100644
--- a/src/core/or/connection_or.c
+++ b/src/core/or/connection_or.c
@@ -56,6 +56,7 @@
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/ext_orport.h"
diff --git a/src/core/or/dos.c b/src/core/or/dos.c
index a75c2070d..c59e2f636 100644
--- a/src/core/or/dos.c
+++ b/src/core/or/dos.c
@@ -19,7 +19,7 @@
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "core/or/dos.h"
diff --git a/src/core/or/policies.c b/src/core/or/policies.c
index 3443a1710..fc359627b 100644
--- a/src/core/or/policies.c
+++ b/src/core/or/policies.c
@@ -25,6 +25,7 @@
#include "feature/nodelist/nodelist.h"
#include "core/or/policies.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/routerparse.h"
#include "feature/stats/geoip.h"
#include "ht.h"
diff --git a/src/core/or/status.c b/src/core/or/status.c
index 45b8217d9..d8a9da0a5 100644
--- a/src/core/or/status.c
+++ b/src/core/or/status.c
@@ -21,6 +21,7 @@
#include "feature/nodelist/nodelist.h"
#include "core/or/relay.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "core/or/circuitlist.h"
#include "core/mainloop/mainloop.h"
#include "feature/stats/rephist.h"
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index c1fb76812..43ec0bd8b 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -81,6 +81,7 @@
#include "feature/rend/rendservice.h"
#include "feature/stats/rephist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index c58512814..76bde0b78 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -23,7 +23,7 @@
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/routerlist.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/rend/rendcache.h"
#include "feature/stats/geoip.h"
#include "feature/stats/rephist.h"
diff --git a/src/feature/dircache/dirserv.c b/src/feature/dircache/dirserv.c
index 65c3d6d91..4fa3cd7f9 100644
--- a/src/feature/dircache/dirserv.c
+++ b/src/feature/dircache/dirserv.c
@@ -15,6 +15,7 @@
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/stats/rephist.h"
#include "feature/dircache/cached_dir_st.h"
diff --git a/src/feature/dirclient/dirclient.c b/src/feature/dirclient/dirclient.c
index bd6800c74..16d2e03b4 100644
--- a/src/feature/dirclient/dirclient.c
+++ b/src/feature/dirclient/dirclient.c
@@ -35,6 +35,7 @@
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendclient.h"
diff --git a/src/feature/dirclient/dlstatus.c b/src/feature/dirclient/dlstatus.c
index 017281e00..aea17bdac 100644
--- a/src/feature/dirclient/dlstatus.c
+++ b/src/feature/dirclient/dlstatus.c
@@ -11,7 +11,7 @@
#include "feature/client/entrynodes.h"
#include "feature/dirclient/dlstatus.h"
#include "feature/nodelist/networkstatus.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "feature/dirclient/download_status_st.h"
diff --git a/src/feature/nodelist/authcert.c b/src/feature/nodelist/authcert.c
index 665105e60..2624ed5ee 100644
--- a/src/feature/nodelist/authcert.c
+++ b/src/feature/nodelist/authcert.c
@@ -35,7 +35,7 @@
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerparse.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "core/or/connection_st.h"
#include "feature/dirclient/dir_server_st.h"
diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c
index 2ce38e204..40457ef68 100644
--- a/src/feature/nodelist/networkstatus.c
+++ b/src/feature/nodelist/networkstatus.c
@@ -65,7 +65,7 @@
#include "feature/nodelist/nodelist.h"
#include "core/or/protover.h"
#include "core/or/relay.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/node_select.h"
diff --git a/src/feature/nodelist/node_select.c b/src/feature/nodelist/node_select.c
index aab0bbe9f..6d58705cc 100644
--- a/src/feature/nodelist/node_select.c
+++ b/src/feature/nodelist/node_select.c
@@ -28,6 +28,7 @@
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/math/fp.h"
diff --git a/src/feature/nodelist/routerlist.c b/src/feature/nodelist/routerlist.c
index afecaa4fb..2bd6e5c6f 100644
--- a/src/feature/nodelist/routerlist.c
+++ b/src/feature/nodelist/routerlist.c
@@ -85,7 +85,7 @@
#include "feature/nodelist/routerparse.h"
#include "feature/nodelist/routerset.h"
#include "feature/nodelist/torcert.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/crypt_ops/crypto_rand.h"
diff --git a/src/feature/relay/dns.c b/src/feature/relay/dns.c
index 6e9be5e2e..52488ff94 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 cc5c424fe..e145a8e41 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 7b33069aa..5e342cc49 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 c13359795..2499d7c8f 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 000000000..3f87cda50
--- /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 000000000..1442d706d
--- /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) */
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c
index 210576b9e..fa4bd0ba4 100644
--- a/src/feature/stats/rephist.c
+++ b/src/feature/stats/rephist.c
@@ -83,7 +83,7 @@
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/stats/rephist.h"
-#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/nodelist/routerlist.h"
#include "ht.h"
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 4dc1b8c0e..77c0d248c 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -38,6 +38,7 @@
#include "feature/rend/rendclient.h"
#include "feature/rend/rendservice.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/routerset.h"
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 686b03949..58070766a 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -51,6 +51,7 @@
#include "feature/nodelist/networkstatus.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
+#include "feature/relay/routermode.h"
#include "feature/nodelist/authcert.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/node_select.h"
diff --git a/src/test/test_status.c b/src/test/test_status.c
index 46dbd9dcd..3ceba77a8 100644
--- a/src/test/test_status.c
+++ b/src/test/test_status.c
@@ -21,6 +21,7 @@
#include "feature/stats/rephist.h"
#include "core/or/relay.h"
#include "feature/relay/router.h"
+#include "feature/relay/routermode.h"
#include "core/mainloop/mainloop.h"
#include "feature/nodelist/nodelist.h"
#include "app/config/statefile.h"
1
0