rippled
Loading...
Searching...
No Matches
Peers.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/misc/LoadFeeTrack.h>
22#include <xrpld/core/TimeKeeper.h>
23#include <xrpld/overlay/Cluster.h>
24#include <xrpld/overlay/Overlay.h>
25#include <xrpld/rpc/Context.h>
26
27#include <xrpl/protocol/ErrorCodes.h>
28#include <xrpl/protocol/jss.h>
29
30namespace ripple {
31
34{
36
37 jvResult[jss::peers] = context.app.overlay().json();
38
39 // Legacy support
40 if (context.apiVersion == 1)
41 {
42 for (auto& p : jvResult[jss::peers])
43 {
44 if (p.isMember(jss::track))
45 {
46 auto const s = p[jss::track].asString();
47
48 if (s == "diverged")
49 p["sanity"] = "insane";
50 else if (s == "unknown")
51 p["sanity"] = "unknown";
52 }
53 }
54 }
55
56 auto const now = context.app.timeKeeper().now();
57 auto const self = context.app.nodeIdentity().first;
58
59 Json::Value& cluster = (jvResult[jss::cluster] = Json::objectValue);
60 std::uint32_t ref = context.app.getFeeTrack().getLoadBase();
61
62 context.app.cluster().for_each(
63 [&cluster, now, ref, &self](ClusterNode const& node) {
64 if (node.identity() == self)
65 return;
66
67 Json::Value& json =
68 cluster[toBase58(TokenType::NodePublic, node.identity())];
69
70 if (!node.name().empty())
71 json[jss::tag] = node.name();
72
73 if ((node.getLoadFee() != ref) && (node.getLoadFee() != 0))
74 json[jss::fee] = static_cast<double>(node.getLoadFee()) / ref;
75
76 if (node.getReportTime() != NetClock::time_point{})
77 json[jss::age] = (node.getReportTime() >= now)
78 ? 0
79 : (now - node.getReportTime()).count();
80 });
81
82 return jvResult;
83}
84
85} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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:46
std::uint32_t getLoadFee() const
Definition ClusterNode.h:52
NetClock::time_point getReportTime() const
Definition ClusterNode.h:58
PublicKey const & identity() const
Definition ClusterNode.h:64
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition Cluster.cpp:83
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:64
T empty(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Json::Value doPeers(RPC::JsonContext &)
Definition Peers.cpp:33
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
unsigned int apiVersion
Definition Context.h:49
Application & app
Definition Context.h:41