In the first commit, why not move this initialization into the NetPermissions
class, where it makes sense to hold this logic.
0diff --git a/src/net.cpp b/src/net.cpp
1index 16771c8c428..64a1c9c30a7 100644
2--- a/src/net.cpp
3+++ b/src/net.cpp
4@@ -328,16 +328,6 @@ bool IsLocal(const CService& addr)
5 return mapLocalHost.count(addr) > 0;
6 }
7
8-static void InitializePermissionFlags(NetPermissionFlags& flags) {
9- if (NetPermissions::HasFlag(flags, NetPermissionFlags::Implicit)) {
10- NetPermissions::ClearFlag(flags, NetPermissionFlags::Implicit);
11- if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
12- if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
13- NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
14- NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
15- }
16-}
17-
18 CNode* CConnman::FindNode(const CNetAddr& ip)
19 {
20 LOCK(m_nodes_mutex);
21@@ -1744,7 +1734,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
22 int nInbound = 0;
23
24 AddWhitelistPermissionFlags(permission_flags, addr);
25- InitializePermissionFlags(permission_flags);
26+ NetPermissions::Initialize(permission_flags);
27
28 {
29 LOCK(m_nodes_mutex);
30diff --git a/src/net.h b/src/net.h
31index 36c6065b192..6c1672e7599 100644
32--- a/src/net.h
33+++ b/src/net.h
34@@ -53,11 +53,6 @@ class CNode;
35 class CScheduler;
36 struct bilingual_str;
37
38-/** Default for -whitelistrelay. */
39-static const bool DEFAULT_WHITELISTRELAY = true;
40-/** Default for -whitelistforcerelay. */
41-static const bool DEFAULT_WHITELISTFORCERELAY = false;
42-
43 /** Time after which to disconnect, after waiting for a ping response (or inactivity). */
44 static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
45 /** Run the feeler connection loop once every 2 minutes. **/
46diff --git a/src/net_permissions.cpp b/src/net_permissions.cpp
47index a134a552647..3ed230af0c2 100644
48--- a/src/net_permissions.cpp
49+++ b/src/net_permissions.cpp
50@@ -2,6 +2,7 @@
51 // Distributed under the MIT software license, see the accompanying
52 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
53
54+#include <common/args.h>
55 #include <common/system.h>
56 #include <net_permissions.h>
57 #include <netbase.h>
58@@ -18,6 +19,21 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
59 "addr (responses to GETADDR avoid hitting the cache and contain random records with the most up-to-date info)"
60 };
61
62+void NetPermissions::Initialize(NetPermissionFlags& flags)
63+{
64+ if (HasFlag(flags, NetPermissionFlags::Implicit)) {
65+ ClearFlag(flags, NetPermissionFlags::Implicit);
66+ if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
67+ AddFlag(flags, NetPermissionFlags::ForceRelay);
68+ }
69+ if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) {
70+ AddFlag(flags, NetPermissionFlags::Relay);
71+ }
72+ AddFlag(flags, NetPermissionFlags::Mempool);
73+ AddFlag(flags, NetPermissionFlags::NoBan);
74+ };
75+}
76+
77 namespace {
78
79 // Parse the following format: "perm1,perm2@xxxxxx"
80diff --git a/src/net_permissions.h b/src/net_permissions.h
81index b7f3bffe1c6..c82c5f0e6e5 100644
82--- a/src/net_permissions.h
83+++ b/src/net_permissions.h
84@@ -15,6 +15,11 @@ struct bilingual_str;
85
86 extern const std::vector<std::string> NET_PERMISSIONS_DOC;
87
88+/** Default for -whitelistrelay. */
89+constexpr bool DEFAULT_WHITELISTRELAY = true;
90+/** Default for -whitelistforcerelay. */
91+constexpr bool DEFAULT_WHITELISTFORCERELAY = false;
92+
93 enum class NetPermissionFlags : uint32_t {
94 None = 0,
95 // Can query bloomfilter even if -peerbloomfilters is false
96@@ -71,6 +76,7 @@ public:
97 using t = typename std::underlying_type<NetPermissionFlags>::type;
98 flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
99 }
100+ static void Initialize(NetPermissionFlags& flags);
101 };