Skip to content

Commit bef9917

Browse files
committed
Merge bitcoin#27114: p2p: Allow whitelisting manual connections
0a53361 docs: add release notes for bitcoin#27114 (brunoerg) e6b8f19 test: add coverage for whitelisting manual connections (brunoerg) c985eb8 test: add option to speed up tx relay/mempool sync (brunoerg) 66bc6e2 Accept "in" and "out" flags to -whitelist to allow whitelisting manual connections (Luke Dashjr) 8e06be3 net_processing: Move extra service flag into InitializeNode (Luke Dashjr) 9133fd6 net: Move `NetPermissionFlags::Implicit` verification to `AddWhitelistPermissionFlags` (Luke Dashjr) 2863d7d net: store `-whitelist{force}relay` values in `CConnman` (brunoerg) Pull request description: Revives bitcoin#17167. It allows whitelisting manual connections. Fixes bitcoin#9923 Since there are some PRs/issues around this topic, I'll list some motivations/comments for whitelisting outbound connections from them: - Speed-up tx relay/mempool sync for testing purposes (my personal motivation for this) - In bitcoin#26970, theStack pointed out that we whitelist peers to speed up tx relay for fast mempool synchronization, however, since it applies only for inbound connections and considering the topology `node0 <--- node1 <---- node2 <--- ... <-- nodeN`, if a tx is submitted from any node other than node0, the mempool synchronization can take quite long. - bitcoin#29058 (comment) - "Before enabling -v2transport by default (which I'd image may happen after bitcoin#24748) we could consider a way to force manual connections to be only-v1 or even only-v2 (disabling reconnect-with-v1). A possibility could be through a net permission flag, if bitcoin#27114 makes it in." - bitcoin#17167 (comment) - "This would allow us to use bitcoin#25355 when making outgoing connections to all nodes, except to whitelisted ones for which we would use our persistent I2P address." - Force-relay/mempool permissions for a node you intentionally connected to. ACKs for top commit: achow101: ACK 0a53361 sr-gi: re-ACK [0a53361](bitcoin@0a53361) pinheadmz: ACK 0a53361 Tree-SHA512: 97a79bb854110da04540897d2619eda409d829016aafdf1825ab5515334b0b42ef82f33cd41587af235b3af6ddcec3f2905ca038b5ab22e4c8a03d34f27aebe1
2 parents 12dae63 + 0a53361 commit bef9917

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+199
-108
lines changed

doc/release-notes-27114.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Additional flags "in" and "out" have been added to `-whitelist` to control whether
2+
permissions apply to incoming connections and/or manual (default: incoming only).

src/init.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ void SetupServerArgs(ArgsManager& argsman)
477477
argsman.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
478478
#endif
479479
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);
480-
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);
480+
argsman.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Disables automatic broadcast and rebroadcast of transactions, unless the source peer has the 'forcerelay' permission. RPC transactions are not affected. (default: %u)", DEFAULT_BLOCKSONLY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
481481
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
482482
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);
483483
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -571,9 +571,11 @@ void SetupServerArgs(ArgsManager& argsman)
571571
"Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
572572
"Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
573573

574-
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 "
574+
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 "
575575
"CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
576-
"-whitebind. Can be specified multiple times." , ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
576+
"-whitebind. "
577+
"Additional flags \"in\" and \"out\" control whether permissions apply to incoming connections and/or manual (default: incoming only). "
578+
"Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
577579

578580
g_wallet_init_interface.AddWalletOptions(argsman);
579581

@@ -643,8 +645,8 @@ void SetupServerArgs(ArgsManager& argsman)
643645
OptionsCategory::NODE_RELAY);
644646
argsman.AddArg("-minrelaytxfee=<amt>", strprintf("Fees (in %s/kvB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)",
645647
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
646-
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);
647-
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);
648+
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);
649+
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);
648650

649651

650652
argsman.AddArg("-blockmaxweight=<n>", strprintf("Set maximum BIP141 block weight (default: %d)", DEFAULT_BLOCK_MAX_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
@@ -1800,6 +1802,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18001802
connOptions.m_added_nodes = args.GetArgs("-addnode");
18011803
connOptions.nMaxOutboundLimit = *opt_max_upload;
18021804
connOptions.m_peer_connect_timeout = peer_connect_timeout;
1805+
connOptions.whitelist_forcerelay = args.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY);
1806+
connOptions.whitelist_relay = args.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY);
18031807

18041808
// Port to bind to if `-bind=addr` is provided without a `:port` suffix.
18051809
const uint16_t default_bind_port =
@@ -1884,9 +1888,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18841888

