aboutsummaryrefslogtreecommitdiff
path: root/src/test/util
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2023-07-21 16:31:59 -0400
committerPieter Wuille <pieter@wuille.net>2023-08-23 19:56:24 -0400
commit0de48fe858a1ffcced340eef2c849165216141c8 (patch)
tree71f5f482da77208beb51b7c6dc4c6ca721420d94 /src/test/util
parent649a83c7f73db2ee115f5dce3df16622e318aeba (diff)
net: abstract sending side of transport serialization further
This makes the sending side of P2P transports mirror the receiver side: caller provides message (consisting of type and payload) to be sent, and then asks what bytes must be sent. Once the message has been fully sent, a new message can be provided. This removes the assumption that P2P serialization of messages follows a strict structure of header (a function of type and payload), followed by (unmodified) payload, and instead lets transports decide the structure themselves. It also removes the assumption that a message must always be sent at once, or that no bytes are even sent on the wire when there is no message. This opens the door for supporting traffic shaping mechanisms in the future.
Diffstat (limited to 'src/test/util')
-rw-r--r--src/test/util/net.cpp21
-rw-r--r--src/test/util/net.h2
2 files changed, 13 insertions, 10 deletions
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp
index 0031770028..c071355bc0 100644
--- a/src/test/util/net.cpp
+++ b/src/test/util/net.cpp
@@ -41,7 +41,7 @@ void ConnmanTestMsg::Handshake(CNode& node,
relay_txs),
};
- (void)connman.ReceiveMsgFrom(node, msg_version);
+ (void)connman.ReceiveMsgFrom(node, std::move(msg_version));
node.fPauseSend = false;
connman.ProcessMessagesOnce(node);
peerman.SendMessages(&node);
@@ -54,7 +54,7 @@ void ConnmanTestMsg::Handshake(CNode& node,
assert(statestats.their_services == remote_services);
if (successfully_connected) {
CSerializedNetMsg msg_verack{mm.Make(NetMsgType::VERACK)};
- (void)connman.ReceiveMsgFrom(node, msg_verack);
+ (void)connman.ReceiveMsgFrom(node, std::move(msg_verack));
node.fPauseSend = false;
connman.ProcessMessagesOnce(node);
peerman.SendMessages(&node);
@@ -70,14 +70,17 @@ void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_by
}
}
-bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const
+bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) const
{
- std::vector<uint8_t> ser_msg_header;
- node.m_transport->prepareForTransport(ser_msg, ser_msg_header);
-
- bool complete;
- NodeReceiveMsgBytes(node, ser_msg_header, complete);
- NodeReceiveMsgBytes(node, ser_msg.data, complete);
+ bool queued = node.m_transport->SetMessageToSend(ser_msg);
+ assert(queued);
+ bool complete{false};
+ while (true) {
+ const auto& [to_send, _more, _msg_type] = node.m_transport->GetBytesToSend();
+ if (to_send.empty()) break;
+ NodeReceiveMsgBytes(node, to_send, complete);
+ node.m_transport->MarkBytesSent(to_send.size());
+ }
return complete;
}
diff --git a/src/test/util/net.h b/src/test/util/net.h
index b2f6ebb163..687ce1e813 100644
--- a/src/test/util/net.h
+++ b/src/test/util/net.h
@@ -54,7 +54,7 @@ struct ConnmanTestMsg : public CConnman {
void NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_bytes, bool& complete) const;
- bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const;
+ bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg&& ser_msg) const;
};
constexpr ServiceFlags ALL_SERVICE_FLAGS[]{