-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetmessage.h
63 lines (50 loc) · 1.73 KB
/
netmessage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef NETMESSAGE_H
#define NETMESSAGE_H
#include "protocol.h"
struct CSerializedNetMsg
{
CSerializedNetMsg() = default;
CSerializedNetMsg(CSerializedNetMsg&&) = default;
CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
// No copying, only moves.
CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
std::vector<unsigned char> data;
std::string command;
};
class CNetMessage {
private:
//mutable CHash256 hasher;
//mutable uint256 data_hash;
public:
bool in_data; // parsing header (false) or data (true)
//CDataStream hdrbuf; // partially received header
CMessageHeader hdr; // complete header
unsigned int nHdrPos;
// CDataStream vRecv; // received message data
unsigned int nDataPos;
int64_t nTime; // time (in microseconds) of message receipt.
CNetMessage(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : /*hdrbuf(nTypeIn, nVersionIn),*/
hdr(pchMessageStartIn)/*, vRecv(nTypeIn, nVersionIn)*/ {
// hdrbuf.resize(24);
in_data = false;
nHdrPos = 0;
nDataPos = 0;
nTime = 0;
}
bool complete() const
{
if (!in_data)
return false;
return (hdr.nMessageSize == nDataPos);
}
//const uint256& GetMessageHash() const;
// void SetVersion(int nVersionIn)
// {
// // hdrbuf.SetVersion(nVersionIn);
// //vRecv.SetVersion(nVersionIn);
// }
int readHeader(const char *pch, unsigned int nBytes);
int readData(const char *pch, unsigned int nBytes);
};
#endif // NETMESSAGE_H