18851889
for (const auto& net : args.GetArgs("-whitelist")) {
18861890
NetWhitelistPermissions subnet;
1891+
ConnectionDirection connection_direction;
18871892
bilingual_str error;
1888-
if (!NetWhitelistPermissions::TryParse(net, subnet, error)) return InitError(error);
1889-
connOptions.vWhitelistedRange.push_back(subnet);
1893+
if (!NetWhitelistPermissions::TryParse(net, subnet, connection_direction, error)) return InitError(error);
1894+
if (connection_direction & ConnectionDirection::In) {
1895+
connOptions.vWhitelistedRangeIncoming.push_back(subnet);
1896+
}
1897+
if (connection_direction & ConnectionDirection::Out) {
1898+
connOptions.vWhitelistedRangeOutgoing.push_back(subnet);
1899+
}
18901900
}
18911901

18921902
connOptions.vSeedNodes = args.GetArgs("-seednode");

src/net.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
514514
return nullptr;
515515
}
516516

517+
NetPermissionFlags permission_flags = NetPermissionFlags::None;
518+
std::vector<NetWhitelistPermissions> whitelist_permissions = conn_type == ConnectionType::MANUAL ? vWhitelistedRangeOutgoing : std::vector<NetWhitelistPermissions>{};
519+
AddWhitelistPermissionFlags(permission_flags, addrConnect, whitelist_permissions);
520+
517521
// Add node
518522
NodeId id = GetNewNodeId();
519523
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
@@ -530,6 +534,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
530534
conn_type,
531535
/*inbound_onion=*/false,
532536
CNodeOptions{
537+
.permission_flags = permission_flags,
533538
.i2p_sam_session = std::move(i2p_transient_session),
534539
.recv_flood_size = nReceiveFloodSize,
535540
.use_v2transport = use_v2transport,
@@ -553,9 +558,18 @@ void CNode::CloseSocketDisconnect()
553558
m_i2p_sam_session.reset();
554559
}
555560

556-
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const {
557-
for (const auto& subnet : vWhitelistedRange) {
558-
if (subnet.m_subnet.Match(addr)) NetPermissions::AddFlag(flags, subnet.m_flags);
561+
void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const {
562+
for (const auto& subnet : ranges) {
563+
if (subnet.m_subnet.Match(addr)) {
564+
NetPermissions::AddFlag(flags, subnet.m_flags);
565+
}
566+
}
567+
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Implicit)) {
568+
NetPermissions::ClearFlag(flags, NetPermissionFlags::Implicit);
569+
if (whitelist_forcerelay) NetPermissions::AddFlag(flags, NetPermissionFlags::ForceRelay);
570+
if (whitelist_relay) NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
571+
NetPermissions::AddFlag(flags, NetPermissionFlags::Mempool);
572+
NetPermissions::AddFlag(flags, NetPermissionFlags::NoBan);
559573
}
560574
}
561575

@@ -1721,14 +1735,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
17211735
{
17221736
int nInbound = 0;
17231737

1724-
AddWhitelistPermissionFlags(permission_flags, addr);
1725-
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::Implicit)) {
1726-
NetPermissions::ClearFlag(permission_flags, NetPermissionFlags::Implicit);
1727-
if (gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) NetPermissions::AddFlag(permission_flags, NetPermissionFlags::ForceRelay);
1728-
if (gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) NetPermissions::AddFlag(permission_flags, NetPermissionFlags::Relay);
1729-
NetPermissions::AddFlag(permission_flags, NetPermissionFlags::Mempool);
1730-
NetPermissions::AddFlag(permission_flags, NetPermissionFlags::NoBan);
1731-
}
1738+
AddWhitelistPermissionFlags(permission_flags, addr, vWhitelistedRangeIncoming);
17321739

17331740
{
17341741
LOCK(m_nodes_mutex);
@@ -1783,15 +1790,10 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
17831790
NodeId id = GetNewNodeId();
17841791
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
17851792

1786-
ServiceFlags nodeServices = nLocalServices;
1787-
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::BloomFilter)) {
1788-
nodeServices = static_cast<ServiceFlags>(nodeServices | NODE_BLOOM);
1789-
}
1790-
17911793
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
17921794
// The V2Transport transparently falls back to V1 behavior when an incoming V1 connection is
17931795
// detected, so use it whenever we signal NODE_P2P_V2.
1794-
const bool use_v2transport(nodeServices & NODE_P2P_V2);
1796+
const bool use_v2transport(nLocalServices & NODE_P2P_V2);
17951797

