Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static std::unordered_set<std::string> const TESTING_ONLY_OPTIONS = {

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

namespace
{
Expand Down Expand Up @@ -155,6 +155,7 @@ Config::Config() : NODE_SEED(SecretKey::random())
IGNORE_MESSAGE_LIMITS_FOR_TESTING = false;
TESTING_IGNORE_LEDGER_TIME_UPGRADE_BOUNDS = false;
TESTING_NOMINATE_RANDOM_VALUES = false;
ALLOW_PRIVATE_ADDRESSES_FOR_TESTING = false;
#endif

FORCE_SCP = false;
Expand Down Expand Up @@ -1278,6 +1279,10 @@ Config::processConfig(std::shared_ptr<cpptoml::table> t)
}},
{"IGNORE_MESSAGE_LIMITS_FOR_TESTING",
[&]() { IGNORE_MESSAGE_LIMITS_FOR_TESTING = readBool(item); }},
{"ALLOW_PRIVATE_ADDRESSES_FOR_TESTING",
[&]() {
ALLOW_PRIVATE_ADDRESSES_FOR_TESTING = readBool(item);
}},
#endif // BUILD_TESTS
{"ARTIFICIALLY_GENERATE_LOAD_FOR_TESTING",
[&]() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,13 @@ class Config : public std::enable_shared_from_this<Config>
// When set to true, ignores all message and tx set size limits for testing
bool IGNORE_MESSAGE_LIMITS_FOR_TESTING;

// A config to allow gossiping (advertising and accepting in PEERS
// messages) and connecting to RFC1918 private addresses (10/8, 172.16/12,
// 192.168/16). Private addresses are normally filtered out of peer
// exchange, which disables gossip-based peer discovery in environments
// where every node has a private address (e.g. a Kubernetes pod network).
bool ALLOW_PRIVATE_ADDRESSES_FOR_TESTING;

// When set, disables validation of the ledger target close time
// bounds on config upgrades (for testing only).
bool TESTING_IGNORE_LEDGER_TIME_UPGRADE_BOUNDS;
Expand Down
7 changes: 6 additions & 1 deletion src/overlay/Peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,12 @@ Peer::recvPeers(StellarMessage const& msg)
releaseAssert(peer.ip.type() == IPv4);
auto address = PeerBareAddress{peer};

if (address.isPrivate())
bool allowPrivateAddresses = false;
#ifdef BUILD_TESTS
allowPrivateAddresses =
mAppConnector.getConfig().ALLOW_PRIVATE_ADDRESSES_FOR_TESTING;
#endif
if (address.isPrivate() && !allowPrivateAddresses)
{
CLOG_DEBUG(Overlay, "ignoring received private address {}",
address.toString());
Expand Down
6 changes: 5 additions & 1 deletion src/overlay/PeerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ std::vector<PeerBareAddress>
PeerManager::getPeersToSend(size_t size, PeerBareAddress const& address)
{
ZoneScoped;
bool allowPrivate = false;
#ifdef BUILD_TESTS
allowPrivate = mApp.getConfig().ALLOW_PRIVATE_ADDRESSES_FOR_TESTING;
#endif
auto keep = [&](PeerBareAddress const& pba) {
return !pba.isPrivate() && pba != address;
return (allowPrivate || !pba.isPrivate()) && pba != address;
};

auto peers = mOutboundPeersToSend->getRandomPeers(size, keep);
Expand Down
Loading