1#include <xrpld/overlay/detail/OverlayImpl.h>
3#include <xrpld/app/misc/ValidatorList.h>
4#include <xrpld/app/misc/ValidatorSite.h>
5#include <xrpld/overlay/Cluster.h>
6#include <xrpld/overlay/detail/ConnectAttempt.h>
7#include <xrpld/overlay/detail/Handshake.h>
8#include <xrpld/overlay/detail/PeerImp.h>
9#include <xrpld/overlay/detail/ProtocolVersion.h>
10#include <xrpld/overlay/detail/TrafficCount.h>
11#include <xrpld/overlay/detail/Tuning.h>
12#include <xrpld/peerfinder/PeerfinderManager.h>
13#include <xrpld/rpc/ServerHandler.h>
14#include <xrpld/rpc/handlers/admin/status/GetCounts.h>
15#include <xrpld/rpc/json_body.h>
17#include <xrpl/basics/Log.h>
18#include <xrpl/basics/Resolver.h>
19#include <xrpl/basics/Slice.h>
20#include <xrpl/basics/base64.h>
21#include <xrpl/basics/base_uint.h>
22#include <xrpl/basics/chrono.h>
23#include <xrpl/basics/contract.h>
24#include <xrpl/basics/make_SSLContext.h>
25#include <xrpl/basics/random.h>
26#include <xrpl/basics/strHex.h>
27#include <xrpl/beast/core/LexicalCast.h>
28#include <xrpl/beast/insight/Collector.h>
29#include <xrpl/beast/net/IPAddress.h>
30#include <xrpl/beast/net/IPAddressConversion.h>
31#include <xrpl/beast/net/IPEndpoint.h>
32#include <xrpl/beast/rfc2616.h>
33#include <xrpl/beast/utility/PropertyStream.h>
34#include <xrpl/beast/utility/WrappedSink.h>
35#include <xrpl/beast/utility/instrumentation.h>
36#include <xrpl/config/BasicConfig.h>
37#include <xrpl/config/Constants.h>
38#include <xrpl/core/HashRouter.h>
39#include <xrpl/json/json_value.h>
40#include <xrpl/peerfinder/Config.h>
41#include <xrpl/peerfinder/Slot.h>
42#include <xrpl/peerfinder/make_Manager.h>
43#include <xrpl/protocol/BuildInfo.h>
44#include <xrpl/protocol/STTx.h>
45#include <xrpl/protocol/Serializer.h>
46#include <xrpl/protocol/SystemParameters.h>
47#include <xrpl/protocol/jss.h>
48#include <xrpl/resource/Fees.h>
49#include <xrpl/resource/ResourceManager.h>
50#include <xrpl/server/Handoff.h>
51#include <xrpl/server/Manifest.h>
52#include <xrpl/server/NetworkOPs.h>
53#include <xrpl/server/SimpleWriter.h>
54#include <xrpl/server/Wallet.h>
55#include <xrpl/server/Writer.h>
57#include <boost/algorithm/string/predicate.hpp>
58#include <boost/asio/bind_executor.hpp>
59#include <boost/asio/dispatch.hpp>
60#include <boost/asio/error.hpp>
61#include <boost/asio/executor_work_guard.hpp>
62#include <boost/asio/io_context.hpp>
63#include <boost/asio/ip/address.hpp>
64#include <boost/asio/post.hpp>
65#include <boost/asio/strand.hpp>
66#include <boost/beast/http/empty_body.hpp>
67#include <boost/beast/http/field.hpp>
68#include <boost/beast/http/status.hpp>
69#include <boost/lexical_cast.hpp>
70#include <boost/lexical_cast/bad_lexical_cast.hpp>
71#include <boost/lexical_cast/try_lexical_convert.hpp>
104static constexpr auto kUnl = (1 << 3);
138 boost::asio::bind_executor(
148 if (ec && ec != boost::asio::error::operation_aborted)
150 JLOG(
overlay_.journal_.error()) <<
"on_timer: " << ec.message();
155 overlay_.peerFinder_->oncePerSecond();
158 if (
overlay_.app_.config().txReduceRelayEnable)
175 boost::asio::io_context& ioContext,
191 app_.getJournal(
"PeerFinder"),
196 ,
slots_(app, *this, app.config())
200 [counts = traffic_.getCounts(), collector] {
203 for (
auto const& pair : counts)
204 ret.
emplace(pair.first, TrafficGauges(pair.second.name, collector));
220 auto const peerJournal =
app_.getJournal(
"Peer");
230 handoff.
moved =
true;
232 JLOG(journal.
debug()) <<
"Peer connection upgrade from " << remoteEndpoint;
235 auto const localEndpoint(streamPtr->next_layer().socket().local_endpoint(ec));
238 JLOG(journal.
debug()) << remoteEndpoint <<
" failed: " << ec.message();
244 if (consumer.disconnect(journal))
247 auto const [slot, result] =
peerFinder_->newInboundSlot(
254 handoff.
moved =
false;
255 JLOG(journal.
debug()) <<
"Peer " << remoteEndpoint <<
" refused, " <<
to_string(result);
264 return boost::iequals(s,
"peer");
267 handoff.
moved =
false;
275 if (!negotiatedVersion)
278 handoff.
moved =
false;
280 slot, request, remoteEndpoint.address(),
"Unable to agree on a protocol version");
289 handoff.
moved =
false;
291 makeErrorResponse(slot, request, remoteEndpoint.address(),
"Incorrect security cookie");
303 remoteEndpoint.address(),
306 consumer.setPublicKey(publicKey);
311 bool const reserved =
app_.getCluster().isMember(publicKey) ||
312 app_.getPeerReservations().contains(publicKey);
313 auto const result =
peerFinder_->activate(slot, publicKey, reserved);
314 if (result != peer_finder::Result::Success)
317 JLOG(journal.
debug())
318 <<
"Peer " << remoteEndpoint <<
" redirected, " <<
to_string(result);
319 handoff.
moved =
false;
334 std::move(streamPtr),
342 auto const result =
peers_.emplace(peer->slot(), peer);
343 XRPL_ASSERT(result.second,
"xrpl::OverlayImpl::onHandoff : peer is inserted");
346 list_.emplace(peer.get(), peer);
350 handoff.
moved =
true;
355 JLOG(journal.
debug()) <<
"Peer " << remoteEndpoint <<
" fails handshake (" << e.
what()
359 handoff.
moved =
false;
374 return !versions.empty();
391 boost::beast::http::response<JsonBody> msg;
392 msg.version(request.version());
393 msg.result(boost::beast::http::status::service_unavailable);
397 ostr << remoteAddress;
398 msg.insert(
"Remote-Address", ostr.
str());
400 msg.insert(
"Content-Type",
"application/json");
401 msg.insert(boost::beast::http::field::connection,
"close");
406 ips.
append(_.address.toString());
408 msg.prepare_payload();
419 boost::beast::http::response<boost::beast::http::empty_body> msg;
420 msg.version(request.version());
421 msg.result(boost::beast::http::status::bad_request);
422 msg.reason(
"Bad Request (" + text +
")");
424 msg.insert(
"Remote-Address", remoteAddress.to_string());
425 msg.insert(boost::beast::http::field::connection,
"close");
426 msg.prepare_payload();
435 XRPL_ASSERT(
work_,
"xrpl::OverlayImpl::connect : work is set");
440 JLOG(
journal_.info()) <<
"Over resource limit: " << remoteEndpoint;
447 JLOG(
journal_.debug()) <<
"Connect: No slot for " << remoteEndpoint <<
": "
460 app_.getJournal(
"Peer"),
464 list_.emplace(p.get(), p);
480 auto const result =
peers_.emplace(peer->slot(), peer);
481 XRPL_ASSERT(result.second,
"xrpl::OverlayImpl::addActive : peer is inserted");
486 auto const result =
ids_.emplace(
488 XRPL_ASSERT(result.second,
"xrpl::OverlayImpl::addActive : peer ID is inserted");
494 JLOG(journal.
debug()) <<
"activated";
506 auto const iter =
peers_.find(slot);
507 XRPL_ASSERT(iter !=
peers_.end(),
"xrpl::OverlayImpl::remove : valid input");
513 "r.ripple.com 51235",
514 "sahyadri.isrdc.in 51235",
515 "hubs.xrpkuwait.com 51235",
516 "hub.xrpl-commons.org 51235",
525 for (
auto const& addr : addresses)
526 endpoints.
push_back(addr.port() == 0 ? addr.atPort(kDefaultPeerPort) : addr);
536 app_.getValidationPublicKey().has_value(),
544 if (!
app_.config().standalone())
548 auto bootstrapIps =
app_.config().ips.empty() ?
app_.config().ipsFixed :
app_.config().ips;
549 if (bootstrapIps.empty())
566 if (!
app_.config().ipsFixed.empty())
569 app_.config().ipsFixed,
571 auto const ips = withDefaultPeerPort(addresses);
573 peerFinder_->addFixedPeer(name, ips);
580 list_.emplace(timer.get(), timer);
591 cond_.wait(lock, [
this] {
return list_.empty(); });
606 auto const stats =
traffic_.getCounts();
607 for (
auto const& pair : stats)
610 item[
"category"] = pair.second.name;
612 item[
"messages_in"] =
std::to_string(pair.second.messagesIn.load());
614 item[
"messages_out"] =
std::to_string(pair.second.messagesOut.load());
634 auto const result(
ids_.emplace(
636 XRPL_ASSERT(result.second,
"xrpl::OverlayImpl::activate : peer ID is inserted");
640 JLOG(journal.
debug()) <<
"activated";
643 XRPL_ASSERT(
size(),
"xrpl::OverlayImpl::activate : nonzero peers");
658 auto const& journal = from->pJournal();
665 auto const total =
static_cast<std::size_t>(m->list_size());
667 bool skippedUntrusted =
false;
669 protocol::TMManifests
relay;
673 auto& s = m->list().Get(i).stobject();
677 auto const serialized = mo->serialized;
681 bool const isTrusted =
app_.getValidators().listed(mo->masterKey);
688 if (untrusted >= maxUntrusted)
690 skippedUntrusted =
true;
696 auto const result =
app_.getValidatorManifests().applyManifest(
709 "xrpl::OverlayImpl::onManifests : manifest "
710 "deserialization succeeded");
712 app_.getOPs().pubManifest(*mo);
715 relay.add_list()->set_stobject(s);
721 auto db =
app_.getWalletDB().checkoutDb();
728 JLOG(journal.debug()) <<
"Malformed manifest #" << i + 1 <<
": " <<
strHex(s);
733 if (skippedUntrusted)
739 JLOG(journal.warn()) <<
"Manifests: message had " << total
740 <<
" entries; processed all trusted plus the first " << maxUntrusted
744 if (!
relay.list().empty())
789 pv[jss::public_key] =
base64Encode(sp->getNodePublic().data(), sp->getNodePublic().size());
790 pv[jss::type] = sp->slot()->inbound() ? jss::in : jss::out;
794 pv[jss::ip] = sp->getRemoteAddress().address().to_string();
795 if (sp->slot()->inbound())
797 if (
auto port = sp->slot()->listeningPort())
798 pv[jss::port] = *port;
802 pv[jss::port] = sp->getRemoteAddress().port();
807 auto const version{sp->getVersion()};
808 if (!version.empty())
816 sp->ledgerRange(minSeq, maxSeq);
817 if (minSeq != 0 || maxSeq != 0)
827 bool const humanReadable =
false;
828 bool const admin =
false;
829 bool const counters =
false;
831 json::Value serverInfo =
app_.getOPs().getServerInfo(humanReadable, admin, counters);
835 serverInfo.
removeMember(jss::load_factor_fee_escalation);
839 if (serverInfo.
isMember(jss::validated_ledger))
841 json::Value& validatedLedger = serverInfo[jss::validated_ledger];
862 if (validators.
isMember(jss::publisher_lists))
864 json::Value& publisherLists = validators[jss::publisher_lists];
866 for (
auto& publisher : publisherLists)
868 publisher.removeMember(jss::list);
878 if (validatorSites.
isMember(jss::validator_sites))
880 validators[jss::validator_sites] = std::move(validatorSites[jss::validator_sites]);
893 json.append(peer->json());
904 boost::beast::http::response<JsonBody> msg;
905 msg.version(req.version());
906 msg.result(boost::beast::http::status::ok);
908 msg.insert(
"Content-Type",
"application/json");
909 msg.insert(
"Connection",
"close");
929 msg.prepare_payload();
941 if (!req.target().starts_with(kPrefix) || !
setup_.vlEnabled)
946 boost::beast::http::response<JsonBody> msg;
947 msg.version(req.version());
949 msg.insert(
"Content-Type",
"application/json");
950 msg.insert(
"Connection",
"close");
952 auto const fail = [&msg, &handoff](
auto status) {
954 msg.insert(
"Content-Length",
"0");
958 msg.prepare_payload();
965 if (
auto const slash = key.
find(
'/'); slash != std::string_view::npos)
967 auto const verString = key.
substr(0, slash);
968 if (!boost::conversion::try_lexical_convert(verString, version))
969 return fail(boost::beast::http::status::bad_request);
970 key = key.
substr(slash + 1);
974 return fail(boost::beast::http::status::bad_request);
977 auto vl =
app_.getValidators().getAvailable(key, version);
982 return fail(boost::beast::http::status::not_found);
986 return fail(boost::beast::http::status::bad_request);
989 msg.result(boost::beast::http::status::ok);
993 msg.prepare_payload();
1001 if (req.target() !=
"/health")
1003 boost::beast::http::response<JsonBody> msg;
1004 msg.version(req.version());
1006 msg.insert(
"Content-Type",
"application/json");
1007 msg.insert(
"Connection",
"close");
1011 int lastValidatedLedgerAge = -1;
1012 if (info.isMember(jss::validated_ledger))
1013 lastValidatedLedgerAge = info[jss::validated_ledger][jss::age].asInt();
1014 bool amendmentBlocked =
false;
1015 if (info.isMember(jss::amendment_blocked))
1016 amendmentBlocked =
true;
1017 int const numberPeers = info[jss::peers].asInt();
1018 std::string const serverState = info[jss::server_state].asString();
1019 auto const loadFactor =
1020 info[jss::load_factor_server].asDouble() / info[jss::load_base].asDouble();
1022 enum class HealthState { Healthy, Warning, Critical };
1023 auto health = HealthState::Healthy;
1024 auto const setHealth = [&health](HealthState state) { health =
std::max(health, state); };
1027 if (lastValidatedLedgerAge >= 7 || lastValidatedLedgerAge < 0)
1029 msg.body()[jss::info][jss::validated_ledger] = lastValidatedLedgerAge;
1030 if (lastValidatedLedgerAge < 20)
1032 setHealth(HealthState::Warning);
1036 setHealth(HealthState::Critical);
1040 if (amendmentBlocked)
1042 msg.body()[jss::info][jss::amendment_blocked] =
true;
1043 setHealth(HealthState::Critical);
1046 if (numberPeers <= 7)
1048 msg.body()[jss::info][jss::peers] = numberPeers;
1049 if (numberPeers != 0)
1051 setHealth(HealthState::Warning);
1055 setHealth(HealthState::Critical);
1059 if (!(serverState ==
"full" || serverState ==
"validating" || serverState ==
"proposing"))
1061 msg.body()[jss::info][jss::server_state] = serverState;
1062 if (serverState ==
"syncing" || serverState ==
"tracking" || serverState ==
"connected")
1064 setHealth(HealthState::Warning);
1068 setHealth(HealthState::Critical);
1072 if (loadFactor > 100)
1074 msg.body()[jss::info][jss::load_factor] = loadFactor;
1075 if (loadFactor < 1000)
1077 setHealth(HealthState::Warning);
1081 setHealth(HealthState::Critical);
1087 case HealthState::Healthy:
1088 msg.result(boost::beast::http::status::ok);
1090 case HealthState::Warning:
1091 msg.result(boost::beast::http::status::service_unavailable);
1093 case HealthState::Critical:
1094 msg.result(boost::beast::http::status::internal_server_error);
1098 msg.prepare_payload();
1132 active =
ids_.size();
1133 disabled = enabledInSkip = 0;
1138 for (
auto& [
id, w] :
ids_)
1140 if (p = w.lock(); p !=
nullptr)
1142 bool const reduceRelayEnabled = p->txReduceRelayEnabled();
1144 if (!reduceRelayEnabled)
1151 else if (reduceRelayEnabled)
1171 auto const iter =
ids_.find(
id);
1172 if (iter !=
ids_.end())
1173 return iter->second.lock();
1185 for (
auto const& e :
ids_)
1187 if (peer = e.second.lock(); peer !=
nullptr)
1189 if (peer->getNodePublic() == pubKey)
1206 if (
auto const toSkip =
app_.getHashRouter().shouldRelay(uid))
1210 if (!toSkip->contains(p->id()))
1228 if (
auto const toSkip =
app_.getHashRouter().shouldRelay(uid))
1232 if (!toSkip->contains(p->id()))
1253 struct CachedManifest
1260 app_.getValidatorManifests().forEachManifest(
1262 [&cached](
Manifest const& manifest) {
1264 .masterKey = manifest.masterKey,
1265 .serialized = manifest.serialized,
1266 .hash = manifest.hash(),
1276 for (
auto const& e : cached)
1278 if (
app_.getValidators().listed(e.masterKey))
1296 protocol::TMManifests
tm;
1297 auto& hr =
app_.getHashRouter();
1298 tm.mutable_list()->Reserve(
static_cast<int>(selected.
size()));
1299 for (
auto const* e : selected)
1301 tm.add_list()->set_stobject(e->serialized.data(), e->serialized.size());
1302 hr.addSuppression(e->hash);
1307 if (
tm.list_size() != 0)
1324 auto const& txn = tx->get();
1334 JLOG(
journal_.debug()) <<
"Could not construct STTx: " <<
hash;
1345 protocol::TMTransaction
const& m,
1364 bool const relay = tx.has_value();
1373 if (!
app_.config().txReduceRelayEnable)
1377 JLOG(
journal_.trace()) <<
"not relaying tx, total peers " << peers.
size();
1378 for (
auto const& p : peers)
1380 if (p->txReduceRelayEnabled())
1381 p->addTxQueue(
hash);
1386 auto const& txn = tx->get();
1389 auto const minRelay =
app_.config().txReduceRelayMinPeers + disabled;
1391 if (!
app_.config().txReduceRelayEnable || total <= minRelay)
1393 for (
auto const& p : peers)
1395 if (
app_.config().txReduceRelayEnable ||
app_.config().txReduceRelayMetrics)
1403 auto const enabledTarget =
app_.config().txReduceRelayMinPeers +
1404 ((total - minRelay) *
app_.config().txRelayPercentage / 100);
1408 if (enabledTarget > enabledInSkip)
1411 JLOG(
journal_.trace()) <<
"relaying tx, total peers " << peers.
size() <<
" selected "
1412 << enabledTarget <<
" skip " << toSkip.
size() <<
" disabled "
1417 for (
auto const& p : peers)
1420 if (!p->txReduceRelayEnabled())
1424 else if (enabledAndRelayed < enabledTarget)
1426 enabledAndRelayed++;
1431 p->addTxQueue(
hash);
1442 list_.erase(&child);
1463 work_ = std::nullopt;
1466 for (
auto const& element :
list_)
1472 for (
auto const& child : children)
1474 if (child !=
nullptr)
1483 for (
auto const& addr : result)
1490 auto const result =
peerFinder_->buildEndpointsForPeers();
1491 for (
auto const& e : result)
1496 auto const iter =
peers_.find(e.first);
1497 if (iter !=
peers_.end())
1498 peer = iter->second.lock();
1501 peer->sendEndpoints(e.second.begin(), e.second.end());
1509 if (p->txReduceRelayEnabled())
1517 protocol::TMSquelch m;
1519 m.set_validatorpubkey(validator.data(), validator.size());
1521 m.set_squelchduration(squelchDuration);
1550 protocol::MessageType type)
1552 if (!
slots_.baseSquelchReady())
1555 if (!
strand_.running_in_this_thread())
1560 [
this, key = key, validator = validator, peers = std::move(peers), type]
mutable {
1567 for (
auto const id : peers)
1569 slots_.updateSlotAndSquelch(key, validator,
id, type, [&] {
1580 protocol::MessageType type)
1582 if (!
slots_.baseSquelchReady())
1585 if (!
strand_.running_in_this_thread())
1591 [
this, key = key, validator = validator, peer, type] {
1598 slots_.updateSlotAndSquelch(key, validator, peer, type, [&] {
1606 if (!
strand_.running_in_this_thread())
1612 slots_.deletePeer(
id,
true);
1618 if (!
strand_.running_in_this_thread())
1624 slots_.deleteIdlePeers();
1643 set(ip,
"public_ip", section);
1646 boost::system::error_code ec;
1647 setup.
publicIp = boost::asio::ip::make_address(ip, ec);
1655 JLOG(j.
warn()) <<
"Endpoint verification is disabled. This is a "
1656 "security risk and should only be used for "
1663 auto const& values = section.
values();
1665 if (values.size() > 1)
1670 bool crawlEnabled =
true;
1673 if (values.size() == 1)
1677 crawlEnabled = boost::lexical_cast<bool>(values.front());
1679 catch (boost::bad_lexical_cast
const&)
1682 "Configured [crawl] section has invalid value: {}", values.front()));
1721 if (
id ==
"testnet")
1733 "Configured [network_id] section is invalid: must be a number "
1734 "or one of the strings 'main', 'testnet' or 'devnet'.");
1747 boost::asio::io_context& ioContext,
1752 app, setup, serverHandler, resourceManager, resolver, ioContext, config, collector);
A generic endpoint for log messages.
std::string const & name() const
Returns the name of this source.
void add(Source &source)
Add a child source.
Wraps a Journal::Sink to prefix its output with a string.
std::shared_ptr< Collector > Ptr
A version-independent IP address and port combination.
Value removeMember(char const *key)
Remove and return the named member.
Value & append(Value const &value)
Append value to array at the end.
bool isMember(char const *key) const
Return true if the object has a member named key.
Holds unparsed configuration information.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
Section & section(std::string const &name)
Returns the section with the given name.
Child(OverlayImpl &overlay)
static std::shared_ptr< Writer > makeErrorResponse(std::shared_ptr< peer_finder::Slot > const &slot, HttpRequestType const &request, AddressType remoteAddress, std::string const &msg)
boost::system::error_code ErrorCode
std::weak_ptr< Timer > timer_
boost::asio::io_context & ioContext_
resource::Manager & resourceManager()
void squelch(PublicKey const &validator, Peer::ID const id, std::uint32_t squelchDuration) const override
Squelch handler.
std::set< Peer::ID > relay(protocol::TMProposeSet const &m, UInt256 const &uid, PublicKey const &validator) override
Relay a proposal.
json::Value getOverlayInfo() const
Returns information about peers on the overlay network.
bool processRequest(HttpRequestType const &req, Handoff &handoff)
Handles non-peer protocol requests.
bool processValidatorList(HttpRequestType const &req, Handoff &handoff)
Handles validator list requests.
void addActive(std::shared_ptr< PeerImp > const &peer)
std::atomic< Peer::ID > nextId_
void broadcast(protocol::TMProposeSet const &m) override
Broadcast a proposal.
void activate(std::shared_ptr< PeerImp > const &peer)
Called when a peer has connected successfully This is called after the peer handshake has been comple...
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
void connect(beast::ip::Endpoint const &remoteEndpoint) override
Establish a peer connection to the specified endpoint.
peer_finder::Manager & peerFinder()
void remove(std::shared_ptr< peer_finder::Slot > const &slot)
void onPeerDeactivate(Peer::ID id)
std::size_t size() const override
The number of active peers on the network Active peers are only those peers that have completed the h...
static bool isUpgrade(boost::beast::http::header< true, Fields > const &req)
ServerHandler & serverHandler_
void onManifests(std::shared_ptr< protocol::TMManifests > const &m, std::shared_ptr< PeerImp > const &from)
std::shared_ptr< Writer > makeRedirectResponse(std::shared_ptr< peer_finder::Slot > const &slot, HttpRequestType const &request, AddressType remoteAddress)
peer_finder::StoreSqdb store_
reduce_relay::Slots< UptimeClock > slots_
void deleteIdlePeers()
Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.
void unsquelch(PublicKey const &validator, Peer::ID id) const override
Unsquelch handler.
bool processHealth(HttpRequestType const &req, Handoff &handoff)
Handles health requests.
void reportInboundTraffic(TrafficCount::Category cat, int bytes)
std::shared_ptr< Message > manifestMessage_
void sendTxQueue() const
Send once a second transactions' hashes aggregated by peers.
std::optional< std::uint32_t > manifestListSeq_
std::unique_ptr< peer_finder::Manager > peerFinder_
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
resource::Manager & resourceManager_
HashMap< std::shared_ptr< peer_finder::Slot >, std::weak_ptr< PeerImp > > peers_
json::Value getServerCounts()
Returns information about the local server's performance counters.
std::recursive_mutex mutex_
bool processCrawl(HttpRequestType const &req, Handoff &handoff)
Handles crawl requests.
beast::Journal const journal_
json::Value json() override
Return diagnostics on the status of all peers.
void forEach(UnaryFunc &&f) const
std::shared_ptr< Peer > findPeerByShortID(Peer::ID const &id) const override
Returns the peer with the matching short id, or null.
Handoff onHandoff(std::unique_ptr< StreamType > &&bundle, HttpRequestType &&request, EndpointType remoteEndpoint) override
Conditionally accept an incoming HTTP request.
boost::asio::strand< boost::asio::io_context::executor_type > strand_
static std::string makePrefix(std::uint32_t id)
Setup const & setup() const
HashMap< Peer::ID, std::weak_ptr< PeerImp > > ids_
boost::asio::ip::address AddressType
static bool isPeerUpgrade(HttpRequestType const &request)
metrics::TxMetrics txMetrics_
boost::container::flat_map< Child *, std::weak_ptr< Child > > list_
int limit() override
Returns the maximum number of peers we are configured to allow.
std::condition_variable_any cond_
OverlayImpl(Application &app, Setup setup, ServerHandler &serverHandler, resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_context &ioContext, BasicConfig const &config, beast::insight::Collector::Ptr const &collector)
json::Value getUnlInfo()
Returns information about the local server's UNL.
std::shared_ptr< Message > getManifestsMessage()
std::shared_ptr< Peer > findPeerByPublicKey(PublicKey const &pubKey) override
Returns the peer with the matching public key, or null.
boost::asio::ip::tcp::endpoint EndpointType
void deletePeer(Peer::ID id)
Called when the peer is deleted.
void checkTracking(std::uint32_t) override
Calls the checkTracking function on each peer.
json::Value getServerInfo()
Returns information about the local server.
void reportOutboundTraffic(TrafficCount::Category cat, int bytes)
void relayChecked(UInt256 const &hash, std::optional< std::reference_wrapper< protocol::TMTransaction const > > tx, std::set< Peer::ID > const &toSkip)
Relay tx if present, else only queue its hash for peers that have tx reduce-relay enabled.
PeerSequence getActivePeers() const override
Returns a sequence representing the current list of peers.
void updateSlotAndSquelch(UInt256 const &key, PublicKey const &validator, std::set< Peer::ID > &&peers, protocol::MessageType type)
Updates message count for validator/peer.
std::vector< std::shared_ptr< Peer > > PeerSequence
std::uint32_t ID
Uniquely identifies a peer.
UInt256 getTransactionID() const
std::vector< std::string > const & values() const
Returns all the values in the section.
virtual std::pair< std::shared_ptr< Slot >, Result > newOutboundSlot(beast::ip::Endpoint const &remoteEndpoint)=0
Create a new outbound slot with the specified remote endpoint.
Tracks load and resource consumption.
virtual Consumer newOutboundEndpoint(beast::ip::Endpoint const &address)=0
Create a new endpoint keyed by outbound IP address and port.
T duration_cast(T... args)
T emplace_back(T... args)
bool isPublic(Address const &addr)
Returns true if the address is a public routable address.
bool isKeepAlive(boost::beast::http::message< IsRequest, Body, Fields > const &m)
Result splitCommas(FwdIt first, FwdIt last)
constexpr Out lexicalCastThrow(In in)
Convert from one type to another, throw on error.
JSON (JavaScript Object Notation).
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
std::string const & getFullVersionString()
Full server version string.
static constexpr auto kDisabled
static constexpr auto kOverlay
static constexpr auto kUnl
static constexpr auto kServerCounts
static constexpr auto kServerInfo
Config makeConfig(xrpl::Config const &cfg, std::uint16_t port, bool validationPublicKey, int ipLimit, bool verifyEndpoints)
Charge const kFeeMalformedRequest
Schedule of fees charged for imposing load on the server.
static constexpr auto kCheckIdlePeers
How often we check for idle peers (seconds).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
beast::XorShiftEngine & defaultPrng()
Return the default random engine.
Stopwatch & stopwatch()
Returns an instance of a wall clock.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::string strHex(FwdIt begin, FwdIt end)
std::optional< ProtocolVersion > negotiateProtocolVersion(std::vector< ProtocolVersion > const &versions)
Given a list of supported protocol versions, choose the one we prefer.
static std::vector< beast::ip::Endpoint > withDefaultPeerPort(std::vector< beast::ip::Endpoint > const &addresses)
static constexpr auto kDefaultBootstrapIps
std::string to_string(BaseUInt< Bits, Tag > const &a)
void addValidatorManifest(soci::session &session, std::string const &serialized)
addValidatorManifest Saves the manifest of a validator to the database.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
@ Uncapped
Bypasses the cap (listed/trusted or config manifests).
@ Capped
Subject to the untrusted cap (unlisted peer gossip).
Slice makeSlice(std::array< T, N > const &a)
boost::beast::http::request< boost::beast::http::dynamic_body > HttpRequestType
std::shared_ptr< boost::asio::ssl::context > makeSslContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
std::string base64Encode(std::uint8_t const *data, std::size_t len)
std::optional< UInt256 > makeSharedValue(StreamType &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
std::unique_ptr< Overlay > makeOverlay(Application &app, Overlay::Setup const &setup, ServerHandler &serverHandler, resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_context &ioContext, BasicConfig const &config, beast::insight::Collector::Ptr const &collector)
Creates the implementation of Overlay.
constexpr Number squelch(Number const &x, Number const &limit) noexcept
std::shared_ptr< Message > makeSquelchMessage(PublicKey const &validator, bool squelch, uint32_t squelchDuration)
constexpr std::size_t untrustedManifestCount(std::optional< std::size_t > const &configured)
Number of untrusted manifests to store in cache and allowed in one Manifest message.
Overlay::Setup setupOverlay(BasicConfig const &config, beast::Journal j)
json::Value getCountsJson(Application &app, int minObjectCount)
std::vector< ProtocolVersion > parseProtocolVersions(std::string_view value)
Parse a set of protocol versions.
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
PublicKey verifyHandshake(boost::beast::http::fields const &headers, xrpl::UInt256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::ip::Address publicIp, beast::ip::Address remote, Application &app)
Validate header fields necessary for upgrading the link to the peer protocol.
@ Accepted
Manifest is valid.
T shared_from_this(T... args)
static boost::asio::ip::tcp::endpoint toAsioEndpoint(ip::Endpoint const &address)
static ip::Endpoint fromAsio(boost::asio::ip::address const &address)
Used to indicate the result of a server connection handoff.
std::shared_ptr< Writer > response
static constexpr auto kUnl
static constexpr auto kCounts
static constexpr auto kOverlay
static constexpr auto kServer
void onTimer(ErrorCode ec)
boost::asio::basic_waitable_timer< ClockType > timer
Timer(OverlayImpl &overlay)
std::uint32_t crawlOptions
std::optional< std::uint32_t > networkID
beast::ip::Address publicIp
std::shared_ptr< boost::asio::ssl::context > context
static constexpr auto kOverlay
static constexpr auto kVl
static constexpr auto kCrawl
static constexpr auto kNetworkId
PeerFinder configuration settings.