mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Improved user inputs handling in consensus (#46)
Updated flatbuffer proposal raw_inputs, raw_outputs data structure. Improved user inputs handling in consensus.
This commit is contained in:
@@ -31,13 +31,13 @@ std::mutex users_mutex; // Mutex for users access race conditions.
|
||||
* This is used for pubkey duplicate checks as well.
|
||||
* Map key: User binary pubkey
|
||||
*/
|
||||
std::unordered_map<std::string, std::string> sessionids;
|
||||
std::unordered_map<std::string, const std::string> sessionids;
|
||||
|
||||
/**
|
||||
* Keep track of verification-pending challenges issued to newly connected users.
|
||||
* Map key: User socket session id (<ip:port>)
|
||||
*/
|
||||
std::unordered_map<std::string, std::string> pending_challenges;
|
||||
std::unordered_map<std::string, const std::string> pending_challenges;
|
||||
|
||||
/**
|
||||
* User session handler instance. This instance's methods will be fired for any user socket activity.
|
||||
@@ -152,7 +152,10 @@ int verify_user_challenge_response(std::string &extracted_pubkeyhex, std::string
|
||||
{
|
||||
// We load response raw bytes into json document.
|
||||
rapidjson::Document d;
|
||||
d.Parse(response.data());
|
||||
|
||||
// Because we project the response message directly from the binary socket buffer in a zero-copy manner, the response
|
||||
// string is not null terminated. 'kParseStopWhenDoneFlag' avoids rapidjson error in this case.
|
||||
d.Parse<rapidjson::kParseStopWhenDoneFlag>(response.data());
|
||||
if (d.HasParseError())
|
||||
{
|
||||
LOG_INFO << "Challenge response json parsing failed.";
|
||||
@@ -226,7 +229,7 @@ int add_user(sock::socket_session<user_outbound_message> *session, const std::st
|
||||
}
|
||||
|
||||
// Populate sessionid map so we can lookup by user pubkey.
|
||||
sessionids[pubkey] = sessionid;
|
||||
sessionids.try_emplace(pubkey, sessionid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -254,7 +257,7 @@ int remove_user(const std::string &sessionid)
|
||||
std::lock_guard<std::mutex> lock(users_mutex);
|
||||
sessionids.erase(user.pubkey);
|
||||
}
|
||||
|
||||
|
||||
users.erase(itr);
|
||||
return 0;
|
||||
}
|
||||
@@ -268,7 +271,6 @@ void start_listening()
|
||||
auto address = net::ip::make_address(conf::cfg.listenip);
|
||||
sess_opts.max_message_size = conf::cfg.pubmaxsize;
|
||||
|
||||
|
||||
std::make_shared<sock::socket_server<user_outbound_message>>(
|
||||
ioc,
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user