17961798
CNode* pnode = new CNode(id,
17971799
std::move(sock),
@@ -1809,7 +1811,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
18091811
.use_v2transport = use_v2transport,
18101812
});
18111813
pnode->AddRef();
1812-
m_msgproc->InitializeNode(*pnode, nodeServices);
1814+
m_msgproc->InitializeNode(*pnode, nLocalServices);
18131815

18141816
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToStringAddrPort());
18151817

src/net.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class CNode;
5353
class CScheduler;
5454
struct bilingual_str;
5555

56-
/** Default for -whitelistrelay. */
57-
static const bool DEFAULT_WHITELISTRELAY = true;
58-
/** Default for -whitelistforcerelay. */
59-
static const bool DEFAULT_WHITELISTFORCERELAY = false;
60-
6156
/** Time after which to disconnect, after waiting for a ping response (or inactivity). */
6257
static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
6358
/** Run the feeler connection loop once every 2 minutes. **/
@@ -1053,7 +1048,8 @@ class CConnman
10531048
uint64_t nMaxOutboundLimit = 0;
10541049
int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
10551050
std::vector<std::string> vSeedNodes;
1056-
std::vector<NetWhitelistPermissions> vWhitelistedRange;
1051+
std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1052+
std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
10571053
std::vector<NetWhitebindPermissions> vWhiteBinds;
10581054
std::vector<CService> vBinds;
10591055
std::vector<CService> onion_binds;
@@ -1064,6 +1060,8 @@ class CConnman
10641060
std::vector<std::string> m_specified_outgoing;
10651061
std::vector<std::string> m_added_nodes;
10661062
bool m_i2p_accept_incoming;
1063+
bool whitelist_forcerelay = DEFAULT_WHITELISTFORCERELAY;
1064+
bool whitelist_relay = DEFAULT_WHITELISTRELAY;
10671065
};
10681066

10691067
void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
@@ -1087,7 +1085,8 @@ class CConnman
10871085
LOCK(m_total_bytes_sent_mutex);
10881086
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
10891087
}
1090-
vWhitelistedRange = connOptions.vWhitelistedRange;
1088+
vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
1089+
vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
10911090
{
10921091
LOCK(m_added_nodes_mutex);
10931092
// Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
@@ -1098,6 +1097,8 @@ class CConnman
10981097
}
10991098
}
11001099
m_onion_binds = connOptions.onion_binds;
1100+
whitelist_forcerelay = connOptions.whitelist_forcerelay;
1101+
whitelist_relay = connOptions.whitelist_relay;
11011102
}
11021103

11031104
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
@@ -1339,7 +1340,7 @@ class CConnman
13391340

13401341
bool AttemptToEvictConnection();
13411342
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1342-
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
1343+
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const;
13431344

13441345
void DeleteNode(CNode* pnode);
13451346

@@ -1398,7 +1399,9 @@ class CConnman
13981399

13991400
// Whitelisted ranges. Any node connecting from these is automatically
14001401
// whitelisted (as well as those connecting to whitelisted binds).
1401-
std::vector<NetWhitelistPermissions> vWhitelistedRange;
1402+
std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1403+
// Whitelisted ranges for outgoing connections.
1404+
std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
14021405

14031406
unsigned int nSendBufferMaxSize{0};
14041407
unsigned int nReceiveFloodSize{0};
@@ -1551,6 +1554,18 @@ class CConnman
15511554
*/
15521555
std::vector<CService> m_onion_binds;
15531556

1557+
/**
1558+
* flag for adding 'forcerelay' permission to whitelisted inbound
1559+
* and manual peers with default permissions.
1560+
*/
1561+
bool whitelist_forcerelay;
1562+
1563+
/**
1564+
* flag for adding 'relay' permission to whitelisted inbound
1565+
* and manual peers with default permissions.
1566+
*/
1567+
bool whitelist_relay;
1568+
15541569
/**
15551570
* Mutex protecting m_i2p_sam_sessions.
15561571
*/

