Changeset View
Changeset View
Standalone View
Standalone View
src/net_permissions.h
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_NET_PERMISSIONS_H | #ifndef BITCOIN_NET_PERMISSIONS_H | ||||
#define BITCOIN_NET_PERMISSIONS_H | #define BITCOIN_NET_PERMISSIONS_H | ||||
#include <netaddress.h> | #include <netaddress.h> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
struct bilingual_str; | struct bilingual_str; | ||||
extern const std::vector<std::string> NET_PERMISSIONS_DOC; | |||||
enum NetPermissionFlags { | enum NetPermissionFlags { | ||||
PF_NONE = 0, | PF_NONE = 0, | ||||
// Can query bloomfilter even if -peerbloomfilters is false | // Can query bloomfilter even if -peerbloomfilters is false | ||||
PF_BLOOMFILTER = (1U << 1), | PF_BLOOMFILTER = (1U << 1), | ||||
// Relay and accept transactions from this peer, even if -blocksonly is true | // Relay and accept transactions from this peer, even if -blocksonly is true | ||||
PF_RELAY = (1U << 3), | PF_RELAY = (1U << 3), | ||||
// Always relay transactions from this peer, even if already in mempool or | // Always relay transactions from this peer, even if already in mempool or | ||||
// rejected from policy Keep parameter interaction: forcerelay implies relay | // rejected from policy Keep parameter interaction: forcerelay implies relay | ||||
PF_FORCERELAY = (1U << 2) | PF_RELAY, | PF_FORCERELAY = (1U << 2) | PF_RELAY, | ||||
// Can't be banned/disconnected/discouraged for misbehavior | // Can't be banned/disconnected/discouraged for misbehavior | ||||
PF_NOBAN = (1U << 4), | PF_NOBAN = (1U << 4), | ||||
// Can query the mempool | // Can query the mempool | ||||
PF_MEMPOOL = (1U << 5), | PF_MEMPOOL = (1U << 5), | ||||
// True if the user did not specifically set fine grained permissions | // True if the user did not specifically set fine grained permissions | ||||
PF_ISIMPLICIT = (1U << 31), | PF_ISIMPLICIT = (1U << 31), | ||||
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL, | PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL, | ||||
}; | }; | ||||
class NetPermissions { | class NetPermissions { | ||||
public: | public: | ||||
NetPermissionFlags m_flags; | NetPermissionFlags m_flags; | ||||
static std::vector<std::string> ToStrings(NetPermissionFlags flags); | static std::vector<std::string> ToStrings(NetPermissionFlags flags); | ||||
static inline bool HasFlag(const NetPermissionFlags &flags, | static inline bool HasFlag(const NetPermissionFlags &flags, | ||||
NetPermissionFlags f) { | NetPermissionFlags f) { | ||||
return (flags & f) == f; | return (flags & f) == f; | ||||
} | } | ||||
static inline void AddFlag(NetPermissionFlags &flags, | static inline void AddFlag(NetPermissionFlags &flags, | ||||
NetPermissionFlags f) { | NetPermissionFlags f) { | ||||
flags = static_cast<NetPermissionFlags>(flags | f); | flags = static_cast<NetPermissionFlags>(flags | f); | ||||
} | } | ||||
static inline void ClearFlag(NetPermissionFlags &flags, | static inline void ClearFlag(NetPermissionFlags &flags, | ||||
NetPermissionFlags f) { | NetPermissionFlags f) { | ||||
flags = static_cast<NetPermissionFlags>(flags & ~f); | flags = static_cast<NetPermissionFlags>(flags & ~f); | ||||
} | } | ||||
}; | }; | ||||
class NetWhitebindPermissions : public NetPermissions { | class NetWhitebindPermissions : public NetPermissions { | ||||
public: | public: | ||||
static bool TryParse(const std::string str, NetWhitebindPermissions &output, | static bool TryParse(const std::string str, NetWhitebindPermissions &output, | ||||
bilingual_str &error); | bilingual_str &error); | ||||
CService m_service; | CService m_service; | ||||
}; | }; | ||||
class NetWhitelistPermissions : public NetPermissions { | class NetWhitelistPermissions : public NetPermissions { | ||||
public: | public: | ||||
static bool TryParse(const std::string str, NetWhitelistPermissions &output, | static bool TryParse(const std::string str, NetWhitelistPermissions &output, | ||||
bilingual_str &error); | bilingual_str &error); | ||||
CSubNet m_subnet; | CSubNet m_subnet; | ||||
}; | }; | ||||
#endif // BITCOIN_NET_PERMISSIONS_H | #endif // BITCOIN_NET_PERMISSIONS_H |