aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-09-30 17:08:26 +0200
committerMarcoFalke <falke.marco@gmail.com>2020-10-02 16:26:33 +0200
commitfa5ed3b4ca609426b2622cad235e107d33db7b30 (patch)
treec5fccc954fccb4b2eb028a2dc656493e03c4066c /src/net.h
parent69a73803dfb2f65919660902d126487906a31770 (diff)
downloadbitcoin-fa5ed3b4ca609426b2622cad235e107d33db7b30.tar.xz
net: Use Span in ReceiveMsgBytes
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 fb68827144..93aaab12cf 100644
--- a/src/net.h
+++ b/src/net.h
@@ -745,8 +745,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() {}
@@ -767,8 +767,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();
@@ -802,9 +802,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;
@@ -1088,7 +1093,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)
{