Skip to content

Commit 8e11ec9

Browse files
committed
Allow private addresses for testing
1 parent d6f2546 commit 8e11ec9

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎src/main/Config.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static std::unordered_set<std::string> const TESTING_ONLY_OPTIONS = {
7777

7878
// Options that should only be used for testing
7979
static std::unordered_set<std::string> const TESTING_SUGGESTED_OPTIONS = {
80-
"ALLOW_LOCALHOST_FOR_TESTING"};
80+
"ALLOW_LOCALHOST_FOR_TESTING", "ALLOW_PRIVATE_ADDRESSES_FOR_TESTING"};
8181

8282
namespace
8383
{
@@ -199,6 +199,7 @@ Config::Config() : NODE_SEED(SecretKey::random())
199199
std::chrono::seconds::zero();
200200
ARTIFICIALLY_DELAY_LEDGER_CLOSE_FOR_TESTING = std::chrono::milliseconds(0);
201201
ALLOW_LOCALHOST_FOR_TESTING = false;
202+
ALLOW_PRIVATE_ADDRESSES_FOR_TESTING = false;
202203
USE_CONFIG_FOR_GENESIS = false;
203204
GENESIS_TEST_ACCOUNT_COUNT = 0;
204205
FAILURE_SAFETY = -1;
@@ -1315,6 +1316,10 @@ Config::processConfig(std::shared_ptr<cpptoml::table> t)
13151316
}},
13161317
{"ALLOW_LOCALHOST_FOR_TESTING",
13171318
[&]() { ALLOW_LOCALHOST_FOR_TESTING = readBool(item); }},
1319+
{"ALLOW_PRIVATE_ADDRESSES_FOR_TESTING",
1320+
[&]() {
1321+
ALLOW_PRIVATE_ADDRESSES_FOR_TESTING = readBool(item);
1322+
}},
13181323
{"PUBLISH_TO_ARCHIVE_DELAY",
13191324
[&]() {
13201325
PUBLISH_TO_ARCHIVE_DELAY =

‎src/main/Config.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,13 @@ class Config : public std::enable_shared_from_this<Config>
575575
// this should only be enabled when testing as it's a security issue
576576
bool ALLOW_LOCALHOST_FOR_TESTING;
577577

578+
// A config to allow gossiping (advertising and accepting in PEERS
579+
// messages) and connecting to RFC1918 private addresses (10/8, 172.16/12,
580+
// 192.168/16). Private addresses are normally filtered out of peer
581+
// exchange, which disables gossip-based peer discovery in environments
582+
// where every node has a private address (e.g. a Kubernetes pod network).
583+
bool ALLOW_PRIVATE_ADDRESSES_FOR_TESTING;
584+
578585
// Set to use config file values for genesis ledger
579586
// not setable in config file - only tests are allowed to do this
580587
bool USE_CONFIG_FOR_GENESIS;

‎src/overlay/Peer.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,8 @@ Peer::recvPeers(StellarMessage const& msg)
20182018
releaseAssert(peer.ip.type() == IPv4);
20192019
auto address = PeerBareAddress{peer};
20202020

2021-
if (address.isPrivate())
2021+
if (address.isPrivate() &&
2022+
!mAppConnector.getConfig().ALLOW_PRIVATE_ADDRESSES_FOR_TESTING)
20222023
{
20232024
CLOG_DEBUG(Overlay, "ignoring received private address {}",
20242025
address.toString());

‎src/overlay/PeerManager.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ std::vector<PeerBareAddress>
211211
PeerManager::getPeersToSend(size_t size, PeerBareAddress const& address)
212212
{
213213
ZoneScoped;
214+
bool const allowPrivate =
215+
mApp.getConfig().ALLOW_PRIVATE_ADDRESSES_FOR_TESTING;
214216
auto keep = [&](PeerBareAddress const& pba) {
215-
return !pba.isPrivate() && pba != address;
217+
return (allowPrivate || !pba.isPrivate()) && pba != address;
216218
};
217219

218220
auto peers = mOutboundPeersToSend->getRandomPeers(size, keep);

0 commit comments

Comments
 (0)