diff options
author | Pieter Wuille <pieter@wuille.net> | 2023-08-14 16:37:05 -0400 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2023-08-23 19:56:24 -0400 |
commit | 649a83c7f73db2ee115f5dce3df16622e318aeba (patch) | |
tree | 7aa2417d7c54f6446f2f5ee8f1a647b07ad6dd11 /src/net.h | |
parent | 27f9ba23efe82531a465c5e63bf7dc62b6a3a8db (diff) |
refactor: rename Transport class receive functions
Now that the Transport class deals with both the sending and receiving side
of things, make the receive side have function names that clearly indicate
they're about receiving.
* Transport::Read() -> Transport::ReceivedBytes()
* Transport::Complete() -> Transport::ReceivedMessageComplete()
* Transport::GetMessage() -> Transport::GetReceivedMessage()
* Transport::SetVersion() -> Transport::SetReceiveVersion()
Further, also update the comments on these functions to (among others) remove
the "deserialization" terminology. That term is better reserved for just the
serialization/deserialization between objects and bytes (see serialize.h), and
not the conversion from/to wire bytes as performed by the Transport.
Diffstat (limited to 'src/net.h')
-rw-r--r-- | src/net.h | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -261,14 +261,14 @@ public: // 1. Receiver side functions, for decoding bytes received on the wire into transport protocol // agnostic CNetMessage (message type & payload) objects. - // returns true if the current deserialization is complete - virtual bool Complete() const = 0; - // set the deserialization context version - virtual void SetVersion(int version) = 0; - /** read and deserialize data, advances msg_bytes data pointer */ - virtual int Read(Span<const uint8_t>& msg_bytes) = 0; - // decomposes a message from the context - virtual CNetMessage GetMessage(std::chrono::microseconds time, bool& reject_message) = 0; + /** Returns true if the current message is complete (so GetReceivedMessage can be called). */ + virtual bool ReceivedMessageComplete() const = 0; + /** Set the deserialization context version for objects returned by GetReceivedMessage. */ + virtual void SetReceiveVersion(int version) = 0; + /** Feed wire bytes to the transport; chops off consumed bytes off front of msg_bytes. */ + virtual int ReceivedBytes(Span<const uint8_t>& msg_bytes) = 0; + /** Retrieve a completed message from transport (only when ReceivedMessageComplete). */ + virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0; // 2. Sending side functions: @@ -325,13 +325,13 @@ public: Reset(); } - bool Complete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) + bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) { AssertLockNotHeld(m_recv_mutex); return WITH_LOCK(m_recv_mutex, return CompleteInternal()); } - void SetVersion(int nVersionIn) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) + void SetReceiveVersion(int nVersionIn) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) { AssertLockNotHeld(m_recv_mutex); LOCK(m_recv_mutex); @@ -339,7 +339,7 @@ public: vRecv.SetVersion(nVersionIn); } - int Read(Span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) + int ReceivedBytes(Span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) { AssertLockNotHeld(m_recv_mutex); LOCK(m_recv_mutex); @@ -351,7 +351,8 @@ public: } return ret; } - CNetMessage GetMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex); + + CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex); void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) const override; }; |