mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Make resetting implicit in TransportDeserializer::Read()
This commit is contained in:
committed by
Jonas Schnelli
parent
6a91499496
commit
f342a5e61a
@@ -572,10 +572,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
|
|||||||
while (nBytes > 0) {
|
while (nBytes > 0) {
|
||||||
// absorb network data
|
// absorb network data
|
||||||
int handled = m_deserializer->Read(pch, nBytes);
|
int handled = m_deserializer->Read(pch, nBytes);
|
||||||
if (handled < 0) {
|
if (handled < 0) return false;
|
||||||
m_deserializer->Reset();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pch += handled;
|
pch += handled;
|
||||||
nBytes -= handled;
|
nBytes -= handled;
|
||||||
|
|||||||
18
src/net.h
18
src/net.h
@@ -638,8 +638,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
class TransportDeserializer {
|
class TransportDeserializer {
|
||||||
public:
|
public:
|
||||||
// prepare for next message
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
// returns true if the current deserialization is complete
|
// returns true if the current deserialization is complete
|
||||||
virtual bool Complete() const = 0;
|
virtual bool Complete() const = 0;
|
||||||
// set the serialization context version
|
// set the serialization context version
|
||||||
@@ -666,11 +664,6 @@ private:
|
|||||||
const uint256& GetMessageHash() const;
|
const uint256& GetMessageHash() const;
|
||||||
int readHeader(const char *pch, unsigned int nBytes);
|
int readHeader(const char *pch, unsigned int nBytes);
|
||||||
int readData(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() {
|
void Reset() {
|
||||||
vRecv.clear();
|
vRecv.clear();
|
||||||
@@ -682,6 +675,13 @@ public:
|
|||||||
data_hash.SetNull();
|
data_hash.SetNull();
|
||||||
hasher.Reset();
|
hasher.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
bool Complete() const
|
bool Complete() const
|
||||||
{
|
{
|
||||||
if (!in_data)
|
if (!in_data)
|
||||||
@@ -694,7 +694,9 @@ public:
|
|||||||
vRecv.SetVersion(nVersionIn);
|
vRecv.SetVersion(nVersionIn);
|
||||||
}
|
}
|
||||||
int Read(const char *pch, unsigned int nBytes) {
|
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);
|
CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user