File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
7979static 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
8282namespace
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 =
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ());
Original file line number Diff line number Diff line change @@ -211,8 +211,10 @@ std::vector<PeerBareAddress>
211211PeerManager::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);
You can’t perform that action at this time.
0 commit comments