20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/misc/HashRouter.h>
22 #include <ripple/app/misc/NetworkOPs.h>
23 #include <ripple/app/misc/ValidatorList.h>
24 #include <ripple/app/misc/ValidatorSite.h>
25 #include <ripple/app/rdb/RelationalDatabase.h>
26 #include <ripple/app/rdb/Wallet.h>
27 #include <ripple/basics/base64.h>
28 #include <ripple/basics/make_SSLContext.h>
29 #include <ripple/basics/random.h>
30 #include <ripple/beast/core/LexicalCast.h>
31 #include <ripple/nodestore/DatabaseShard.h>
32 #include <ripple/overlay/Cluster.h>
33 #include <ripple/overlay/impl/ConnectAttempt.h>
34 #include <ripple/overlay/impl/PeerImp.h>
35 #include <ripple/overlay/predicates.h>
36 #include <ripple/peerfinder/make_Manager.h>
37 #include <ripple/rpc/handlers/GetCounts.h>
38 #include <ripple/rpc/json_body.h>
39 #include <ripple/server/SimpleWriter.h>
41 #include <boost/algorithm/string/predicate.hpp>
42 #include <boost/utility/in_place_factory.hpp>
46 namespace CrawlOptions {
64 overlay_.remove(*
this);
96 if (ec && ec != boost::asio::error::operation_aborted)
98 JLOG(overlay_.journal_.error()) <<
"on_timer: " << ec.message();
103 overlay_.m_peerFinder->once_per_second();
104 overlay_.sendEndpoints();
105 overlay_.autoConnect();
106 if (overlay_.app_.config().TX_REDUCE_RELAY_ENABLE)
107 overlay_.sendTxQueue();
110 overlay_.deleteIdlePeers();
123 boost::asio::io_service& io_service,
137 app_.journal(
"PeerFinder"),
143 ,
slots_(app.logs(), *this)
147 [counts =
m_traffic.getCounts(), collector]() {
151 for (
size_t i = 0; i < counts.size(); ++i)
178 handoff.
moved =
true;
180 JLOG(journal.
debug()) <<
"Peer connection upgrade from " << remote_endpoint;
183 auto const local_endpoint(
184 stream_ptr->next_layer().socket().local_endpoint(ec));
187 JLOG(journal.
debug()) << remote_endpoint <<
" failed: " << ec.message();
193 if (consumer.disconnect(journal))
203 handoff.
moved =
false;
212 return boost::iequals(s,
"peer");
215 handoff.
moved =
false;
224 if (!negotiatedVersion)
227 handoff.
moved =
false;
231 remote_endpoint.address(),
232 "Unable to agree on a protocol version");
241 handoff.
moved =
false;
245 remote_endpoint.address(),
246 "Incorrect security cookie");
258 remote_endpoint.address(),
264 bool const reserved =
272 JLOG(journal.
debug())
273 <<
"Peer " << remote_endpoint <<
" redirected, slots full";
274 handoff.
moved =
false;
276 slot, request, remote_endpoint.address());
282 auto const peer = std::make_shared<PeerImp>(
290 std::move(stream_ptr),
298 auto const result =
m_peers.emplace(peer->slot(), peer);
299 assert(result.second);
302 list_.emplace(peer.get(), peer);
306 handoff.
moved =
true;
311 JLOG(journal.
debug()) <<
"Peer " << remote_endpoint
312 <<
" fails handshake (" << e.
what() <<
")";
315 handoff.
moved =
false;
317 slot, request, remote_endpoint.address(), e.
what());
331 return !versions.empty();
348 boost::beast::http::response<json_body> msg;
349 msg.version(request.version());
350 msg.result(boost::beast::http::status::service_unavailable);
354 ostr << remote_address;
355 msg.insert(
"Remote-Address", ostr.
str());
357 msg.insert(
"Content-Type",
"application/json");
358 msg.insert(boost::beast::http::field::connection,
"close");
363 ips.
append(_.address.to_string());
365 msg.prepare_payload();
366 return std::make_shared<SimpleWriter>(msg);
376 boost::beast::http::response<boost::beast::http::empty_body> msg;
377 msg.version(request.version());
378 msg.result(boost::beast::http::status::bad_request);
379 msg.reason(
"Bad Request (" + text +
")");
381 msg.insert(
"Remote-Address", remote_address.to_string());
382 msg.insert(boost::beast::http::field::connection,
"close");
383 msg.prepare_payload();
384 return std::make_shared<SimpleWriter>(msg);
397 JLOG(
journal_.
info()) <<
"Over resource limit: " << remote_endpoint;
404 JLOG(
journal_.
debug()) <<
"Connect: No slot for " << remote_endpoint;
408 auto const p = std::make_shared<ConnectAttempt>(
420 list_.emplace(p.get(), p);
433 auto const result =
m_peers.emplace(peer->slot(), peer);
434 assert(result.second);
439 auto const result =
ids_.emplace(
440 std::piecewise_construct,
443 assert(result.second);
449 JLOG(
journal_.
debug()) <<
"activated " << peer->getRemoteAddress() <<
" ("
465 auto const iter =
m_peers.find(slot);
489 if (bootstrapIps.empty())
492 bootstrapIps.
push_back(
"r.ripple.com 51235");
495 bootstrapIps.
push_back(
"zaphod.alloy.ee 51235");
498 bootstrapIps.push_back(
"sahyadri.isrdc.in 51235");
508 for (
auto const& addr : addresses)
510 if (addr.port() == 0)
532 for (
auto& addr : addresses)
534 if (addr.port() == 0)
544 auto const timer = std::make_shared<Timer>(*
this);
546 list_.emplace(timer.get(), timer);
573 for (
auto const& i : stats)
578 item[
"category"] = i.name;
599 auto const result(
ids_.emplace(
600 std::piecewise_construct,
603 assert(result.second);
607 JLOG(
journal_.
debug()) <<
"activated " << peer->getRemoteAddress() <<
" ("
629 auto const n = m->list_size();
630 auto const& journal = from->pjournal();
632 protocol::TMManifests
relay;
636 auto& s = m->list().Get(i).stobject();
640 auto const serialized = mo->serialized;
647 relay.add_list()->set_stobject(s);
666 JLOG(journal.debug())
667 <<
"Malformed manifest #" << i + 1 <<
": " <<
strHex(s);
672 if (!
relay.list().empty())
673 for_each([m2 = std::make_shared<Message>(
relay, protocol::mtMANIFESTS)](
696 if (includePublicKey)
697 jv[jss::public_key] =
700 auto const shardInfo{shardStore->getShardInfo()};
702 jv[jss::complete_shards] =
shardInfo->finalizedToString();
704 jv[jss::incomplete_shards] =
shardInfo->incompleteToString();
707 if (relays == 0 ||
size() == 0)
711 protocol::TMGetPeerShardInfoV2 tmGPS;
712 tmGPS.set_relays(relays);
721 for (
auto const&
id :
ids_)
727 tmGPS, protocol::mtGET_PEER_SHARD_INFO_V2)));
739 auto const psi{peer->getPeerShardInfos()};
740 for (
auto const& [publicKey,
shardInfo] : psi)
742 auto const it{peerShardInfo.
find(publicKey)};
743 if (it == peerShardInfo.
end())
745 else if (
shardInfo.msgTimestamp() > it->second.msgTimestamp())
751 if (!peerShardInfo.
empty())
754 for (
auto const& [publicKey,
shardInfo] : peerShardInfo)
757 if (includePublicKey)
759 pv[jss::public_key] =
764 pv[jss::complete_shards] =
shardInfo.finalizedToString();
766 pv[jss::incomplete_shards] =
shardInfo.incompleteToString();
810 sp->getNodePublic().data(), sp->getNodePublic().size());
811 pv[jss::type] = sp->slot()->inbound() ?
"in" :
"out";
813 duration_cast<seconds>(sp->uptime()).count());
816 pv[jss::ip] = sp->getRemoteAddress().address().to_string();
817 if (sp->slot()->inbound())
819 if (
auto port = sp->slot()->listening_port())
820 pv[jss::port] = *port;
829 auto version{sp->getVersion()};
830 if (!version.empty())
832 pv[jss::version] = version;
836 sp->ledgerRange(minSeq, maxSeq);
837 if (minSeq != 0 || maxSeq != 0)
838 pv[jss::complete_ledgers] =
841 auto const peerShardInfos{sp->getPeerShardInfos()};
842 auto const it{peerShardInfos.find(sp->getNodePublic())};
843 if (it != peerShardInfos.end())
847 pv[jss::complete_shards] =
shardInfo.finalizedToString();
849 pv[jss::incomplete_shards] =
shardInfo.incompleteToString();
859 bool const humanReadable =
false;
860 bool const admin =
false;
861 bool const counters =
false;
868 server_info.
removeMember(jss::load_factor_fee_escalation);
872 if (server_info.
isMember(jss::validated_ledger))
874 Json::Value& validated_ledger = server_info[jss::validated_ledger];
895 if (validators.
isMember(jss::publisher_lists))
897 Json::Value& publisher_lists = validators[jss::publisher_lists];
899 for (
auto& publisher : publisher_lists)
911 if (validatorSites.
isMember(jss::validator_sites))
913 validators[jss::validator_sites] =
914 std::move(validatorSites[jss::validator_sites]);
935 if (req.target() !=
"/crawl" ||
939 boost::beast::http::response<json_body> msg;
940 msg.version(req.version());
941 msg.result(boost::beast::http::status::ok);
943 msg.insert(
"Content-Type",
"application/json");
944 msg.insert(
"Connection",
"close");
964 msg.prepare_payload();
965 handoff.
response = std::make_shared<SimpleWriter>(msg);
983 boost::beast::http::response<json_body> msg;
984 msg.version(req.version());
986 msg.insert(
"Content-Type",
"application/json");
987 msg.insert(
"Connection",
"close");
989 auto fail = [&msg, &handoff](
auto status) {
991 msg.insert(
"Content-Length",
"0");
995 msg.prepare_payload();
996 handoff.
response = std::make_shared<SimpleWriter>(msg);
1000 auto key = req.target().substr(prefix.size());
1002 if (
auto slash = key.find(
'/'); slash != boost::string_view::npos)
1004 auto verString = key.substr(0, slash);
1005 if (!boost::conversion::try_lexical_convert(verString, version))
1006 return fail(boost::beast::http::status::bad_request);
1007 key = key.substr(slash + 1);
1011 return fail(boost::beast::http::status::bad_request);
1019 return fail(boost::beast::http::status::not_found);
1023 return fail(boost::beast::http::status::bad_request);
1027 msg.result(boost::beast::http::status::ok);
1031 msg.prepare_payload();
1032 handoff.
response = std::make_shared<SimpleWriter>(msg);
1040 if (req.target() !=
"/health")
1042 boost::beast::http::response<json_body> msg;
1043 msg.version(req.version());
1045 msg.insert(
"Content-Type",
"application/json");
1046 msg.insert(
"Connection",
"close");
1050 int last_validated_ledger_age = -1;
1051 if (info.isMember(jss::validated_ledger))
1052 last_validated_ledger_age =
1053 info[jss::validated_ledger][jss::age].asInt();
1054 bool amendment_blocked =
false;
1055 if (info.isMember(jss::amendment_blocked))
1056 amendment_blocked =
true;
1057 int number_peers = info[jss::peers].asInt();
1058 std::string server_state = info[jss::server_state].asString();
1059 auto load_factor = info[jss::load_factor_server].asDouble() /
1060 info[jss::load_base].asDouble();
1062 enum { healthy, warning, critical };
1063 int health = healthy;
1064 auto set_health = [&health](
int state) {
1070 if (last_validated_ledger_age >= 7 || last_validated_ledger_age < 0)
1072 msg.body()[jss::info][jss::validated_ledger] =
1073 last_validated_ledger_age;
1074 if (last_validated_ledger_age < 20)
1075 set_health(warning);
1077 set_health(critical);
1080 if (amendment_blocked)
1082 msg.body()[jss::info][jss::amendment_blocked] =
true;
1083 set_health(critical);
1086 if (number_peers <= 7)
1088 msg.body()[jss::info][jss::peers] = number_peers;
1089 if (number_peers != 0)
1090 set_health(warning);
1092 set_health(critical);
1095 if (!(server_state ==
"full" || server_state ==
"validating" ||
1096 server_state ==
"proposing"))
1098 msg.body()[jss::info][jss::server_state] = server_state;
1099 if (server_state ==
"syncing" || server_state ==
"tracking" ||
1100 server_state ==
"connected")
1102 set_health(warning);
1105 set_health(critical);
1108 if (load_factor > 100)
1110 msg.body()[jss::info][jss::load_factor] = load_factor;
1111 if (load_factor < 1000)
1112 set_health(warning);
1114 set_health(critical);
1120 msg.result(boost::beast::http::status::ok);
1123 msg.result(boost::beast::http::status::service_unavailable);
1126 msg.result(boost::beast::http::status::internal_server_error);
1130 msg.prepare_payload();
1131 handoff.
response = std::make_shared<SimpleWriter>(msg);
1166 active =
ids_.size();
1167 disabled = enabledInSkip = 0;
1170 for (
auto& [
id, w] :
ids_)
1172 if (
auto p = w.lock())
1174 bool const reduceRelayEnabled = p->txReduceRelayEnabled();
1176 if (!reduceRelayEnabled)
1179 if (toSkip.
count(
id) == 0)
1181 else if (reduceRelayEnabled)
1200 auto const iter =
ids_.find(
id);
1201 if (iter !=
ids_.end())
1202 return iter->second.lock();
1212 for (
auto const& e :
ids_)
1214 if (
auto peer = e.second.lock())
1216 if (peer->getNodePublic() == pubKey)
1226 auto const sm = std::make_shared<Message>(m, protocol::mtPROPOSE_LEDGER);
1232 protocol::TMProposeSet& m,
1239 std::make_shared<Message>(m, protocol::mtPROPOSE_LEDGER, validator);
1241 if (toSkip->find(p->id()) == toSkip->end())
1252 auto const sm = std::make_shared<Message>(m, protocol::mtVALIDATION);
1258 protocol::TMValidation& m,
1265 std::make_shared<Message>(m, protocol::mtVALIDATION, validator);
1267 if (toSkip->find(p->id()) == toSkip->end())
1283 protocol::TMManifests tm;
1286 [&tm](
std::size_t s) { tm.mutable_list()->Reserve(s); },
1288 tm.add_list()->set_stobject(
1290 hr.addSuppression(
manifest.hash());
1295 if (tm.list_size() != 0)
1297 std::make_shared<Message>(tm, protocol::mtMANIFESTS);
1308 protocol::TMTransaction& m,
1311 auto const sm = std::make_shared<Message>(m, protocol::mtTRANSACTION);
1317 auto peers =
getActivePeers(toSkip, total, disabled, enabledInSkip);
1322 for (
auto const& p : peers)
1338 if (enabledTarget > enabledInSkip)
1341 JLOG(
journal_.
trace()) <<
"relaying tx, total peers " << peers.size()
1342 <<
" selected " << enabledTarget <<
" skip "
1343 << toSkip.
size() <<
" disabled " << disabled;
1347 for (
auto const& p : peers)
1350 if (!p->txReduceRelayEnabled())
1354 else if (enabledAndRelayed < enabledTarget)
1356 enabledAndRelayed++;
1361 p->addTxQueue(hash);
1372 list_.erase(&child);
1393 work_ = std::nullopt;
1396 for (
auto const& element :
list_)
1402 for (
auto const& child : children)
1404 if (child !=
nullptr)
1413 for (
auto addr : result)
1420 auto const result =
m_peerFinder->buildEndpointsForPeers();
1421 for (
auto const& e : result)
1426 auto const iter =
m_peers.find(e.first);
1428 peer = iter->second.lock();
1431 peer->sendEndpoints(e.second.begin(), e.second.end());
1439 if (p->txReduceRelayEnabled())
1448 uint32_t squelchDuration)
1450 protocol::TMSquelch m;
1452 m.set_validatorpubkey(validator.data(), validator.size());
1454 m.set_squelchduration(squelchDuration);
1455 return std::make_shared<Message>(m, protocol::mtSQUELCH);
1462 peer &&
app_.
config().VP_REDUCE_RELAY_SQUELCH)
1474 uint32_t squelchDuration)
const
1477 peer &&
app_.
config().VP_REDUCE_RELAY_SQUELCH)
1488 protocol::MessageType type)
1490 if (!
strand_.running_in_this_thread())
1493 [
this, key, validator, peers = std::move(peers), type]()
mutable {
1497 for (
auto id : peers)
1498 slots_.updateSlotAndSquelch(key, validator,
id, type);
1506 protocol::MessageType type)
1508 if (!
strand_.running_in_this_thread())
1509 return post(
strand_, [
this, key, validator, peer, type]() {
1513 slots_.updateSlotAndSquelch(key, validator, peer, type);
1519 if (!
strand_.running_in_this_thread())
1522 slots_.deletePeer(
id,
true);
1528 if (!
strand_.running_in_this_thread())
1531 slots_.deleteIdlePeers();
1542 auto const& section = config.
section(
"overlay");
1547 Throw<std::runtime_error>(
"Configured IP limit is invalid");
1550 set(ip,
"public_ip", section);
1553 boost::system::error_code ec;
1556 Throw<std::runtime_error>(
"Configured public IP is invalid");
1561 auto const& section = config.
section(
"crawl");
1562 auto const& values = section.
values();
1564 if (values.size() > 1)
1566 Throw<std::runtime_error>(
1567 "Configured [crawl] section is invalid, too many values");
1570 bool crawlEnabled =
true;
1573 if (values.size() == 1)
1577 crawlEnabled = boost::lexical_cast<bool>(values.front());
1579 catch (boost::bad_lexical_cast
const&)
1581 Throw<std::runtime_error>(
1582 "Configured [crawl] section has invalid value: " +
1589 if (get<bool>(section,
"overlay",
true))
1593 if (get<bool>(section,
"server",
true))
1597 if (get<bool>(section,
"counts",
false))
1601 if (get<bool>(section,
"unl",
true))
1608 auto const& section = config.
section(
"vl");
1615 auto id = config.
legacy(
"network_id");
1622 if (
id ==
"testnet")
1633 Throw<std::runtime_error>(
1634 "Configured [network_id] section is invalid: must be a number "
1635 "or one of the strings 'main', 'testnet' or 'devnet'.");
1648 boost::asio::io_service& io_service,
1652 return std::make_unique<OverlayImpl>(
OverlayImpl(Application &app, Setup const &setup, ServerHandler &serverHandler, Resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_service &io_service, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
std::string const & name() const
Returns the name of this source.
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
virtual Consumer newOutboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by outbound IP address and port.
Json::Value getServerCounts()
Returns information about the local server's performance counters.
const beast::Journal journal_
boost::asio::ip::address address_type
virtual Cluster & cluster()=0
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
auto const & getCounts() const
An up-to-date copy of all the counters.
std::shared_ptr< Message > makeSquelchMessage(PublicKey const &validator, bool squelch, uint32_t squelchDuration)
std::optional< std::uint32_t > networkID
std::unique_ptr< Overlay > make_Overlay(Application &app, Overlay::Setup const &setup, ServerHandler &serverHandler, Resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_service &io_service, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
Creates the implementation of Overlay.
Stream trace() const
Severity stream access functions.
virtual void pubManifest(Manifest const &)=0
static bool is_upgrade(boost::beast::http::header< true, Fields > const &req)
hash_map< Peer::id_t, std::weak_ptr< PeerImp > > ids_
@ arrayValue
array value (ordered list)
void updateSlotAndSquelch(uint256 const &key, PublicKey const &validator, std::set< Peer::id_t > &&peers, protocol::MessageType type)
Updates message count for validator/peer.
virtual ValidatorSite & validatorSites()=0
std::uint32_t crawlOptions
void endOfPeerChain(std::uint32_t id)
Called when the reply from the last peer in a peer chain is received.
std::set< std::uint32_t > csIDs_
std::recursive_mutex mutex_
void on_timer(error_code ec)
virtual PeerReservationTable & peerReservations()=0
std::atomic< Peer::id_t > next_id_
std::string base64_encode(std::uint8_t const *data, std::size_t len)
bool empty() const noexcept
std::shared_ptr< boost::asio::ssl::context > make_SSLContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
static std::string makePrefix(std::uint32_t id)
Handoff onHandoff(std::unique_ptr< stream_type > &&bundle, http_request_type &&request, endpoint_type remote_endpoint) override
Conditionally accept an incoming HTTP request.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::condition_variable csCV_
void setup(Setup const &setup, beast::Journal journal)
void addValidatorManifest(soci::session &session, std::string const &serialized)
addValidatorManifest Saves the manifest of a validator to the database.
boost::asio::io_service::strand strand_
Json::Value getServerInfo()
Returns information about the local server.
virtual NodeStore::DatabaseShard * getShardStore()=0
std::vector< ProtocolVersion > parseProtocolVersions(boost::beast::string_view const &value)
Parse a set of protocol versions.
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Stopwatch & stopwatch()
Returns an instance of a wall clock.
void broadcast(protocol::TMProposeSet &m) override
Broadcast a proposal.
virtual std::shared_ptr< Slot > new_outbound_slot(beast::IP::Endpoint const &remote_endpoint)=0
Create a new outbound slot with the specified remote endpoint.
void connect(beast::IP::Endpoint const &remote_endpoint) override
Establish a peer connection to the specified endpoint.
Json::Value json() override
Return diagnostics on the status of all peers.
Setup const & setup() const
bool processValidatorList(http_request_type const &req, Handoff &handoff)
Handles validator list requests.
virtual NetworkOPs & getOPs()=0
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
bool processHealth(http_request_type const &req, Handoff &handoff)
Handles health requests.
std::vector< std::string > const & values() const
Returns all the values in the section.
bool is_private(AddressV4 const &addr)
Returns true if the address is a private unroutable address.
Sends a message to all peers.
static Config makeConfig(ripple::Config const &config, std::uint16_t port, bool validationPublicKey, int ipLimit)
Make PeerFinder::Config from configuration parameters.
std::condition_variable_any cond_
void sendTxQueue()
Send once a second transactions' hashes aggregated by peers.
static IP::Endpoint from_asio(boost::asio::ip::address const &address)
@ checkIdlePeers
How often we check for idle peers (seconds)
PeerFinder::Manager & peerFinder()
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...
void checkTracking(std::uint32_t) override
Calls the checkTracking function on each peer.
bool is_keep_alive(boost::beast::http::message< isRequest, Body, Fields > const &m)
Overlay::Setup setup_Overlay(BasicConfig const &config)
Value & append(const Value &value)
Append value to array at the end.
void onManifests(std::shared_ptr< protocol::TMManifests > const &m, std::shared_ptr< PeerImp > const &from)
beast::IP::Address public_ip
std::shared_ptr< Message > manifestMessage_
LockedSociSession checkoutDb()
Resource::Manager & resourceManager()
@ objectValue
object value (collection of name/value pairs).
void add(Source &source)
Add a child source.
Json::Value getOverlayInfo()
Returns information about peers on the overlay network.
boost::asio::io_service & io_service_
virtual Config & config()=0
Json::Value getJson() const
Return JSON representation of configured validator sites.
std::vector< std::string > IPS_FIXED
reduce_relay::Slots< UptimeClock > slots_
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
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,...
Json::Value getUnlInfo()
Returns information about the local server's UNL.
bool listed(PublicKey const &identity) const
Returns true if public key is included on any lists.
beast::xor_shift_engine & default_prng()
Return the default random engine.
std::optional< Json::Value > getAvailable(boost::beast::string_view const &pubKey, std::optional< std::uint32_t > forceVersion={})
Returns the current valid list for the given publisher key, if available, as a Json object.
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
void for_each_manifest(Function &&f) const
Invokes the callback once for every populated manifest.
std::unique_ptr< PeerFinder::Manager > m_peerFinder
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
ServerHandler & serverHandler_
Child(OverlayImpl &overlay)
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
PeerSequence getActivePeers() const override
Returns a sequence representing the current list of peers.
Result split_commas(FwdIt first, FwdIt last)
virtual PublicKey const & getValidationPublicKey() const =0
void deleteIdlePeers()
Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.
virtual ValidatorList & validators()=0
bool processRequest(http_request_type const &req, Handoff &handoff)
Handles non-peer protocol requests.
std::optional< std::uint32_t > manifestListSeq_
@ accepted
Manifest is valid.
Tracks load and resource consumption.
std::string const & getFullVersionString()
Full server version string.
void deletePeer(Peer::id_t id)
Called when the peer is deleted.
Json::Value getCountsJson(Application &app, int minObjectCount)
Resource::Manager & m_resourceManager
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::set< Peer::id_t > relay(protocol::TMProposeSet &m, uint256 const &uid, PublicKey const &validator) override
Relay a proposal.
void addMetrics(protocol::MessageType type, std::uint32_t val)
Add protocol message metrics.
virtual beast::Journal journal(std::string const &name)=0
virtual ManifestCache & validatorManifests()=0
std::shared_ptr< Message > getManifestsMessage()
Value removeMember(const char *key)
Remove and return the named member.
Json::Value crawlShards(bool includePublicKey, std::uint32_t relays) override
Returns information reported to the crawl shard RPC command.
std::size_t TX_REDUCE_RELAY_MIN_PEERS
void remove(std::shared_ptr< PeerFinder::Slot > const &slot)
Manages the set of connected peers.
bool TX_REDUCE_RELAY_METRICS
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...
void onPeerDeactivate(Peer::id_t id)
boost::container::flat_map< Child *, std::weak_ptr< Child > > list_
std::optional< boost::asio::io_service::work > work_
Timer(OverlayImpl &overlay)
void squelch(PublicKey const &validator, Peer::id_t const id, std::uint32_t squelchDuration) const override
Squelch handler.
Wraps a Journal::Sink to prefix its output with a string.
Used to indicate the result of a server connection handoff.
std::shared_ptr< Peer > findPeerByPublicKey(PublicKey const &pubKey) override
Returns the peer with the matching public key, or null.
Json::Value getJson() const
Return a JSON representation of the state of the validator list.
bool contains(PublicKey const &nodeId)
std::vector< std::string > IPS
metrics::TxMetrics txMetrics_
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
std::shared_ptr< Writer > makeRedirectResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address)
std::size_t TX_RELAY_PERCENTAGE
A version-independent IP address and port combination.
std::string strHex(FwdIt begin, FwdIt end)
std::weak_ptr< Timer > timer_
std::shared_ptr< boost::asio::ssl::context > context
std::shared_ptr< Writer > response
static boost::asio::ip::tcp::endpoint to_asio_endpoint(IP::Endpoint const &address)
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
bool TX_REDUCE_RELAY_ENABLE
PeerFinder configuration settings.
PublicKey verifyHandshake(boost::beast::http::fields const &headers, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote, Application &app)
Validate header fields necessary for upgrading the link to the peer protocol.
std::shared_ptr< Peer > findPeerByShortID(Peer::id_t const &id) const override
Returns the peer with the matching short id, or null.
void reportTraffic(TrafficCount::category cat, bool isInbound, int bytes)
void addCount(category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
ManifestDisposition applyManifest(Manifest m)
Add manifest to cache.
std::shared_ptr< Writer > makeErrorResponse(std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type const &request, address_type remote_address, std::string msg)
hash_map< std::shared_ptr< PeerFinder::Slot >, std::weak_ptr< PeerImp > > m_peers
void resolve(std::vector< std::string > const &names, Handler handler)
resolve all hostnames on the list
static bool isPeerUpgrade(http_request_type const &request)
void add_active(std::shared_ptr< PeerImp > const &peer)
std::optional< ProtocolVersion > negotiateProtocolVersion(std::vector< ProtocolVersion > const &versions)
Given a list of supported protocol versions, choose the one we prefer.
boost::system::error_code error_code
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
virtual HashRouter & getHashRouter()=0
Holds unparsed configuration information.
void for_each(UnaryFunc &&f) const
void unsquelch(PublicKey const &validator, Peer::id_t id) const override
Unsquelch handler.
@ shardInfo
shard info for signing
Section & section(std::string const &name)
Returns the section with the given name.
int limit() override
Returns the maximum number of peers we are configured to allow.
bool processCrawl(http_request_type const &req, Handoff &handoff)
Handles crawl requests.
boost::asio::ip::tcp::endpoint endpoint_type
std::uint32_t sequence() const
A monotonically increasing number used to detect new manifests.