src/net_permissions.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
2121
namespace {
2222

2323
// Parse the following format: "perm1,perm2@xxxxxx"
24-
bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, size_t& readen, bilingual_str& error)
24+
static bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output, ConnectionDirection* output_connection_direction, size_t& readen, bilingual_str& error)
2525
{
2626
NetPermissionFlags flags = NetPermissionFlags::None;
27+
ConnectionDirection connection_direction = ConnectionDirection::None;
2728
const auto atSeparator = str.find('@');
2829

2930
// if '@' is not found (ie, "xxxxx"), the caller should apply implicit permissions
@@ -52,6 +53,15 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
5253
else if (permission == "all") NetPermissions::AddFlag(flags, NetPermissionFlags::All);
5354
else if (permission == "relay") NetPermissions::AddFlag(flags, NetPermissionFlags::Relay);
5455
else if (permission == "addr") NetPermissions::AddFlag(flags, NetPermissionFlags::Addr);
56+
else if (permission == "in") connection_direction |= ConnectionDirection::In;
57+
else if (permission == "out") {
58+
if (output_connection_direction == nullptr) {
59+
// Only NetWhitebindPermissions() should pass a nullptr.
60+
error = _("whitebind may only be used for incoming connections (\"out\" was passed)");
61+
return false;
62+
}
63+
connection_direction |= ConnectionDirection::Out;
64+
}
5565
else if (permission.length() == 0); // Allow empty entries
5666
else {
5767
error = strprintf(_("Invalid P2P permission: '%s'"), permission);
@@ -61,7 +71,16 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
6171
readen++;
6272
}
6373

74+
// By default, whitelist only applies to incoming connections
75+
if (connection_direction == ConnectionDirection::None) {
76+
connection_direction = ConnectionDirection::In;
77+
} else if (flags == NetPermissionFlags::None) {
78+
error = strprintf(_("Only direction was set, no permissions: '%s'"), str);
79+
return false;
80+
}
81+
6482
output = flags;
83+
if (output_connection_direction) *output_connection_direction = connection_direction;
6584
error = Untranslated("");
6685
return true;
6786
}
@@ -85,7 +104,7 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
85104
{
86105
NetPermissionFlags flags;
87106
size_t offset;
88-
if (!TryParsePermissionFlags(str, flags, offset, error)) return false;
107+
if (!TryParsePermissionFlags(str, flags, /*output_connection_direction=*/nullptr, offset, error)) return false;
89108

90109
const std::string strBind = str.substr(offset);
91110
const std::optional<CService> addrBind{Lookup(strBind, 0, false)};
@@ -104,11 +123,12 @@ bool NetWhitebindPermissions::TryParse(const std::string& str, NetWhitebindPermi
104123
return true;
105124
}
106125

107-
bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error)
126+
bool NetWhitelistPermissions::TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error)
108127
{
109128
NetPermissionFlags flags;
110129
size_t offset;
111-
if (!TryParsePermissionFlags(str, flags, offset, error)) return false;
130+
// Only NetWhitebindPermissions should pass a nullptr for output_connection_direction.
131+
if (!TryParsePermissionFlags(str, flags, &output_connection_direction, offset, error)) return false;
112132

113133
const std::string net = str.substr(offset);
114134
const CSubNet subnet{LookupSubNet(net)};

src/net_permissions.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <netaddress.h>
6+
#include <netbase.h>
67

78
#include <string>
89
#include <type_traits>
@@ -15,6 +16,11 @@ struct bilingual_str;
1516

1617
extern const std::vector<std::string> NET_PERMISSIONS_DOC;
1718

19+
/** Default for -whitelistrelay. */
20+
constexpr bool DEFAULT_WHITELISTRELAY = true;
21+
/** Default for -whitelistforcerelay. */
22+
constexpr bool DEFAULT_WHITELISTFORCERELAY = false;
23+
1824
enum class NetPermissionFlags : uint32_t {
1925
None = 0,
2026
// Can query bloomfilter even if -peerbloomfilters is false
@@ -83,7 +89,7 @@ class NetWhitebindPermissions : public NetPermissions
8389
class NetWhitelistPermissions : public NetPermissions
8490
{
8591
public:
86-
static bool TryParse(const std::string& str, NetWhitelistPermissions& output, bilingual_str& error);
92+
static bool TryParse(const std::string& str, NetWhitelistPermissions& output, ConnectionDirection& output_connection_direction, bilingual_str& error);
8793
CSubNet m_subnet;
8894
};
8995

src/net_processing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,11 @@ void PeerManagerImpl::InitializeNode(CNode& node, ServiceFlags our_services)
15881588
m_node_states.emplace_hint(m_node_states.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(node.IsInboundConn()));
15891589
assert(m_txrequest.Count(nodeid) == 0);
15901590
}
1591+
1592+
if (NetPermissions::HasFlag(node.m_permission_flags, NetPermissionFlags::BloomFilter)) {
1593+
our_services = static_cast<ServiceFlags>(our_services | NODE_BLOOM);
1594+
}
1595+
15911596
PeerRef peer = std::make_shared<Peer>(nodeid, our_services);
15921597
{
15931598
LOCK(m_peer_mutex);

0 commit comments

Comments
 (0)