xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
admin
peer
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
17
namespace
xrpl
{
18
19
json::Value
20
doPeers
(
rpc::JsonContext
& context)
21
{
22
json::Value
jvResult(
json::ValueType::Object
);
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
57
json::Value
&
json
= cluster[
toBase58
(
TokenType::NodePublic
, node.
identity
())];
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
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::Application::nodeIdentity
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
xrpl::ClusterNode
Definition
ClusterNode.h:13
xrpl::ClusterNode::getLoadFee
std::uint32_t getLoadFee() const
Definition
ClusterNode.h:33
xrpl::ClusterNode::getReportTime
NetClock::time_point getReportTime() const
Definition
ClusterNode.h:39
xrpl::ClusterNode::identity
PublicKey const & identity() const
Definition
ClusterNode.h:45
xrpl::ClusterNode::name
std::string const & name() const
Definition
ClusterNode.h:27
xrpl::Cluster::forEach
void forEach(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
Definition
Cluster.cpp:84
xrpl::LoadFeeTrack::getLoadBase
static std::uint32_t getLoadBase()
Definition
LoadFeeTrack.h:66
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::Overlay::json
virtual json::Value json()=0
Return diagnostics on the status of all peers.
xrpl::ServiceRegistry::getFeeTrack
virtual LoadFeeTrack & getFeeTrack()=0
xrpl::ServiceRegistry::getCluster
virtual Cluster & getCluster()=0
xrpl::ServiceRegistry::getOverlay
virtual Overlay & getOverlay()=0
xrpl::ServiceRegistry::getTimeKeeper
virtual TimeKeeper & getTimeKeeper()=0
xrpl::TimeKeeper::now
time_point now() const override
Returns the current time, using the server's clock.
Definition
TimeKeeper.h:48
cstdint
std::string::empty
T empty(T... args)
std::uint32_t
json
JSON (JavaScript Object Notation).
Definition
json_errors.h:5
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::doPeers
json::Value doPeers(rpc::JsonContext &context)
Definition
Peers.cpp:20
xrpl::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition
AccountID.cpp:95
xrpl::TokenType::NodePublic
@ NodePublic
Definition
tokens.h:21
xrpl::rpc::Context::apiVersion
unsigned int apiVersion
Definition
Context.h:37
xrpl::rpc::Context::app
Application & app
Definition
Context.h:29
xrpl::rpc::JsonContext
Definition
Context.h:41
Generated by
1.17.0