mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
a34237c54b
39393479c514f271c42750ffcd0adc6bc1db2e2f p2p: pass strings to NetPermissions::TryParse functions by const ref (Jon Atack) Pull request description: instead of by value, as these are "in" params that are not cheap to copy. Reference: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f16-for-in-parameters-pass-cheaply-copied-types-by-value-and-others-by-reference-to-const ACKs for top commit: MarcoFalke: cr ACK 39393479c514f271c42750ffcd0adc6bc1db2e2f Tree-SHA512: 294fe0f2d900293b4447d4e1f0ccc60c1ed27b3bdbd0f5d71d3dbf71de86879638b1b813fadfb44c58b4acff4e7d75b7ed6a4f9cc5fcf627108224e6a21b524c
66 lines
2.1 KiB
C++
66 lines
2.1 KiB
C++
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <netaddress.h>
|
|
|
|
#ifndef BITCOIN_NET_PERMISSIONS_H
|
|
#define BITCOIN_NET_PERMISSIONS_H
|
|
|
|
struct bilingual_str;
|
|
|
|
enum NetPermissionFlags
|
|
{
|
|
PF_NONE = 0,
|
|
// Can query bloomfilter even if -peerbloomfilters is false
|
|
PF_BLOOMFILTER = (1U << 1),
|
|
// Relay and accept transactions from this peer, even if -blocksonly is true
|
|
PF_RELAY = (1U << 3),
|
|
// Always relay transactions from this peer, even if already in mempool or rejected from policy
|
|
// Keep parameter interaction: forcerelay implies relay
|
|
PF_FORCERELAY = (1U << 2) | PF_RELAY,
|
|
// Can't be banned for misbehavior
|
|
PF_NOBAN = (1U << 4),
|
|
// Can query the mempool
|
|
PF_MEMPOOL = (1U << 5),
|
|
|
|
// True if the user did not specifically set fine grained permissions
|
|
PF_ISIMPLICIT = (1U << 31),
|
|
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL,
|
|
};
|
|
class NetPermissions
|
|
{
|
|
public:
|
|
NetPermissionFlags m_flags;
|
|
static std::vector<std::string> ToStrings(NetPermissionFlags flags);
|
|
static inline bool HasFlag(const NetPermissionFlags& flags, NetPermissionFlags f)
|
|
{
|
|
return (flags & f) == f;
|
|
}
|
|
static inline void AddFlag(NetPermissionFlags& flags, NetPermissionFlags f)
|
|
{
|
|
flags = static_cast<NetPermissionFlags>(flags | f);
|
|
}
|
|
static inline void ClearFlag(NetPermissionFlags& flags, NetPermissionFlags f)
|
|
{
|
|
flags = static_cast<NetPermissionFlags>(flags & ~f);
|
|
}
|
|
};
|
|
class NetWhitebindPermissions : public NetPermissions
|
|
{
|
|
public:
|
|
static bool TryParse(const std::string& str, NetWhitebindPermissions& output, bilingual_str& error);
|
|
CService m_service;
|
|
};
|
|
|
|
class NetWhitelistPermissions : public NetPermissions
|
|
{
|
|
public:
|
|
static bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error);
|
|
CSubNet m_subnet;
|
|
};
|
|
|
|
#endif // BITCOIN_NET_PERMISSIONS_H
|