Bitcoin Core  27.99.0
P2P Digital Currency
net_permissions.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <netaddress.h>
6 #include <netbase.h>
7 
8 #include <string>
9 #include <type_traits>
10 #include <vector>
11 
12 #ifndef BITCOIN_NET_PERMISSIONS_H
13 #define BITCOIN_NET_PERMISSIONS_H
14 
15 struct bilingual_str;
16 
17 extern const std::vector<std::string> NET_PERMISSIONS_DOC;
18 
20 constexpr bool DEFAULT_WHITELISTRELAY = true;
22 constexpr bool DEFAULT_WHITELISTFORCERELAY = false;
23 
24 enum class NetPermissionFlags : uint32_t {
25  None = 0,
26  // Can query bloomfilter even if -peerbloomfilters is false
27  BloomFilter = (1U << 1),
28  // Relay and accept transactions from this peer, even if -blocksonly is true
29  // This peer is also not subject to limits on how many transaction INVs are tracked
30  Relay = (1U << 3),
31  // Always relay transactions from this peer, even if already in mempool
32  // Keep parameter interaction: forcerelay implies relay
33  ForceRelay = (1U << 2) | Relay,
34  // Allow getheaders during IBD and block-download after maxuploadtarget limit
35  Download = (1U << 6),
36  // Can't be banned/disconnected/discouraged for misbehavior
37  NoBan = (1U << 4) | Download,
38  // Can query the mempool
39  Mempool = (1U << 5),
40  // Can request addrs without hitting a privacy-preserving cache, and send us
41  // unlimited amounts of addrs.
42  Addr = (1U << 7),
43 
44  // True if the user did not specifically set fine-grained permissions with
45  // the -whitebind or -whitelist configuration options.
46  Implicit = (1U << 31),
48 };
50 {
51  using t = typename std::underlying_type<NetPermissionFlags>::type;
52  return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));
53 }
54 
56 {
57 public:
59  static std::vector<std::string> ToStrings(NetPermissionFlags flags);
61  {
62  using t = typename std::underlying_type<NetPermissionFlags>::type;
63  return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f);
64  }
66  {
67  flags = flags | f;
68  }
75  {
77  using t = typename std::underlying_type<NetPermissionFlags>::type;
78  flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
79  }
80 };
81 
83 {
84 public:
85  static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error);
87 };
88 
90 {
91 public:
92  static bool TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error);
94 };
95 
96 #endif // BITCOIN_NET_PERMISSIONS_H
int flags
Definition: bitcoin-tx.cpp:530
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:531
NetPermissionFlags m_flags
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
static void ClearFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ClearFlag is only called with f == NetPermissionFlags::Implicit.
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
static bool TryParse(const std::string &str, NetWhitebindPermissions &output, bilingual_str &error)
static bool TryParse(const std::string &str, NetWhitelistPermissions &output, ConnectionDirection &output_connection_direction, bilingual_str &error)
constexpr bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
constexpr bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
static constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
NetPermissionFlags
const std::vector< std::string > NET_PERMISSIONS_DOC
ConnectionDirection
Definition: netbase.h:33
Bilingual messages:
Definition: translation.h:18
assert(!tx.IsCoinBase())