rippled
Loading...
Searching...
No Matches
Peers.cpp
1#include <xrpld/app/main/Application.h>
2#include <xrpld/app/misc/LoadFeeTrack.h>
3#include <xrpld/core/TimeKeeper.h>
4#include <xrpld/overlay/Cluster.h>
5#include <xrpld/overlay/Overlay.h>
6#include <xrpld/rpc/Context.h>
7
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/jss.h>
10
11namespace ripple {
12
15{
17
18 jvResult[jss::peers] = context.app.overlay().json();
19
20 // Legacy support
21 if (context.apiVersion == 1)
22 {
23 for (auto& p : jvResult[jss::peers])
24 {
25 if (p.isMember(jss::track))
26 {
27 auto const s = p[jss::track].asString();
28
29 if (s == "diverged")
30 p["sanity"] = "insane";
31 else if (s == "unknown")
32 p["sanity"] = "unknown";
33 }
34 }
35 }
36
37 auto const now = context.app.timeKeeper().now();
38 auto const self = context.app.nodeIdentity().first;
39
40 Json::Value& cluster = (jvResult[jss::cluster] = Json::objectValue);
41 std::uint32_t ref = context.app.getFeeTrack().getLoadBase();
42
43 context.app.cluster().for_each(
44 [&cluster, now, ref, &self](ClusterNode const& node) {
45 if (node.identity() == self)
46 return;
47
48 Json::Value& json =
49 cluster[toBase58(TokenType::NodePublic, node.identity())];
50
51 if (!node.name().empty())
52 json[jss::tag] = node.name();
53
54 if ((node.getLoadFee() != ref) && (node.getLoadFee() != 0))
55 json[jss::fee] = static_cast<double>(node.getLoadFee()) / ref;
56
57 if (node.getReportTime() != NetClock::time_point{})
58 json[jss::age] = (node.getReportTime() >= now)
59 ? 0
60 : (now - node.getReportTime()).count();
61 });
62
63 return jvResult;
64}
65
66} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
std::string asString() const
Returns the unquoted string value.
virtual Overlay & overlay()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual TimeKeeper & timeKeeper()=0
virtual Cluster & cluster()=0
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
std::string const & name() const
Definition ClusterNode.h:27
std::uint32_t getLoadFee() const
Definition ClusterNode.h:33
NetClock::time_point getReportTime() const
Definition ClusterNode.h:39
PublicKey const & identity() const
Definition ClusterNode.h:45
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition Cluster.cpp:64
std::uint32_t getLoadBase() const
virtual Json::Value json()=0
Return diagnostics on the status of all peers.
time_point now() const override
Returns the current time, using the server's clock.
Definition TimeKeeper.h:45
T empty(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Json::Value doPeers(RPC::JsonContext &)
Definition Peers.cpp:14
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
unsigned int apiVersion
Definition Context.h:30
Application & app
Definition Context.h:22