xrpld
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/ClusterNode.h>
5#include <xrpld/overlay/Overlay.h>
6#include <xrpld/rpc/Context.h>
7
8#include <xrpl/basics/chrono.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/protocol/PublicKey.h>
11#include <xrpl/protocol/jss.h>
12#include <xrpl/protocol/tokens.h>
13#include <xrpl/server/LoadFeeTrack.h>
14
15#include <cstdint>
16
17namespace xrpl {
18
19json::Value
21{
23
24 jvResult[jss::peers] = context.app.getOverlay().json();
25
26 // Legacy support
27 if (context.apiVersion == 1)
28 {
29 for (auto& p : jvResult[jss::peers])
30 {
31 if (p.isMember(jss::track))
32 {
33 auto const s = p[jss::track].asString();
34
35 if (s == "diverged")
36 {
37 p["sanity"] = "insane";
38 }
39 else if (s == "unknown")
40 {
41 p["sanity"] = "unknown";
42 }
43 }
44 }
45 }
46
47 auto const now = context.app.getTimeKeeper().now();
48 auto const self = context.app.nodeIdentity().first;
49
50 json::Value& cluster = (jvResult[jss::cluster] = json::ValueType::Object);
51 std::uint32_t const ref = context.app.getFeeTrack().getLoadBase();
52
53 context.app.getCluster().forEach([&cluster, now, ref, &self](ClusterNode const& node) {
54 if (node.identity() == self)
55 return;
56
58
59 if (!node.name().empty())
60 json[jss::tag] = node.name();
61
62 if ((node.getLoadFee() != ref) && (node.getLoadFee() != 0))
63 json[jss::fee] = static_cast<double>(node.getLoadFee()) / ref;
64
65 if (node.getReportTime() != NetClock::time_point{})
66 {
67 json[jss::age] =
68 (node.getReportTime() >= now) ? 0 : (now - node.getReportTime()).count();
69 }
70 });
71
72 return jvResult;
73}
74
75} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
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
std::string const & name() const
Definition ClusterNode.h:27
void forEach(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition Cluster.cpp:76
static std::uint32_t getLoadBase()
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
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)
JSON (JavaScript Object Notation).
Definition json_errors.h:5
@ Object
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:20
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
Application & app
Definition Context.h:21
unsigned int apiVersion
Definition Context.h:29