Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 19757 #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
i->second += result->m_raw_message_size;

// push the message to the process queue,
vRecvMsg.push_back(std::move(*result));
m_recv_msg_most_recent = vRecvMsg.insert_after(m_recv_msg_most_recent, std::move(*result));

complete = true;
}
Expand Down Expand Up @@ -1577,14 +1577,18 @@ void CConnman::SocketHandler()
if (notify) {
size_t nSizeAdded = 0;
auto it(pnode->vRecvMsg.begin());
for (; it != pnode->vRecvMsg.end(); ++it) {
// it2 will hold the before end iterator.
auto it2 = it;
for (; it != pnode->vRecvMsg.end(); it2 = it++) {
// vRecvMsg contains only completed CNetMessage
// the single possible partially deserialized message are held by TransportDeserializer
nSizeAdded += it->m_raw_message_size;
}
{
LOCK(pnode->cs_vProcessMsg);
pnode->vProcessMsg.splice(pnode->vProcessMsg.end(), pnode->vRecvMsg, pnode->vRecvMsg.begin(), it);
pnode->vProcessMsg.splice_after(pnode->m_process_msg_most_recent, pnode->vRecvMsg, pnode->vRecvMsg.before_begin(), it);
pnode->m_process_msg_most_recent = it2;
pnode->m_recv_msg_most_recent = pnode->vRecvMsg.before_begin();
pnode->nProcessQueueSize += nSizeAdded;
pnode->fPauseRecv = pnode->nProcessQueueSize > nReceiveFloodSize;
}
Expand Down Expand Up @@ -2984,6 +2988,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
m_conn_type(conn_type_in),
nLocalServices(nLocalServicesIn)
{
m_recv_msg_most_recent = vRecvMsg.before_begin();
m_process_msg_most_recent = vProcessMsg.before_begin();
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
hSocket = hSocketIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
Expand Down
7 changes: 5 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <optional>
#include <thread>
#include <vector>
#include <forward_list>

class CScheduler;
class CNode;
Expand Down Expand Up @@ -414,7 +415,8 @@ class CNode
Mutex cs_vRecv;

RecursiveMutex cs_vProcessMsg;
std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
std::forward_list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
std::forward_list<CNetMessage>::iterator m_process_msg_most_recent GUARDED_BY(cs_vProcessMsg);
size_t nProcessQueueSize{0};

RecursiveMutex cs_sendProcessing;
Expand Down Expand Up @@ -693,7 +695,8 @@ class CNode
//! service advertisements.
const ServiceFlags nLocalServices;

std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
std::forward_list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
std::forward_list<CNetMessage>::iterator m_recv_msg_most_recent;

mutable RecursiveMutex cs_addrName;
std::string addrName GUARDED_BY(cs_addrName);
Expand Down
6 changes: 4 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4035,12 +4035,14 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
// Don't bother if send buffer is too full to respond anyway
if (pfrom->fPauseSend) return false;

std::list<CNetMessage> msgs;
std::forward_list<CNetMessage> msgs;
{
LOCK(pfrom->cs_vProcessMsg);
if (pfrom->vProcessMsg.empty()) return false;
// Just take one message
msgs.splice(msgs.begin(), pfrom->vProcessMsg, pfrom->vProcessMsg.begin());
msgs.splice_after(msgs.before_begin(), pfrom->vProcessMsg, pfrom->vProcessMsg.before_begin());
if (pfrom->vProcessMsg.empty())
pfrom->m_process_msg_most_recent = pfrom->vProcessMsg.before_begin();
pfrom->nProcessQueueSize -= msgs.front().m_raw_message_size;
pfrom->fPauseRecv = pfrom->nProcessQueueSize > m_connman.GetReceiveFloodSize();
fMoreWork = !pfrom->vProcessMsg.empty();
Expand Down
7 changes: 5 additions & 2 deletions src/test/util/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_by
if (complete) {
size_t nSizeAdded = 0;
auto it(node.vRecvMsg.begin());
for (; it != node.vRecvMsg.end(); ++it) {
auto it2 = it;
for (; it != node.vRecvMsg.end(); it2 = it++) {
// vRecvMsg contains only completed CNetMessage
// the single possible partially deserialized message are held by TransportDeserializer
nSizeAdded += it->m_raw_message_size;
}
{
LOCK(node.cs_vProcessMsg);
node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
node.vProcessMsg.splice_after(node.m_process_msg_most_recent, node.vRecvMsg, node.vRecvMsg.before_begin(), it);
node.m_process_msg_most_recent = it2;
node.m_recv_msg_most_recent = node.vRecvMsg.before_begin();
node.nProcessQueueSize += nSizeAdded;
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
}
Expand Down