/Users/eugenesiegel/btc/bitcoin/src/net_permissions.h
| Line | Count | Source (jump to first uncovered line) | 
| 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 |  |  | 
| 19 |  | /** Default for -whitelistrelay. */ | 
| 20 |  | constexpr bool DEFAULT_WHITELISTRELAY = true; | 
| 21 |  | /** Default for -whitelistforcerelay. */ | 
| 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), | 
| 47 |  |     All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr, | 
| 48 |  | }; | 
| 49 |  | static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b) | 
| 50 | 0 | { | 
| 51 | 0 |     using t = std::underlying_type_t<NetPermissionFlags>; | 
| 52 | 0 |     return static_cast<NetPermissionFlags>(static_cast<t>(a) | static_cast<t>(b)); | 
| 53 | 0 | } Unexecuted instantiation: addrman.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: banman.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: cmpctblock.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: connman.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: deserialize.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: headerssync.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: i2p.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: net.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: net_permissions.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: netaddress.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: netbase_dns_lookup.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: node_eviction.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: p2p_handshake.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: p2p_headers_presync.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: p2p_transport_serialization.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: pcp.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: process_message.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: process_messages.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: socks5.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txdownloadman.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txorphan.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txrequest.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: setup_common.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: init.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: mapport.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: net_processing.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: context.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: eviction.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: interfaces.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: peerman_args.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: transaction.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txdownloadman_impl.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txorphanage.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: txreconciliation.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: blockchain.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: mempool.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: mining.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: node.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: server_util.cpp:_Zor18NetPermissionFlagsS_Unexecuted instantiation: torcontrol.cpp:_Zor18NetPermissionFlagsS_ | 
| 54 |  |  | 
| 55 |  | class NetPermissions | 
| 56 |  | { | 
| 57 |  | public: | 
| 58 |  |     NetPermissionFlags m_flags; | 
| 59 |  |     static std::vector<std::string> ToStrings(NetPermissionFlags flags); | 
| 60 |  |     static inline bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f) | 
| 61 | 10.9M |     { | 
| 62 | 10.9M |         using t = std::underlying_type_t<NetPermissionFlags>; | 
| 63 | 10.9M |         return (static_cast<t>(flags) & static_cast<t>(f)) == static_cast<t>(f); | 
| 64 | 10.9M |     } | 
| 65 |  |     static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f) | 
| 66 | 0 |     { | 
| 67 | 0 |         flags = flags | f; | 
| 68 | 0 |     } | 
| 69 |  |     //! ClearFlag is only called with `f` == NetPermissionFlags::Implicit. | 
| 70 |  |     //! If that should change in the future, be aware that ClearFlag should not | 
| 71 |  |     //! be called with a subflag of a multiflag, e.g. NetPermissionFlags::Relay | 
| 72 |  |     //! or NetPermissionFlags::Download, as that would leave `flags` in an | 
| 73 |  |     //! invalid state corresponding to none of the existing flags. | 
| 74 |  |     static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f) | 
| 75 | 0 |     { | 
| 76 | 0 |         assert(f == NetPermissionFlags::Implicit); | 
| 77 | 0 |         using t = std::underlying_type_t<NetPermissionFlags>; | 
| 78 | 0 |         flags = static_cast<NetPermissionFlags>(static_cast<t>(flags) & ~static_cast<t>(f)); | 
| 79 | 0 |     } | 
| 80 |  | }; | 
| 81 |  |  | 
| 82 |  | class NetWhitebindPermissions : public NetPermissions | 
| 83 |  | { | 
| 84 |  | public: | 
| 85 |  |     static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error); | 
| 86 |  |     CService m_service; | 
| 87 |  | }; | 
| 88 |  |  | 
| 89 |  | class NetWhitelistPermissions : public NetPermissions | 
| 90 |  | { | 
| 91 |  | public: | 
| 92 |  |     static bool TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error); | 
| 93 |  |     CSubNet m_subnet; | 
| 94 |  | }; | 
| 95 |  |  | 
| 96 |  | #endif // BITCOIN_NET_PERMISSIONS_H |