mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Refactoring hpfs, hpfs sync and hpfs serve code. (#231)
* Refactoring hpfs code to a class so it can support multiple mounts. * Refactoring hpfs serve into a class to support mulitiple mount serving. * Refactoring hpfs sync into class to support multiple instances. * Code improvements in hpfs_sync. * Taking a sync target list for hpfs syncing target set.
This commit is contained in:
committed by
GitHub
parent
08680ee8d4
commit
d08d2630f6
@@ -14,6 +14,7 @@
|
||||
#include "peer_comm_session.hpp"
|
||||
#include "p2p.hpp"
|
||||
#include "../unl.hpp"
|
||||
#include "../hpfs/hpfs.hpp"
|
||||
|
||||
namespace p2pmsg = msg::fbuf::p2pmsg;
|
||||
|
||||
@@ -192,36 +193,44 @@ namespace p2p
|
||||
}
|
||||
else if (content_message_type == p2pmsg::Message_Hpfs_Request_Message)
|
||||
{
|
||||
// Check the cap and insert request with lock.
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.hpfs_requests_mutex);
|
||||
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(content_ptr);
|
||||
const p2p::hpfs_request hr = p2pmsg::create_hpfs_request_from_msg(*content->message_as_Hpfs_Request_Message());
|
||||
if (hr.mount_id == hpfs::contract_fs.mount_id)
|
||||
{
|
||||
// Check the cap and insert request with lock.
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.contract_hpfs_requests_mutex);
|
||||
|
||||
// If max number of state requests reached skip the rest.
|
||||
if (ctx.collected_msgs.hpfs_requests.size() < p2p::STATE_REQ_LIST_CAP)
|
||||
{
|
||||
std::string state_request_msg(reinterpret_cast<const char *>(content_ptr), content_size);
|
||||
ctx.collected_msgs.hpfs_requests.push_back(std::make_pair(session.pubkey, std::move(state_request_msg)));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG << "State request rejected. Maximum state request count reached. " << session.display_name();
|
||||
// If max number of state requests reached skip the rest.
|
||||
if (ctx.collected_msgs.contract_hpfs_requests.size() < p2p::HPFS_REQ_LIST_CAP)
|
||||
{
|
||||
ctx.collected_msgs.contract_hpfs_requests.push_back(std::make_pair(session.pubkey, std::move(hr)));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG << "Hpfs contract fs request rejected. Maximum hpfs contract fs request count reached. " << session.display_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (content_message_type == p2pmsg::Message_Hpfs_Response_Message)
|
||||
{
|
||||
if (hpfs_sync::ctx.is_syncing) // Only accept state responses if state is syncing.
|
||||
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(content_ptr);
|
||||
const msg::fbuf::p2pmsg::Hpfs_Response_Message *resp_msg = content->message_as_Hpfs_Response_Message();
|
||||
|
||||
// Only accept hpfs responses if hpfs fs is syncing.
|
||||
if (hpfs::contract_sync.ctx.is_syncing && resp_msg->mount_id() == hpfs::contract_fs.mount_id)
|
||||
{
|
||||
// Check the cap and insert state_response with lock.
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.hpfs_responses_mutex);
|
||||
std::scoped_lock<std::mutex> lock(ctx.collected_msgs.contract_hpfs_responses_mutex);
|
||||
|
||||
// If max number of state responses reached skip the rest.
|
||||
if (ctx.collected_msgs.hpfs_responses.size() < p2p::STATE_RES_LIST_CAP)
|
||||
if (ctx.collected_msgs.contract_hpfs_responses.size() < p2p::HPFS_RES_LIST_CAP)
|
||||
{
|
||||
std::string response(reinterpret_cast<const char *>(content_ptr), content_size);
|
||||
ctx.collected_msgs.hpfs_responses.push_back(std::make_pair(session.uniqueid, std::move(response)));
|
||||
ctx.collected_msgs.contract_hpfs_responses.push_back(std::make_pair(session.uniqueid, std::move(response)));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG << "State response rejected. Maximum state response count reached. " << session.display_name();
|
||||
LOG_DEBUG << "Contract hpfs response rejected. Maximum contract hpfs response count reached. " << session.display_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user