Skip to content

Commit f342a5e

Browse files
sipajonasschnelli
authored andcommitted
Make resetting implicit in TransportDeserializer::Read()
1 parent 6a91499 commit f342a5e

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/net.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
572572
while (nBytes > 0) {
573573
// absorb network data
574574
int handled = m_deserializer->Read(pch, nBytes);
575-
if (handled < 0) {
576-
m_deserializer->Reset();
577-
return false;
578-
}
575+
if (handled < 0) return false;
579576

580577
pch += handled;
581578
nBytes -= handled;

src/net.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,6 @@ class CNetMessage {
638638
*/
639639
class TransportDeserializer {
640640
public:
641-
// prepare for next message
642-
virtual void Reset() = 0;
643641
// returns true if the current deserialization is complete
644642
virtual bool Complete() const = 0;
645643
// set the serialization context version
@@ -666,11 +664,6 @@ class V1TransportDeserializer : public TransportDeserializer
666664
const uint256& GetMessageHash() const;
667665
int readHeader(const char *pch, unsigned int nBytes);
668666
int readData(const char *pch, unsigned int nBytes);
669-
public:
670-
671-
V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
672-
Reset();
673-
}
674667

675668
void Reset() {
676669
vRecv.clear();
@@ -682,6 +675,13 @@ class V1TransportDeserializer : public TransportDeserializer
682675
data_hash.SetNull();
683676
hasher.Reset();
684677
}
678+
679+
public:
680+
681+
V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
682+
Reset();
683+
}
684+
685685
bool Complete() const
686686
{
687687
if (!in_data)
@@ -694,7 +694,9 @@ class V1TransportDeserializer : public TransportDeserializer
694694
vRecv.SetVersion(nVersionIn);
695695
}
696696
int Read(const char *pch, unsigned int nBytes) {
697-
return in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
697+
int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
698+
if (ret < 0) Reset();
699+
return ret;
698700
}
699701
CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time);
700702
};

0 commit comments

Comments
 (0)