Line data Source code
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 <vector> 9 : 10 : #ifndef BITCOIN_NET_PERMISSIONS_H 11 : #define BITCOIN_NET_PERMISSIONS_H 12 : 13 : struct bilingual_str; 14 : 15 : extern const std::vector<std::string> NET_PERMISSIONS_DOC; 16 : 17 : enum NetPermissionFlags { 18 : PF_NONE = 0, 19 : // Can query bloomfilter even if -peerbloomfilters is false 20 : PF_BLOOMFILTER = (1U << 1), 21 : // Relay and accept transactions from this peer, even if -blocksonly is true 22 : PF_RELAY = (1U << 3), 23 : // Always relay transactions from this peer, even if already in mempool 24 : // Keep parameter interaction: forcerelay implies relay 25 : PF_FORCERELAY = (1U << 2) | PF_RELAY, 26 : // Allow getheaders during IBD and block-download after maxuploadtarget limit 27 : PF_DOWNLOAD = (1U << 6), 28 : // Can't be banned/disconnected/discouraged for misbehavior 29 : PF_NOBAN = (1U << 4) | PF_DOWNLOAD, 30 : // Can query the mempool 31 : PF_MEMPOOL = (1U << 5), 32 : // Can request addrs without hitting a privacy-preserving cache 33 : PF_ADDR = (1U << 7), 34 : 35 : // True if the user did not specifically set fine grained permissions 36 : PF_ISIMPLICIT = (1U << 31), 37 : PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL | PF_DOWNLOAD | PF_ADDR, 38 : }; 39 : 40 : class NetPermissions 41 : { 42 : public: 43 : NetPermissionFlags m_flags; 44 : static std::vector<std::string> ToStrings(NetPermissionFlags flags); 45 662197 : static inline bool HasFlag(const NetPermissionFlags& flags, NetPermissionFlags f) 46 : { 47 662197 : return (flags & f) == f; 48 : } 49 660 : static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f) 50 : { 51 660 : flags = static_cast<NetPermissionFlags>(flags | f); 52 660 : } 53 8 : static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f) 54 : { 55 8 : flags = static_cast<NetPermissionFlags>(flags & ~f); 56 8 : } 57 : }; 58 : 59 16 : class NetWhitebindPermissions : public NetPermissions 60 : { 61 : public: 62 : static bool TryParse(const std::string str, NetWhitebindPermissions& output, bilingual_str& error); 63 : CService m_service; 64 : }; 65 : 66 720 : class NetWhitelistPermissions : public NetPermissions 67 : { 68 : public: 69 : static bool TryParse(const std::string str, NetWhitelistPermissions& output, bilingual_str& error); 70 : CSubNet m_subnet; 71 : }; 72 : 73 : #endif // BITCOIN_NET_PERMISSIONS_H