mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Fixed get status peer address formatting crash. (#295)
This commit is contained in:
@@ -20,8 +20,6 @@ namespace msg::usrmsg::bson
|
||||
* "ledger_hash": <binary lcl hash>
|
||||
* }
|
||||
*/
|
||||
constexpr const size_t MAX_KNOWN_PEERS_INFO = 10;
|
||||
|
||||
void create_status_response(std::vector<uint8_t> &msg, const uint64_t lcl_seq_no, std::string_view lcl_hash)
|
||||
{
|
||||
jsoncons::bson::bson_bytes_encoder encoder(msg);
|
||||
@@ -58,8 +56,15 @@ namespace msg::usrmsg::bson
|
||||
|
||||
encoder.begin_array();
|
||||
// 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++, count++)
|
||||
encoder.string_value(peer->second->known_ipport->host_address + ":" + std::to_string(peer->second->known_ipport->port));
|
||||
for (auto peer = p2p::ctx.peer_connections.begin(); peer != p2p::ctx.peer_connections.end() && count <= max_peers_count; peer++)
|
||||
{
|
||||
const p2p::peer_comm_session *sess = peer->second;
|
||||
if (sess->known_ipport)
|
||||
{
|
||||
encoder.string_value(sess->known_ipport->to_string());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
encoder.end_array();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ namespace msg::usrmsg::json
|
||||
constexpr const char *OPEN_SQR_BRACKET = "[";
|
||||
constexpr const char *CLOSE_SQR_BRACKET = "]";
|
||||
|
||||
constexpr const size_t MAX_KNOWN_PEERS_INFO = 10;
|
||||
|
||||
// std::vector overload to concatonate string.
|
||||
std::vector<uint8_t> &operator+=(std::vector<uint8_t> &vec, std::string_view sv)
|
||||
{
|
||||
@@ -203,12 +201,16 @@ namespace msg::usrmsg::json
|
||||
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++, count++)
|
||||
for (auto peer = p2p::ctx.peer_connections.begin(); peer != p2p::ctx.peer_connections.end() && count <= max_peers_count; peer++)
|
||||
{
|
||||
msg += DOUBLE_QUOTE + peer->second->known_ipport->host_address + ":" + std::to_string(peer->second->known_ipport->port) + DOUBLE_QUOTE;
|
||||
|
||||
if (peer != p2p::ctx.peer_connections.end() && count < max_peers_count)
|
||||
msg += ",";
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace msg::usrmsg
|
||||
// Length of user random challenge bytes.
|
||||
constexpr size_t CHALLENGE_LEN = 16;
|
||||
|
||||
// Max no. of known peers to return in get status.
|
||||
constexpr const size_t MAX_KNOWN_PEERS_INFO = 10;
|
||||
|
||||
// Message field names
|
||||
constexpr const char *FLD_HP_VERSION = "hp_version";
|
||||
constexpr const char *FLD_TYPE = "type";
|
||||
|
||||
Reference in New Issue
Block a user