aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-10-18 12:03:13 -0700
committerJonas Schnelli <dev@jonasschnelli.ch>2019-10-23 09:27:32 +0200
commitf342a5e61a73e1edf389b662d265d20cf26a1d51 (patch)
tree360b936d99f52fe569f12664c68517279001d060 /src/net.h
parent6a91499496d76c2b3e84489e9723b60514fb08db (diff)
Make resetting implicit in TransportDeserializer::Read()
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/net.h b/src/net.h
index 570ae83465..f6a04f5166 100644
--- a/src/net.h
+++ b/src/net.h
@@ -638,8 +638,6 @@ public:
*/
class TransportDeserializer {
public:
- // prepare for next message
- virtual void Reset() = 0;
// returns true if the current deserialization is complete
virtual bool Complete() const = 0;
// set the serialization context version
@@ -666,11 +664,6 @@ private:
const uint256& GetMessageHash() const;
int readHeader(const char *pch, unsigned int nBytes);
int readData(const char *pch, unsigned int nBytes);
-public:
-
- V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
- Reset();
- }
void Reset() {
vRecv.clear();
@@ -682,6 +675,13 @@ public:
data_hash.SetNull();
hasher.Reset();
}
+
+public:
+
+ V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
+ Reset();
+ }
+
bool Complete() const
{
if (!in_data)
@@ -694,7 +694,9 @@ public:
vRecv.SetVersion(nVersionIn);
}
int Read(const char *pch, unsigned int nBytes) {
- return in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
+ int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
+ if (ret < 0) Reset();
+ return ret;
}
CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time);
};