Changeset View
Changeset View
Standalone View
Standalone View
src/protocol.h
Show First 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* A CService with information about it as peer. | * A CService with information about it as peer. | ||||
*/ | */ | ||||
class CAddress : public CService { | class CAddress : public CService { | ||||
static constexpr uint32_t TIME_INIT{100000000}; | static constexpr uint32_t TIME_INIT{100000000}; | ||||
public: | public: | ||||
CAddress() : CService{} {}; | CAddress() : CService{} {}; | ||||
explicit CAddress(CService ipIn, ServiceFlags nServicesIn) | CAddress(CService ipIn, ServiceFlags nServicesIn) | ||||
: CService{ipIn}, nServices{nServicesIn} {}; | : CService{ipIn}, nServices{nServicesIn} {}; | ||||
CAddress(CService ipIn, ServiceFlags nServicesIn, uint32_t nTimeIn) | |||||
: CService{ipIn}, nTime{nTimeIn}, nServices{nServicesIn} {}; | |||||
void Init(); | void Init(); | ||||
SERIALIZE_METHODS(CAddress, obj) { | SERIALIZE_METHODS(CAddress, obj) { | ||||
SER_READ(obj, obj.nTime = TIME_INIT); | SER_READ(obj, obj.nTime = TIME_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(obj.nTime); | READWRITE(obj.nTime); | ||||
} | } | ||||
if (nVersion & ADDRV2_FORMAT) { | |||||
uint64_t services_tmp; | |||||
SER_WRITE(obj, services_tmp = obj.nServices); | |||||
READWRITE(Using<CompactSizeFormatter<false>>(services_tmp)); | |||||
SER_READ(obj, | |||||
obj.nServices = static_cast<ServiceFlags>(services_tmp)); | |||||
} else { | |||||
READWRITE(Using<CustomUintFormatter<8>>(obj.nServices)); | READWRITE(Using<CustomUintFormatter<8>>(obj.nServices)); | ||||
} | |||||
READWRITEAS(CService, obj); | READWRITEAS(CService, obj); | ||||
} | } | ||||
ServiceFlags nServices{NODE_NONE}; | |||||
// disk and network only | // disk and network only | ||||
uint32_t nTime{TIME_INIT}; | uint32_t nTime{TIME_INIT}; | ||||
ServiceFlags nServices{NODE_NONE}; | |||||
}; | }; | ||||
/** getdata message type flags */ | /** getdata message type flags */ | ||||
const uint32_t MSG_TYPE_MASK = 0xffffffff >> 3; | const uint32_t MSG_TYPE_MASK = 0xffffffff >> 3; | ||||
/** | /** | ||||
* getdata / inv message types. | * getdata / inv message types. | ||||
* These numbers are defined by the protocol. When adding a new value, be sure | * These numbers are defined by the protocol. When adding a new value, be sure | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |