mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Allow subscription to peer status changes (RIPD-579)
Subscribe to "peer_status" stream (admin only) permits reception of "peerStatusChange" notifications. These can include the event the peer is reporting, the peer's new status, the peer's currently accepted ledger hash and sequence, the peer's network time, and the range of ledgers the peer has available for remote querying.
This commit is contained in:
@@ -1335,6 +1335,78 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMStatusChange> const& m)
|
||||
{
|
||||
checkSanity (m->ledgerseq(), app_.getLedgerMaster().getValidLedgerIndex());
|
||||
}
|
||||
|
||||
app_.getOPs().pubPeerStatus (
|
||||
[=]() -> Json::Value
|
||||
{
|
||||
Json::Value j = Json::objectValue;
|
||||
|
||||
if (m->has_newstatus ())
|
||||
{
|
||||
switch (m->newstatus ())
|
||||
{
|
||||
case protocol::nsCONNECTING:
|
||||
j[jss::status] = "CONNECTING";
|
||||
break;
|
||||
case protocol::nsCONNECTED:
|
||||
j[jss::status] = "CONNECTED";
|
||||
break;
|
||||
case protocol::nsMONITORING:
|
||||
j[jss::status] = "MONITORING";
|
||||
break;
|
||||
case protocol::nsVALIDATING:
|
||||
j[jss::status] = "VALIDATING";
|
||||
break;
|
||||
case protocol::nsSHUTTING:
|
||||
j[jss::status] = "SHUTTING";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m->has_newevent())
|
||||
{
|
||||
switch (m->newevent ())
|
||||
{
|
||||
case protocol::neCLOSING_LEDGER:
|
||||
j[jss::action] = "CLOSING_LEDGER";
|
||||
break;
|
||||
case protocol::neACCEPTED_LEDGER:
|
||||
j[jss::action] = "ACCEPTED_LEDGER";
|
||||
break;
|
||||
case protocol::neSWITCHED_LEDGER:
|
||||
j[jss::action] = "SWITCHED_LEDGER";
|
||||
break;
|
||||
case protocol::neLOST_SYNC:
|
||||
j[jss::action] = "LOST_SYNC";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m->has_ledgerseq ())
|
||||
{
|
||||
j[jss::ledger_index] = m->ledgerseq();
|
||||
}
|
||||
|
||||
if (m->has_ledgerhash ())
|
||||
{
|
||||
j[jss::ledger_hash] = to_string (closedLedgerHash_);
|
||||
}
|
||||
|
||||
if (m->has_networktime ())
|
||||
{
|
||||
j[jss::date] = Json::UInt (m->networktime());
|
||||
}
|
||||
|
||||
if (m->has_firstseq () && m->has_lastseq ())
|
||||
{
|
||||
j[jss::ledger_index_min] =
|
||||
Json::UInt (m->firstseq ());
|
||||
j[jss::ledger_index_max] =
|
||||
Json::UInt (m->lastseq ());
|
||||
}
|
||||
|
||||
return j;
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user