mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Status tracking infrastructure. (#317)
* Added node's current status information tracker. * Used the status tracker for responding to status messages. * Used change-event notifications to broadcast UNL change event.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "../../pchheader.hpp"
|
||||
#include "../../util/version.hpp"
|
||||
#include "../../util/sequence_hash.hpp"
|
||||
#include "../../util/util.hpp"
|
||||
#include "../../util/merkle_hash_tree.hpp"
|
||||
#include "../../unl.hpp"
|
||||
@@ -7,6 +8,7 @@
|
||||
#include "../../hplog.hpp"
|
||||
#include "../../conf.hpp"
|
||||
#include "../../ledger/ledger_query.hpp"
|
||||
#include "../../status.hpp"
|
||||
#include "../usrmsg_common.hpp"
|
||||
#include "usrmsg_json.hpp"
|
||||
|
||||
@@ -138,9 +140,12 @@ namespace msg::usrmsg::json
|
||||
* "ledger_hash": "<lcl hash hex>"
|
||||
* }
|
||||
*/
|
||||
void create_status_response(std::vector<uint8_t> &msg, const uint64_t lcl_seq_no, std::string_view lcl_hash)
|
||||
void create_status_response(std::vector<uint8_t> &msg)
|
||||
{
|
||||
const uint16_t msg_length = 406 + (69 * conf::cfg.contract.unl.size());
|
||||
const util::sequence_hash lcl_id = status::get_lcl_id();
|
||||
const std::set<std::string> unl = status::get_unl();
|
||||
|
||||
const uint16_t msg_length = 406 + (69 * unl.size());
|
||||
|
||||
msg.reserve(msg_length);
|
||||
msg += "{\"";
|
||||
@@ -154,11 +159,11 @@ namespace msg::usrmsg::json
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_LEDGER_SEQ_NO;
|
||||
msg += SEP_COLON_NOQUOTE;
|
||||
msg += std::to_string(lcl_seq_no);
|
||||
msg += std::to_string(lcl_id.seq_no);
|
||||
msg += SEP_COMMA_NOQUOTE;
|
||||
msg += msg::usrmsg::FLD_LEDGER_HASH;
|
||||
msg += SEP_COLON;
|
||||
msg += util::to_hex(lcl_hash);
|
||||
msg += util::to_hex(lcl_id.hash.to_string_view());
|
||||
msg += SEP_COMMA;
|
||||
msg += msg::usrmsg::FLD_ROUND_TIME;
|
||||
msg += SEP_COLON_NOQUOTE;
|
||||
@@ -180,11 +185,11 @@ namespace msg::usrmsg::json
|
||||
msg += SEP_COLON_NOQUOTE;
|
||||
msg += OPEN_SQR_BRACKET;
|
||||
|
||||
for (auto node = conf::cfg.contract.unl.begin(); node != conf::cfg.contract.unl.end(); node++)
|
||||
for (auto pubkey = unl.begin(); pubkey != unl.end(); pubkey++)
|
||||
{
|
||||
msg += DOUBLE_QUOTE + util::to_hex(*node) + DOUBLE_QUOTE;
|
||||
msg += DOUBLE_QUOTE + util::to_hex(*pubkey) + DOUBLE_QUOTE;
|
||||
|
||||
if (std::next(node) != conf::cfg.contract.unl.end())
|
||||
if (std::next(pubkey) != unl.end())
|
||||
msg += ",";
|
||||
}
|
||||
|
||||
@@ -195,22 +200,16 @@ namespace msg::usrmsg::json
|
||||
msg += OPEN_SQR_BRACKET;
|
||||
|
||||
{
|
||||
std::scoped_lock<std::mutex> lock(p2p::ctx.peer_connections_mutex);
|
||||
|
||||
const size_t max_peers_count = MIN(MAX_KNOWN_PEERS_INFO, p2p::ctx.peer_connections.size());
|
||||
const std::set<conf::peer_ip_port> peers = status::get_peers();
|
||||
const size_t max_peers_count = MIN(MAX_KNOWN_PEERS_INFO, peers.size());
|
||||
size_t count = 1;
|
||||
|
||||
// Currently all peers, up to a max of 10 are sent regardless of state.
|
||||
for (auto peer = p2p::ctx.peer_connections.begin(); peer != p2p::ctx.peer_connections.end() && count <= max_peers_count; peer++)
|
||||
for (auto peer = peers.begin(); peer != peers.end() && count <= max_peers_count; peer++)
|
||||
{
|
||||
const p2p::peer_comm_session *sess = peer->second;
|
||||
if (sess->known_ipport)
|
||||
{
|
||||
if (count > 1)
|
||||
msg += ",";
|
||||
msg += DOUBLE_QUOTE + sess->known_ipport->to_string() + DOUBLE_QUOTE;
|
||||
count++;
|
||||
}
|
||||
if (count > 1)
|
||||
msg += ",";
|
||||
msg += DOUBLE_QUOTE + peer->to_string() + DOUBLE_QUOTE;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user