mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-04 00:12:33 +02:00
Merge branch 'whitelist_outgoing-mini-25+knots' into p2p_forceinbound-25+knots
This commit is contained in:
commit
d34c665c69
32
src/init.cpp
32
src/init.cpp
@ -433,7 +433,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
||||
argsman.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
#endif
|
||||
argsman.AddArg("-blockreconstructionextratxn=<n>", strprintf("Extra transactions to keep in memory for compact block reconstructions (default: %u)", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from inbound peers is disabled, unless the peer has the 'forcerelay' permission. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Automatic broadcast and rebroadcast of any transactions from any peer is disabled, unless it has the 'forcerelay' permission. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
@ -520,9 +520,11 @@ void SetupServerArgs(ArgsManager& argsman)
|
||||
"Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
|
||||
"Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
|
||||
argsman.AddArg("-whitelist=<[permissions@]IP address or network>", "Add permission flags to the peers connecting from the given IP address (e.g. 1.2.3.4) or "
|
||||
argsman.AddArg("-whitelist=<[permissions@]IP address or network>", "Add permission flags to the peers using the given IP address (e.g. 1.2.3.4) or "
|
||||
"CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
|
||||
"-whitebind. Can be specified multiple times." , ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
"-whitebind. "
|
||||
"Additional flags \"in\" and \"out\" control whether permissions apply to incoming connections and/or outgoing (default: both). "
|
||||
"Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||
|
||||
g_wallet_init_interface.AddWalletOptions(argsman);
|
||||
|
||||
@ -587,8 +589,8 @@ void SetupServerArgs(ArgsManager& argsman)
|
||||
OptionsCategory::NODE_RELAY);
|
||||
argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kvB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
|
||||
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
|
||||
argsman.AddArg("-whitelistforcerelay", strprintf("Add 'forcerelay' permission to whitelisted inbound peers with default permissions. This will relay transactions even if the transactions were already in the mempool. (default: %d)", DEFAULT_WHITELISTFORCERELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
|
||||
argsman.AddArg("-whitelistrelay", strprintf("Add 'relay' permission to whitelisted inbound peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
|
||||
argsman.AddArg("-whitelistforcerelay", strprintf("Add 'forcerelay' permission to whitelisted peers with default permissions. This will relay transactions even if the transactions were already in the mempool. (default: %d)", DEFAULT_WHITELISTFORCERELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
|
||||
argsman.AddArg("-whitelistrelay", strprintf("Add 'relay' permission to whitelisted peers with default permissions. This will accept relayed transactions even when not relaying transactions (default: %d)", DEFAULT_WHITELISTRELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
|
||||
|
||||
|
||||
argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
|
||||
@ -1761,10 +1763,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
return InitError(ResolveErrMsg("bind", bind_arg));
|
||||
}
|
||||
|
||||
NetPermissionFlags all_permission_flags{NetPermissionFlags::None};
|
||||
|
||||
for (const std::string& strBind : args.GetArgs("-whitebind")) {
|
||||
NetWhitebindPermissions whitebind;
|
||||
bilingual_str error;
|
||||
if (!NetWhitebindPermissions::TryParse(strBind, whitebind, error)) return InitError(error);
|
||||
NetPermissions::AddFlag(all_permission_flags, whitebind.m_flags);
|
||||
connOptions.vWhiteBinds.push_back(whitebind);
|
||||
}
|
||||
|
||||
@ -1806,9 +1811,22 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
|
||||
for (const auto& net : args.GetArgs("-whitelist")) {
|
||||
NetWhitelistPermissions subnet;
|
||||
ConnectionDirection connection_direction;
|
||||
bilingual_str error;
|
||||
if (!NetWhitelistPermissions::TryParse(net, subnet, error)) return InitError(error);
|
||||
connOptions.vWhitelistedRange.push_back(subnet);
|
||||
if (!NetWhitelistPermissions::TryParse(net, subnet, connection_direction, error)) return InitError(error);
|
||||
NetPermissions::AddFlag(all_permission_flags, subnet.m_flags);
|
||||
if (connection_direction & ConnectionDirection::In) {
|
||||
connOptions.vWhitelistedRange.push_back(subnet);
|
||||
}
|
||||
if (connection_direction & ConnectionDirection::Out) {
|
||||
connOptions.vWhitelistedRangeOutgoing.push_back(subnet);
|
||||
}
|
||||
}
|
||||
|
||||
if (NetPermissions::HasFlag(all_permission_flags, NetPermissionFlags::BlockFilters_Explicit)) {
|
||||
if (g_enabled_filter_types.count(BlockFilterType::BASIC) != 1) {
|
||||
return InitError(_("Cannot grant blockfilters permission without -blockfilterindex."));
|
||||
}
|
||||
}
|
||||
|
||||
connOptions.vSeedNodes = args.GetArgs("-seednode");
|
||||
|
32
src/net.cpp
32
src/net.cpp
@ -360,6 +360,16 @@ bool IsLocal(const CService& addr)
|
||||
return mapLocalHost.count(addr) > 0;
|
||||
}
|
||||
|
||||
static void InitializePermissionFlags(NetPermissionFlags& flags) {
|
||||
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Implicit)) {
|
||||
NetPermissions::ClearFlag(flags, NetPermissionFlags::Implicit);
|
||||
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
|
||||
if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
|
||||
NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
|
||||
NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
|
||||
}
|
||||
}
|
||||
|
||||
CNode* CConnman::FindNode(const CNetAddr& ip)
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
@ -558,6 +568,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetPermissionFlags permission_flags = NetPermissionFlags::None;
|
||||
AddWhitelistPermissionFlags(permission_flags, addrConnect, vWhitelistedRangeOutgoing);
|
||||
InitializePermissionFlags(permission_flags);
|
||||
|
||||
// Add node
|
||||
NodeId id = GetNewNodeId();
|
||||
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
|
||||
@ -574,6 +588,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
conn_type,
|
||||
/*inbound_onion=*/false,
|
||||
CNodeOptions{
|
||||
.permission_flags = permission_flags,
|
||||
.i2p_sam_session = std::move(i2p_transient_session),
|
||||
.recv_flood_size = nReceiveFloodSize,
|
||||
});
|
||||
@ -596,8 +611,8 @@ void CNode::CloseSocketDisconnect()
|
||||
m_i2p_sam_session.reset();
|
||||
}
|
||||
|
||||
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const {
|
||||
for (const auto& subnet : vWhitelistedRange) {
|
||||
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const {
|
||||
for (const auto& subnet : ranges) {
|
||||
if (subnet.m_subnet.Match(addr)) NetPermissions::AddFlag(flags, subnet.m_flags);
|
||||
}
|
||||
}
|
||||
@ -976,14 +991,8 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
||||
int nInbound = 0;
|
||||
int nMaxInbound = nMaxConnections - m_max_outbound;
|
||||
|
||||
AddWhitelistPermissionFlags(permission_flags, addr);
|
||||
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::Implicit)) {
|
||||
NetPermissions::ClearFlag(permission_flags, NetPermissionFlags::Implicit);
|
||||
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permission_flags, NetPermissionFlags::ForceRelay);
|
||||
if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(permission_flags, NetPermissionFlags::Relay);
|
||||
NetPermissions::AddFlag(permission_flags, NetPermissionFlags::Mempool);
|
||||
NetPermissions::AddFlag(permission_flags, NetPermissionFlags::NoBan);
|
||||
}
|
||||
AddWhitelistPermissionFlags(permission_flags, addr, vWhitelistedRange);
|
||||
InitializePermissionFlags(permission_flags);
|
||||
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
@ -1039,9 +1048,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
||||
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
|
||||
|
||||
ServiceFlags nodeServices = nLocalServices;
|
||||
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::BloomFilter)) {
|
||||
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
|
||||
}
|
||||
|
||||
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
|
||||
CNode* pnode = new CNode(id,
|
||||
|
@ -711,6 +711,7 @@ public:
|
||||
int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
|
||||
std::vector<std::string> vSeedNodes;
|
||||
std::vector<NetWhitelistPermissions> vWhitelistedRange;
|
||||
std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
|
||||
std::vector<NetWhitebindPermissions> vWhiteBinds;
|
||||
std::vector<CService> vBinds;
|
||||
std::vector<CService> onion_binds;
|
||||
@ -746,6 +747,7 @@ public:
|
||||
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
|
||||
}
|
||||
vWhitelistedRange = connOptions.vWhitelistedRange;
|
||||
vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
|
||||
{
|
||||
LOCK(m_added_nodes_mutex);
|
||||
m_added_nodes = connOptions.m_added_nodes;
|
||||
@ -983,7 +985,7 @@ private:
|
||||
|
||||
bool AttemptToEvictConnection();
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
||||
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
|
||||
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const;
|
||||
|
||||
void DeleteNode(CNode* pnode);
|
||||
|
||||
@ -1026,6 +1028,8 @@ private:
|
||||
// Whitelisted ranges. Any node connecting from these is automatically
|
||||
// whitelisted (as well as those connecting to whitelisted binds).
|
||||
std::vector<NetWhitelistPermissions> vWhitelistedRange;
|
||||
// Whitelisted ranges for outgoing connections.
|
||||
std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
|
||||
|
||||
unsigned int nSendBufferMaxSize{0};
|
||||
unsigned int nReceiveFloodSize{0};
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
const std::vector<std::string> NET_PERMISSIONS_DOC{
|
||||
"bloomfilter (allow requesting BIP37 filtered blocks and transactions)",
|
||||
"blockfilters (serve compact block filters to peers per BIP157)",
|
||||
"noban (do not ban for misbehavior; implies download)",
|
||||
"forcerelay (relay transactions that are already in the mempool; implies relay)",
|
||||
"relay (relay even in -blocksonly mode, and unlimited transaction announcements)",
|
||||
@ -21,9 +22,10 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
|
||||
namespace {
|
||||
|
||||
// Parse the following format: "perm1,perm2@xxxxxx"
|
||||
bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, size_t& readen, bilingual_str& error)
|
||||
static bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, ConnectionDirection* output_connection_direction, size_t& readen, bilingual_str& error)
|
||||
{
|
||||
NetPermissionFlags flags = NetPermissionFlags::None;
|
||||
ConnectionDirection connection_direction = ConnectionDirection::None;
|
||||
const auto atSeparator = str.find('@');
|
||||
|
||||
// if '@' is not found (ie, "xxxxx"), the caller should apply implicit permissions
|
||||
@ -45,6 +47,7 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
|
||||
if (commaSeparator != std::string::npos) readen++; // We read ","
|
||||
|
||||
if (permission == "bloomfilter" || permission == "bloom") NetPermissions::AddFlag(flags, NetPermissionFlags::BloomFilter);
|
||||
else if (permission == "blockfilters" || permission == "compactfilters" || permission == "cfilters") NetPermissions::AddFlag(flags, NetPermissionFlags::BlockFilters_Explicit);
|
||||
else if (permission == "noban") NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
|
||||
else if (permission == "forcerelay") NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
|
||||
else if (permission == "mempool") NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
|
||||
@ -52,6 +55,15 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
|
||||
else if (permission == "all") NetPermissions::AddFlag(flags, NetPermissionFlags::All);
|
||||
else if (permission == "relay") NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
|
||||
else if (permission == "addr") NetPermissions::AddFlag(flags, NetPermissionFlags::Addr);
|
||||
else if (permission == "in") connection_direction |= ConnectionDirection::In;
|
||||
else if (permission == "out") {
|
||||
if (output_connection_direction == nullptr) {
|
||||
// Only NetWhitebindPermissions() should pass a nullptr.
|
||||
error = _("whitebind may only be used for incoming connections (\"out\" was passed)");
|
||||
return false;
|
||||
}
|
||||
connection_direction |= ConnectionDirection::Out;
|
||||
}
|
||||
else if (permission.length() == 0); // Allow empty entries
|
||||
else {
|
||||
error = strprintf(_("Invalid P2P permission: '%s'"), permission);
|
||||
@ -61,7 +73,11 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
|
||||
readen++;
|
||||
}
|
||||
|
||||
// By default, whitelist applies to all connections
|
||||
if (connection_direction == ConnectionDirection::None) connection_direction = ConnectionDirection::Both;
|
||||
|
||||
output = flags;
|
||||
if (output_connection_direction) *output_connection_direction = connection_direction;
|
||||
error = Untranslated("");
|
||||
return true;
|
||||
}
|
||||
@ -71,6 +87,7 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
|
||||
std::vector<std::string> NetPermissions::ToStrings(NetPermissionFlags flags)
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BlockFilters)) strings.push_back("blockfilters");
|
||||
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.push_back("bloomfilter");
|
||||
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.push_back("noban");
|
||||
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.push_back("forcerelay");
|
||||
@ -85,7 +102,7 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
|
||||
{
|
||||
NetPermissionFlags flags;
|
||||
size_t offset;
|
||||
if (!TryParsePermissionFlags(str, flags, offset, error)) return false;
|
||||
if (!TryParsePermissionFlags(str, flags, /*output_connection_direction=*/nullptr, offset, error)) return false;
|
||||
|
||||
const std::string strBind = str.substr(offset);
|
||||
CService addrBind;
|
||||
@ -104,11 +121,11 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error)
|
||||
bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error)
|
||||
{
|
||||
NetPermissionFlags flags;
|
||||
size_t offset;
|
||||
if (!TryParsePermissionFlags(str, flags, offset, error)) return false;
|
||||
if (!TryParsePermissionFlags(str, flags, &output_connection_direction, offset, error)) return false;
|
||||
|
||||
const std::string net = str.substr(offset);
|
||||
CSubNet subnet;
|
||||
|
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@ -35,10 +36,15 @@ enum class NetPermissionFlags : uint32_t {
|
||||
// unlimited amounts of addrs.
|
||||
Addr = (1U << 7),
|
||||
|
||||
// Can query compact filters even if -peerblockfilters is false
|
||||
BlockFilters = (1U << 8),
|
||||
// Used to avoid an error when All is used to set BlockFilters
|
||||
BlockFilters_Explicit = BlockFilters | (1U << 9),
|
||||
|
||||
// True if the user did not specifically set fine-grained permissions with
|
||||
// the -whitebind or -whitelist configuration options.
|
||||
Implicit = (1U << 31),
|
||||
All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr,
|
||||
All = BloomFilter | ForceRelay | Relay | NoBan | Mempool | Download | Addr | BlockFilters,
|
||||
};
|
||||
static inline constexpr NetPermissionFlags operator|(NetPermissionFlags a, NetPermissionFlags b)
|
||||
{
|
||||
@ -83,7 +89,11 @@ public:
|
||||
class NetWhitelistPermissions : public NetPermissions
|
||||
{
|
||||
public:
|
||||
static bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error);
|
||||
static bool TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error);
|
||||
static inline bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error) {
|
||||
ConnectionDirection connection_direction_ignored;
|
||||
return TryParse(str, output, connection_direction_ignored, error);
|
||||
}
|
||||
CSubNet m_subnet;
|
||||
};
|
||||
|
||||
|
@ -1451,6 +1451,14 @@ void PeerManagerImpl::InitializeNode(CNode& node, ServiceFlags our_services)
|
||||
m_node_states.emplace_hint(m_node_states.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(node.IsInboundConn()));
|
||||
assert(m_txrequest.Count(nodeid) == 0);
|
||||
}
|
||||
|
||||
if (NetPermissions::HasFlag(node.m_permission_flags, NetPermissionFlags::BloomFilter)) {
|
||||
our_services = static_cast<ServiceFlags>(our_services | NODE_BLOOM);
|
||||
}
|
||||
if (NetPermissions::HasFlag(node.m_permission_flags, NetPermissionFlags::BlockFilters)) {
|
||||
our_services = static_cast<ServiceFlags>(our_services | NODE_COMPACT_FILTERS);
|
||||
}
|
||||
|
||||
PeerRef peer = std::make_shared<Peer>(nodeid, our_services);
|
||||
{
|
||||
LOCK(m_peer_mutex);
|
||||
|
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <net_permissions.h>
|
||||
#include <netbase.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
@ -31,8 +32,9 @@ FUZZ_TARGET(net_permissions)
|
||||
}
|
||||
|
||||
NetWhitelistPermissions net_whitelist_permissions;
|
||||
ConnectionDirection connection_direction;
|
||||
bilingual_str error_net_whitelist_permissions;
|
||||
if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) {
|
||||
if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, connection_direction, error_net_whitelist_permissions)) {
|
||||
(void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
|
||||
(void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags);
|
||||
assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags));
|
||||
|
@ -445,6 +445,9 @@ BOOST_AUTO_TEST_CASE(netpermissions_test)
|
||||
BOOST_CHECK(NetWhitebindPermissions::TryParse(",,@1.2.3.4:32", whitebindPermissions, error));
|
||||
BOOST_CHECK_EQUAL(whitebindPermissions.m_flags, NetPermissionFlags::None);
|
||||
|
||||
BOOST_CHECK(!NetWhitebindPermissions::TryParse("out,forcerelay@1.2.3.4:32", whitebindPermissions, error));
|
||||
BOOST_CHECK(error.original.find("whitebind may only be used for incoming connections (\"out\" was passed)") != std::string::npos);
|
||||
|
||||
// Detect invalid flag
|
||||
BOOST_CHECK(!NetWhitebindPermissions::TryParse("bloom,forcerelay,oopsie@1.2.3.4:32", whitebindPermissions, error));
|
||||
BOOST_CHECK(error.original.find("Invalid P2P permission") != std::string::npos);
|
||||
@ -463,9 +466,17 @@ BOOST_AUTO_TEST_CASE(netpermissions_test)
|
||||
BOOST_CHECK(error.empty());
|
||||
BOOST_CHECK_EQUAL(whitelistPermissions.m_subnet.ToString(), "1.2.3.4/32");
|
||||
BOOST_CHECK(NetWhitelistPermissions::TryParse("bloom,forcerelay,noban,relay,mempool@1.2.3.4/32", whitelistPermissions, error));
|
||||
ConnectionDirection connection_direction;
|
||||
BOOST_CHECK(NetWhitelistPermissions::TryParse("in,relay@1.2.3.4", whitelistPermissions, connection_direction, error));
|
||||
BOOST_CHECK_EQUAL(connection_direction, ConnectionDirection::In);
|
||||
BOOST_CHECK(NetWhitelistPermissions::TryParse("out,bloom@1.2.3.4", whitelistPermissions, connection_direction, error));
|
||||
BOOST_CHECK_EQUAL(connection_direction, ConnectionDirection::Out);
|
||||
BOOST_CHECK(NetWhitelistPermissions::TryParse("in,out,bloom@1.2.3.4", whitelistPermissions, connection_direction, error));
|
||||
BOOST_CHECK_EQUAL(connection_direction, ConnectionDirection::Both);
|
||||
|
||||
const auto strings = NetPermissions::ToStrings(NetPermissionFlags::All);
|
||||
BOOST_CHECK_EQUAL(strings.size(), 7U);
|
||||
BOOST_CHECK_EQUAL(strings.size(), 8U);
|
||||
BOOST_CHECK(std::find(strings.begin(), strings.end(), "blockfilters") != strings.end());
|
||||
BOOST_CHECK(std::find(strings.begin(), strings.end(), "bloomfilter") != strings.end());
|
||||
BOOST_CHECK(std::find(strings.begin(), strings.end(), "forcerelay") != strings.end());
|
||||
BOOST_CHECK(std::find(strings.begin(), strings.end(), "relay") != strings.end());
|
||||
|
@ -283,6 +283,13 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
peer.send_message(msg_headers([blockheader]))
|
||||
peer.wait_for_disconnect()
|
||||
|
||||
self.log.info('Test same previous scenario but with a whitelisted (noban) outbound peer. '
|
||||
'It should log as misbehaving but not cause a disconnection')
|
||||
self.restart_node(0, extra_args=["-whitelist=noban,out@127.0.0.1"])
|
||||
ob_peer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=5)
|
||||
with self.nodes[0].assert_debug_log(['Misbehaving', 'header with invalid proof of work']):
|
||||
ob_peer.send_and_ping(msg_headers([blockheader]))
|
||||
|
||||
def test_resource_exhaustion(self):
|
||||
self.log.info("Test node stays up despite many large junk messages")
|
||||
conn = self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
|
@ -81,7 +81,16 @@ class P2PPermissionsTests(BitcoinTestFramework):
|
||||
self.checkpermission(
|
||||
# all permission added
|
||||
["-whitelist=all@127.0.0.1"],
|
||||
["forcerelay", "noban", "mempool", "bloomfilter", "relay", "download", "addr"])
|
||||
[
|
||||
"blockfilters",
|
||||
"forcerelay",
|
||||
"noban",
|
||||
"mempool",
|
||||
"bloomfilter",
|
||||
"relay",
|
||||
"download",
|
||||
"addr",
|
||||
])
|
||||
|
||||
self.stop_node(1)
|
||||
self.nodes[1].assert_start_raises_init_error(["-whitelist=oopsie@127.0.0.1"], "Invalid P2P permission", match=ErrorMatch.PARTIAL_REGEX)
|
||||
|
Loading…
Reference in New Issue
Block a user