Make resetting implicit in TransportDeserializer::Read()
This commit is contained in:
parent
6a91499496
commit
f342a5e61a
|
@ -572,10 +572,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
|
|||
while (nBytes > 0) {
|
||||
// absorb network data
|
||||
int handled = m_deserializer->Read(pch, nBytes);
|
||||
if (handled < 0) {
|
||||
m_deserializer->Reset();
|
||||
return false;
|
||||
}
|
||||
if (handled < 0) return false;
|
||||
|
||||
pch += handled;
|
||||
nBytes -= handled;
|
||||
|
|
18
src/net.h
18
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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue