20#include <test/unit_test/SuiteJournal.h>
22#include <xrpld/core/Config.h>
23#include <xrpld/peerfinder/detail/Logic.h>
25#include <xrpl/basics/chrono.h>
26#include <xrpl/beast/unit_test/suite.h>
27#include <xrpl/protocol/PublicKey.h>
28#include <xrpl/protocol/SecretKey.h>
68 template <
class Handler>
72 boost::system::error_code ec;
80 auto const seconds = 10000;
100 BEAST_EXPECT(list.size() == 1);
111 BEAST_EXPECT(n < 20);
118 auto const seconds = 10000;
141 BEAST_EXPECT(list.size() == 1);
149 PeerFinder::Result::success))
158 BEAST_EXPECT(n <= (seconds + 59) / 60);
180 if (BEAST_EXPECT(!list.empty()))
182 BEAST_EXPECT(list.size() == 1);
183 auto const remote = list.front();
185 if (BEAST_EXPECT(slot1 !=
nullptr))
194 if (!BEAST_EXPECT(slot2 ==
nullptr))
220 if (BEAST_EXPECT(!list.empty()))
222 BEAST_EXPECT(list.size() == 1);
223 auto const remote = list.front();
227 if (BEAST_EXPECT(slot1 !=
nullptr))
234 if (!BEAST_EXPECT(slot2 ==
nullptr))
262 max = maxPeers.value();
265 "\n" +
"[peers_out_max]\n" +
268 else if (maxIn && maxOut)
285 counts.
out_max() == expectOut &&
287 config.
ipLimit == expectIpLimit);
300 run(
"legacy no config", {}, {}, {}, 4000, 10, 11, 2);
301 run(
"legacy max_peers 0", 0, 100, 10, 4000, 10, 11, 2);
302 run(
"legacy max_peers 5", 5, 100, 10, 4000, 10, 0, 1);
303 run(
"legacy max_peers 20", 20, 100, 10, 4000, 10, 10, 2);
304 run(
"legacy max_peers 100", 100, 100, 10, 4000, 15, 85, 6);
305 run(
"legacy max_peers 20, private", 20, 100, 10, 0, 20, 0, 1);
308 run(
"new in 100/out 10", {}, 100, 10, 4000, 10, 100, 6);
309 run(
"new in 0/out 10", {}, 0, 10, 4000, 10, 0, 1);
310 run(
"new in 100/out 10, private", {}, 100, 10, 0, 10, 0, 6);
370BEAST_DEFINE_TESTSUITE(PeerFinder, PeerFinder,
ripple);
A version-independent IP address and port combination.
static Endpoint from_string(std::string const &s)
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
std::size_t PEERS_OUT_MAX
Manages the count of available connections for the various slots.
int inboundSlots() const
Returns the total number of inbound slots.
int out_max() const
Returns the total number of outbound slots.
void onConfig(Config const &config)
Called when the config is set or changed.
The Logic for maintaining the list of Slot addresses.
bool onConnected(SlotImp::ptr const &slot, beast::IP::Endpoint const &local_endpoint)
void on_closed(SlotImp::ptr const &slot)
SlotImp::ptr new_outbound_slot(beast::IP::Endpoint const &remote_endpoint)
Result activate(SlotImp::ptr const &slot, PublicKey const &key, bool reserved)
std::multiset< beast::IP::Address > connectedAddresses_
std::vector< beast::IP::Endpoint > autoconnect()
Create new outbound connection attempts as needed.
SlotImp::ptr new_inbound_slot(beast::IP::Endpoint const &local_endpoint, beast::IP::Endpoint const &remote_endpoint)
void addFixedPeer(std::string const &name, beast::IP::Endpoint const &ep)
void config(Config const &c)
test::SuiteJournal journal_
void test_duplicateInOut()
void test_invalid_config()
void test_duplicateOutIn()
void run() override
Runs the suite.
Abstract persistence for PeerFinder data.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
PeerFinder configuration settings.
bool autoConnect
true if we want to establish connections automatically
int ipLimit
Limit how many incoming connections we allow per IP.
static Config makeConfig(ripple::Config const &config, std::uint16_t port, bool validationPublicKey, int ipLimit)
Make PeerFinder::Config from configuration parameters.
std::uint16_t listeningPort
The listening port number.
void async_connect(beast::IP::Endpoint const &ep, Handler &&handler)
void save(std::vector< Entry > const &) override
std::size_t load(load_callback const &cb) override