Bitcoin Core  22.99.0
P2P Digital Currency
net_permissions.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2020 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 
7 #include <string>
8 #include <type_traits>
9 #include <vector>
10 
11 #ifndef BITCOIN_NET_PERMISSIONS_H
12 #define BITCOIN_NET_PERMISSIONS_H
13 
14 struct bilingual_str;
15 
16 extern const std::vector<std::string> NET_PERMISSIONS_DOC;
17 
18 enum class NetPermissionFlags : uint32_t {
19  None = 0,
20  // Can query bloomfilter even if -peerbloomfilters is false
21  BloomFilter = (1U << 1),
22  // Relay and accept transactions from this peer, even if -blocksonly is true
23  // This peer is also not subject to limits on how many transaction INVs are tracked
24  Relay = (1U << 3),
25  // Always relay transactions from this peer, even if already in mempool
26  // Keep parameter interaction: forcerelay implies relay
27  ForceRelay = (1U << 2) | Relay,
28  // Allow getheaders during IBD and block-download after maxuploadtarget limit
29  Download = (1U << 6),
30  // Can't be banned/disconnected/discouraged for misbehavior
31  NoBan = (1U << 4) | Download,
32  // Can query the mempool
33  Mempool = (1U << 5),
34  // Can request addrs without hitting a privacy-preserving cache, and send us
35  // unlimited amounts of addrs.
36  Addr = (1U << 7),
37 
38  // True if the user did not specifically set fine grained permissions
39  Implicit = (1U << 31),
41 };
43 {
44  using t = typename std::underlying_type<NetPermissionFlags>::type;
45  return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b));
46 }
47 
49 {
50 public:
52  static std::vector<std::string> ToStrings(NetPermissionFlags flags);
54  {
55  using t = typename std::underlying_type<NetPermissionFlags>::type;
56  return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f);
57  }
59  {
60  flags = flags | f;
61  }
68  {
70  using t = typename std::underlying_type<NetPermissionFlags>::type;
71  flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f));
72  }
73 };
74 
76 {
77 public:
78  static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error);
80 };
81 
83 {
84 public:
85  static bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error);
87 };
88 
89 #endif // BITCOIN_NET_PERMISSIONS_H
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:539
assert
assert(!tx.IsCoinBase())
NetPermissionFlags::None
@ None
NetPermissions::ToStrings
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
Definition: net_permissions.cpp:71
flags
int flags
Definition: bitcoin-tx.cpp:513
bilingual_str
Bilingual messages:
Definition: translation.h:16
NetPermissionFlags::NoBan
@ NoBan
NetPermissions::ClearFlag
static void ClearFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ClearFlag is only called with f == NetPermissionFlags::Implicit.
Definition: net_permissions.h:67
NetPermissions::HasFlag
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
Definition: net_permissions.h:53
NetWhitelistPermissions::TryParse
static bool TryParse(const std::string &str, NetWhitelistPermissions &output, bilingual_str &error)
Definition: net_permissions.cpp:107
NetWhitelistPermissions::m_subnet
CSubNet m_subnet
Definition: net_permissions.h:86
NET_PERMISSIONS_DOC
const std::vector< std::string > NET_PERMISSIONS_DOC
Definition: net_permissions.cpp:11
NetPermissionFlags
NetPermissionFlags
Definition: net_permissions.h:18
NetPermissionFlags::BloomFilter
@ BloomFilter
NetWhitelistPermissions
Definition: net_permissions.h:82
NetPermissionFlags::Download
@ Download
netaddress.h
NetWhitebindPermissions::m_service
CService m_service
Definition: net_permissions.h:79
NetPermissionFlags::ForceRelay
@ ForceRelay
CSubNet
Definition: netaddress.h:486
NetPermissionFlags::Relay
@ Relay
NetPermissionFlags::All
@ All
operator|
static constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
Definition: net_permissions.h:42
NetPermissionFlags::Addr
@ Addr
NetWhitebindPermissions::TryParse
static bool TryParse(const std::string &str, NetWhitebindPermissions &output, bilingual_str &error)
Definition: net_permissions.cpp:84
NetPermissionFlags::Implicit
@ Implicit
NetPermissions::AddFlag
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
Definition: net_permissions.h:58
NetPermissions::m_flags
NetPermissionFlags m_flags
Definition: net_permissions.h:51
NetPermissions
Definition: net_permissions.h:48
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
NetWhitebindPermissions
Definition: net_permissions.h:75
NetPermissionFlags::Mempool
@ Mempool