Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.h
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | public: | ||||
CMessageHeader(const MessageMagic &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 Config &config) const; | bool IsValid(const Config &config) const; | ||||
bool IsValidWithoutConfig(const MessageMagic &magic) const; | bool IsValidWithoutConfig(const MessageMagic &magic) const; | ||||
bool IsOversized(const Config &config) const; | bool IsOversized(const Config &config) const; | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(CMessageHeader, obj) { | ||||
READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, | |||||
template <typename Stream, typename Operation> | obj.pchChecksum); | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(pchMessageStart); | |||||
READWRITE(pchCommand); | |||||
READWRITE(nMessageSize); | |||||
READWRITE(pchChecksum); | |||||
} | } | ||||
MessageMagic pchMessageStart; | MessageMagic pchMessageStart; | ||||
std::array<char, COMMAND_SIZE> pchCommand; | std::array<char, COMMAND_SIZE> pchCommand; | ||||
uint32_t nMessageSize; | uint32_t nMessageSize; | ||||
uint8_t pchChecksum[CHECKSUM_SIZE]; | uint8_t pchChecksum[CHECKSUM_SIZE]; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
class CAddress : public CService { | class CAddress : public CService { | ||||
public: | public: | ||||
CAddress(); | CAddress(); | ||||
explicit CAddress(CService ipIn, ServiceFlags nServicesIn); | explicit CAddress(CService ipIn, ServiceFlags nServicesIn); | ||||
void Init(); | void Init(); | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(CAddress, obj) { | ||||
SER_READ(obj, obj.Init()); | |||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
if (ser_action.ForRead()) { | |||||
Init(); | |||||
} | |||||
int nVersion = s.GetVersion(); | int nVersion = s.GetVersion(); | ||||
if (s.GetType() & SER_DISK) { | if (s.GetType() & SER_DISK) { | ||||
READWRITE(nVersion); | READWRITE(nVersion); | ||||
} | } | ||||
if ((s.GetType() & SER_DISK) || | if ((s.GetType() & SER_DISK) || | ||||
(nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) { | (nVersion != INIT_PROTO_VERSION && !(s.GetType() & SER_GETHASH))) { | ||||
// The only time we serialize a CAddress object without nTime is in | // The only time we serialize a CAddress object without nTime is in | ||||
// the initial VERSION messages which contain two CAddress records. | // the initial VERSION messages which contain two CAddress records. | ||||
// At that point, the serialization version is INIT_PROTO_VERSION. | // At that point, the serialization version is INIT_PROTO_VERSION. | ||||
// After the version handshake, serialization version is >= | // After the version handshake, serialization version is >= | ||||
// MIN_PEER_PROTO_VERSION and all ADDR messages are serialized with | // MIN_PEER_PROTO_VERSION and all ADDR messages are serialized with | ||||
// nTime. | // nTime. | ||||
READWRITE(nTime); | READWRITE(obj.nTime); | ||||
} | } | ||||
uint64_t nServicesInt = nServices; | READWRITE(Using<CustomUintFormatter<8>>(obj.nServices)); | ||||
READWRITE(nServicesInt); | READWRITEAS(CService, obj); | ||||
nServices = static_cast<ServiceFlags>(nServicesInt); | |||||
READWRITEAS(CService, *this); | |||||
} | } | ||||
ServiceFlags nServices; | ServiceFlags nServices; | ||||
// disk and network only | // disk and network only | ||||
unsigned int nTime; | unsigned int nTime; | ||||
}; | }; | ||||
Show All 24 Lines | |||||
class CInv { | class CInv { | ||||
public: | public: | ||||
uint32_t type; | uint32_t type; | ||||
uint256 hash; | uint256 hash; | ||||
CInv() : type(0), hash() {} | CInv() : type(0), hash() {} | ||||
CInv(uint32_t typeIn, const uint256 &hashIn) : type(typeIn), hash(hashIn) {} | CInv(uint32_t typeIn, const uint256 &hashIn) : type(typeIn), hash(hashIn) {} | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); } | ||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(type); | |||||
READWRITE(hash); | |||||
} | |||||
friend bool operator<(const CInv &a, const CInv &b) { | friend bool operator<(const CInv &a, const CInv &b) { | ||||
return a.type < b.type || (a.type == b.type && a.hash < b.hash); | return a.type < b.type || (a.type == b.type && a.hash < b.hash); | ||||
} | } | ||||
std::string GetCommand() const; | std::string GetCommand() const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
Show All 15 Lines |