In the first commit, why not move this initialization into the NetPermissions class, where it makes sense to hold this logic.
<details><summary>suggested diff</summary><p>
diff --git a/src/net.cpp b/src/net.cpp
index 16771c8c428..64a1c9c30a7 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -328,16 +328,6 @@ bool IsLocal(const CService& addr)
return mapLocalHost.count(addr) > 0;
}
-static void InitializePermissionFlags(NetPermissionFlags& flags) {
- if (NetPermissions::HasFlag(flags, NetPermissionFlags::Implicit)) {
- NetPermissions::ClearFlag(flags, NetPermissionFlags::Implicit);
- if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
- if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
- NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
- NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
- }
-}
-
CNode* CConnman::FindNode(const CNetAddr& ip)
{
LOCK(m_nodes_mutex);
@@ -1744,7 +1734,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
int nInbound = 0;
AddWhitelistPermissionFlags(permission_flags, addr);
- InitializePermissionFlags(permission_flags);
+ NetPermissions::Initialize(permission_flags);
{
LOCK(m_nodes_mutex);
diff --git a/src/net.h b/src/net.h
index 36c6065b192..6c1672e7599 100644
--- a/src/net.h
+++ b/src/net.h
@@ -53,11 +53,6 @@ class CNode;
class CScheduler;
struct bilingual_str;
-/** Default for -whitelistrelay. */
-static const bool DEFAULT_WHITELISTRELAY = true;
-/** Default for -whitelistforcerelay. */
-static const bool DEFAULT_WHITELISTFORCERELAY = false;
-
/** Time after which to disconnect, after waiting for a ping response (or inactivity). */
static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
/** Run the feeler connection loop once every 2 minutes. **/
diff --git a/src/net_permissions.cpp b/src/net_permissions.cpp
index a134a552647..3ed230af0c2 100644
--- a/src/net_permissions.cpp
+++ b/src/net_permissions.cpp
@@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <common/args.h>
#include <common/system.h>
#include <net_permissions.h>
#include <netbase.h>
@@ -18,6 +19,21 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
"addr (responses to GETADDR avoid hitting the cache and contain random records with the most up-to-date info)"
};
+void NetPermissions::Initialize(NetPermissionFlags& flags)
+{
+ if (HasFlag(flags, NetPermissionFlags::Implicit)) {
+ ClearFlag(flags, NetPermissionFlags::Implicit);
+ if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
+ AddFlag(flags, NetPermissionFlags::ForceRelay);
+ }
+ if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) {
+ AddFlag(flags, NetPermissionFlags::Relay);
+ }
+ AddFlag(flags, NetPermissionFlags::Mempool);
+ AddFlag(flags, NetPermissionFlags::NoBan);
+ };
+}
+
namespace {
// Parse the following format: "perm1,perm2@xxxxxx"
diff --git a/src/net_permissions.h b/src/net_permissions.h
index b7f3bffe1c6..c82c5f0e6e5 100644
--- a/src/net_permissions.h
+++ b/src/net_permissions.h
@@ -15,6 +15,11 @@ struct bilingual_str;
extern const std::vector<std::string> NET_PERMISSIONS_DOC;
+/** Default for -whitelistrelay. */
+constexpr bool DEFAULT_WHITELISTRELAY = true;
+/** Default for -whitelistforcerelay. */
+constexpr bool DEFAULT_WHITELISTFORCERELAY = false;
+
enum class NetPermissionFlags : uint32_t {
None = 0,
// Can query bloomfilter even if -peerbloomfilters is false
@@ -71,6 +76,7 @@ public:
using t = typename std::underlying_type<NetPermissionFlags>::type;
flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
}
+ static void Initialize(NetPermissionFlags& flags);
};
</p></details>