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:
@@ -684,7 +684,7 @@
|
||||
catch (e) {
|
||||
liblog(1, e);
|
||||
liblog(0, "Exception deserializing: ");
|
||||
liblog(0, data || rcvd);
|
||||
liblog(0, (data && (isTextMode ? data.toString() : data) || rcvd));
|
||||
|
||||
// If we get invalid message during handshake, close the socket.
|
||||
if (connectionStatus < 2)
|
||||
|
||||
17
src/conf.hpp
17
src/conf.hpp
@@ -15,7 +15,7 @@ namespace conf
|
||||
struct peer_ip_port
|
||||
{
|
||||
std::string host_address;
|
||||
uint16_t port;
|
||||
uint16_t port = 0;
|
||||
|
||||
bool operator==(const peer_ip_port &other) const
|
||||
{
|
||||
@@ -31,6 +31,11 @@ namespace conf
|
||||
{
|
||||
return (host_address == other.host_address) ? port < other.port : host_address < other.host_address;
|
||||
}
|
||||
|
||||
const std::string to_string() const
|
||||
{
|
||||
return host_address + ":" + std::to_string(port);
|
||||
}
|
||||
};
|
||||
|
||||
// The role of the contract node.
|
||||
@@ -50,8 +55,8 @@ namespace conf
|
||||
// Max number of shards to keep for primary and raw shards.
|
||||
struct history_configuration
|
||||
{
|
||||
uint64_t max_primary_shards; // Maximum number of shards for primary shards.
|
||||
uint64_t max_raw_shards; // Maximum number of shards for raw data shards.
|
||||
uint64_t max_primary_shards = 0; // Maximum number of shards for primary shards.
|
||||
uint64_t max_raw_shards = 0; // Maximum number of shards for raw data shards.
|
||||
};
|
||||
|
||||
// Log severity levels used in Hot Pocket.
|
||||
@@ -68,8 +73,8 @@ namespace conf
|
||||
std::string loglevel; // Log severity level (debug, info, warn, error)
|
||||
LOG_SEVERITY loglevel_type; // Log severity level enum (debug, info, warn, error)
|
||||
std::unordered_set<std::string> loggers; // List of enabled loggers (console, file)
|
||||
size_t max_mbytes_per_file; // Max MB size of a single log file.
|
||||
size_t max_file_count; // Max no. of log files to keep.
|
||||
size_t max_mbytes_per_file = 0; // Max MB size of a single log file.
|
||||
size_t max_file_count = 0; // Max no. of log files to keep.
|
||||
};
|
||||
|
||||
struct node_config
|
||||
@@ -189,7 +194,7 @@ namespace conf
|
||||
std::string tls_key_file; // Full path to the tls private key file.
|
||||
std::string tls_cert_file; // Full path to the tls certificate.
|
||||
|
||||
int config_fd; // Config file file descriptor.
|
||||
int config_fd = -1; // Config file file descriptor.
|
||||
struct flock config_lock; // Config file lock.
|
||||
};
|
||||
|
||||
|
||||
@@ -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