aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-11-20 06:05:42 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-11-20 06:10:58 +0100
commitfdd068507d2694137d72638d87ea961e6f16a753 (patch)
tree30d062132e86047b71d7de2ff0c021ca3d8aea82 /src/net.h
parent46f0b2f97601e9d13277fd73bed9b0219bcdee5b (diff)
parentfa5ed3b4ca609426b2622cad235e107d33db7b30 (diff)
downloadbitcoin-fdd068507d2694137d72638d87ea961e6f16a753.tar.xz
Merge #20056: net: Use Span in ReceiveMsgBytes
fa5ed3b4ca609426b2622cad235e107d33db7b30 net: Use Span in ReceiveMsgBytes (MarcoFalke) Pull request description: Pass a data pointer and a size as span in `ReceiveMsgBytes` to get the benefits of a span ACKs for top commit: jonatack: ACK fa5ed3b4ca609426b2622cad235e107d33db7b30 code review, rebased to current master 12a1c3ad1a43634, debug build, unit tests, ran bitcoind/-netinfo/getpeerinfo theStack: ACK fa5ed3b4ca609426b2622cad235e107d33db7b30 Tree-SHA512: 89bf111323148d6e6e50185ad20ab39f73ab3a58a27e46319e3a08bcf5dcf9d6aa84faff0fd6afb90cb892ac2f557a237c144560986063bc736a69ace353ab9d
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/net.h b/src/net.h
index a6dcf7f610..b14c860f7d 100644
--- a/src/net.h
+++ b/src/net.h
@@ -757,8 +757,8 @@ public:
virtual bool Complete() const = 0;
// set the serialization context version
virtual void SetVersion(int version) = 0;
- // read and deserialize data
- virtual int Read(const char *data, unsigned int bytes) = 0;
+ /** read and deserialize data, advances msg_bytes data pointer */
+ virtual int Read(Span<const char>& msg_bytes) = 0;
// decomposes a message from the context
virtual Optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err) = 0;
virtual ~TransportDeserializer() {}
@@ -779,8 +779,8 @@ private:
unsigned int nDataPos;
const uint256& GetMessageHash() const;
- int readHeader(const char *pch, unsigned int nBytes);
- int readData(const char *pch, unsigned int nBytes);
+ int readHeader(Span<const char> msg_bytes);
+ int readData(Span<const char> msg_bytes);
void Reset() {
vRecv.clear();
@@ -814,9 +814,14 @@ public:
hdrbuf.SetVersion(nVersionIn);
vRecv.SetVersion(nVersionIn);
}
- int Read(const char *pch, unsigned int nBytes) override {
- int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
- if (ret < 0) Reset();
+ int Read(Span<const char>& msg_bytes) override
+ {
+ int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
+ if (ret < 0) {
+ Reset();
+ } else {
+ msg_bytes = msg_bytes.subspan(ret);
+ }
return ret;
}
Optional<CNetMessage> GetMessage(std::chrono::microseconds time, uint32_t& out_err_raw_size) override;
@@ -1118,7 +1123,16 @@ public:
return nRefCount;
}
- bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
+ /**
+ * Receive bytes from the buffer and deserialize them into messages.
+ *
+ * @param[in] msg_bytes The raw data
+ * @param[out] complete Set True if at least one message has been
+ * deserialized and is ready to be processed
+ * @return True if the peer should stay connected,
+ * False if the peer should be disconnected from.
+ */
+ bool ReceiveMsgBytes(Span<const char> msg_bytes, bool& complete);
void SetCommonVersion(int greatest_common_version)
{