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