Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.h
Show All 12 Lines | |||||
#include "netaddress.h" | #include "netaddress.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include "version.h" | #include "version.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <string> | #include <string> | ||||
/** Message header. | /** | ||||
* Message header. | |||||
* (4) message start. | * (4) message start. | ||||
* (12) command. | * (12) command. | ||||
* (4) size. | * (4) size. | ||||
* (4) checksum. | * (4) checksum. | ||||
*/ | */ | ||||
class CMessageHeader { | class CMessageHeader { | ||||
public: | public: | ||||
enum { | enum { | ||||
MESSAGE_START_SIZE = 4, | MESSAGE_START_SIZE = 4, | ||||
COMMAND_SIZE = 12, | COMMAND_SIZE = 12, | ||||
MESSAGE_SIZE_SIZE = 4, | MESSAGE_SIZE_SIZE = 4, | ||||
CHECKSUM_SIZE = 4, | CHECKSUM_SIZE = 4, | ||||
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, | MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, | ||||
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE, | CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE, | ||||
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + | HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + | ||||
CHECKSUM_SIZE | CHECKSUM_SIZE | ||||
}; | }; | ||||
typedef uint8_t MessageStartChars[MESSAGE_START_SIZE]; | typedef uint8_t MessageMagic[MESSAGE_START_SIZE]; | ||||
CMessageHeader(const MessageStartChars &pchMessageStartIn); | CMessageHeader(const MessageMagic &pchMessageStartIn); | ||||
CMessageHeader(const MessageStartChars &pchMessageStartIn, | CMessageHeader(const MessageMagic &pchMessageStartIn, | ||||
const char *pszCommand, unsigned int nMessageSizeIn); | const char *pszCommand, unsigned int nMessageSizeIn); | ||||
std::string GetCommand() const; | std::string GetCommand() const; | ||||
bool IsValid(const MessageStartChars &messageStart) const; | bool IsValid(const MessageMagic &messageStart) const; | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(FLATDATA(pchMessageStart)); | READWRITE(FLATDATA(pchMessageStart)); | ||||
READWRITE(FLATDATA(pchCommand)); | READWRITE(FLATDATA(pchCommand)); | ||||
READWRITE(nMessageSize); | READWRITE(nMessageSize); | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |