Skip to content

Commit cf1569e

Browse files
committed
Add addr permission flag enabling non-cached addr sharing
1 parent acd6135 commit cf1569e

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class CConnman
258258
/**
259259
* Cache is used to minimize topology leaks, so it should
260260
* be used for all non-trusted calls, for example, p2p.
261-
* A non-malicious call (from RPC) should
261+
* A non-malicious call (from RPC or a peer with addr permission) should
262262
* call the function without a parameter to avoid using the cache.
263263
*/
264264
std::vector<CAddress> GetAddresses(Network requestor_network);

src/net_permissions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const std::vector<std::string> NET_PERMISSIONS_DOC{
1515
"relay (relay even in -blocksonly mode)",
1616
"mempool (allow requesting BIP35 mempool contents)",
1717
"download (allow getheaders during IBD, no disconnect after maxuploadtarget limit)",
18+
"addr (responses to GETADDR avoid hitting the cache and contain random records with the most up-to-date info)"
1819
};
1920

2021
namespace {
@@ -50,6 +51,7 @@ bool TryParsePermissionFlags(const std::string str, NetPermissionFlags& output,
5051
else if (permission == "download") NetPermissions::AddFlag(flags, PF_DOWNLOAD);
5152
else if (permission == "all") NetPermissions::AddFlag(flags, PF_ALL);
5253
else if (permission == "relay") NetPermissions::AddFlag(flags, PF_RELAY);
54+
else if (permission == "addr") NetPermissions::AddFlag(flags, PF_ADDR);
5355
else if (permission.length() == 0); // Allow empty entries
5456
else {
5557
error = strprintf(_("Invalid P2P permission: '%s'"), permission);
@@ -75,6 +77,7 @@ std::vector<std::string> NetPermissions::ToStrings(NetPermissionFlags flags)
7577
if (NetPermissions::HasFlag(flags, PF_RELAY)) strings.push_back("relay");
7678
if (NetPermissions::HasFlag(flags, PF_MEMPOOL)) strings.push_back("mempool");
7779
if (NetPermissions::HasFlag(flags, PF_DOWNLOAD)) strings.push_back("download");
80+
if (NetPermissions::HasFlag(flags, PF_ADDR)) strings.push_back("addr");
7881
return strings;
7982
}
8083

src/net_permissions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ enum NetPermissionFlags {
2929
PF_NOBAN = (1U << 4) | PF_DOWNLOAD,
3030
// Can query the mempool
3131
PF_MEMPOOL = (1U << 5),
32+
// Can request addrs without hitting a privacy-preserving cache
33+
PF_ADDR = (1U << 7),
3234

3335
// True if the user did not specifically set fine grained permissions
3436
PF_ISIMPLICIT = (1U << 31),
35-
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL | PF_DOWNLOAD,
37+
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL | PF_DOWNLOAD | PF_ADDR,
3638
};
3739

3840
class NetPermissions

src/net_processing.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3477,7 +3477,12 @@ void ProcessMessage(
34773477
pfrom.fSentAddr = true;
34783478

34793479
pfrom.vAddrToSend.clear();
3480-
std::vector<CAddress> vAddr = connman.GetAddresses(pfrom.addr.GetNetwork());
3480+
std::vector<CAddress> vAddr;
3481+
if (pfrom.HasPermission(PF_ADDR)) {
3482+
vAddr = connman.GetAddresses();
3483+
} else {
3484+
vAddr = connman.GetAddresses(pfrom.addr.GetNetwork());
3485+
}
34813486
FastRandomContext insecure_rand;
34823487
for (const CAddress &addr : vAddr) {
34833488
pfrom.PushAddress(addr, insecure_rand);

src/test/fuzz/net_permissions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
2424
NetPermissionFlags::PF_FORCERELAY,
2525
NetPermissionFlags::PF_NOBAN,
2626
NetPermissionFlags::PF_MEMPOOL,
27+
NetPermissionFlags::PF_ADDR,
2728
NetPermissionFlags::PF_ISIMPLICIT,
2829
NetPermissionFlags::PF_ALL,
2930
}) :

src/test/netbase_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@ BOOST_AUTO_TEST_CASE(netpermissions_test)
397397
BOOST_CHECK(NetWhitelistPermissions::TryParse("bloom,forcerelay,noban,relay,[email protected]/32", whitelistPermissions, error));
398398

399399
const auto strings = NetPermissions::ToStrings(PF_ALL);
400-
BOOST_CHECK_EQUAL(strings.size(), 6U);
400+
BOOST_CHECK_EQUAL(strings.size(), 7U);
401401
BOOST_CHECK(std::find(strings.begin(), strings.end(), "bloomfilter") != strings.end());
402402
BOOST_CHECK(std::find(strings.begin(), strings.end(), "forcerelay") != strings.end());
403403
BOOST_CHECK(std::find(strings.begin(), strings.end(), "relay") != strings.end());
404404
BOOST_CHECK(std::find(strings.begin(), strings.end(), "noban") != strings.end());
405405
BOOST_CHECK(std::find(strings.begin(), strings.end(), "mempool") != strings.end());
406406
BOOST_CHECK(std::find(strings.begin(), strings.end(), "download") != strings.end());
407+
BOOST_CHECK(std::find(strings.begin(), strings.end(), "addr") != strings.end());
407408
}
408409

409410
BOOST_AUTO_TEST_CASE(netbase_dont_resolve_strings_with_embedded_nul_characters)

test/functional/p2p_permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def run_test(self):
9696
self.checkpermission(
9797
# all permission added
9898
99-
["forcerelay", "noban", "mempool", "bloomfilter", "relay", "download"],
99+
["forcerelay", "noban", "mempool", "bloomfilter", "relay", "download", "addr"],
100100
False)
101101

102102
self.stop_node(1)

0 commit comments

Comments
 (0)