Changeset View
Changeset View
Standalone View
Standalone View
src/seeder/protocol.h
Show All 11 Lines | |||||
#include "netbase.h" | #include "netbase.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <string> | #include <string> | ||||
extern bool fTestNet; | |||||
static inline unsigned short GetDefaultPort(const bool testnet = fTestNet) { | |||||
return testnet ? 18333 : 8333; | |||||
} | |||||
// | |||||
// Message header | |||||
// (4) message start | |||||
// (12) command | |||||
// (4) size | |||||
// (4) checksum | |||||
extern uint8_t pchMessageStart[4]; | |||||
class CMessageHeader { | class CMessageHeader { | ||||
public: | public: | ||||
typedef uint8_t MessageMagic[4]; | |||||
CMessageHeader(); | CMessageHeader(); | ||||
CMessageHeader(const char *pszCommand, unsigned int nMessageSizeIn); | CMessageHeader(const char *pszCommand, unsigned int nMessageSizeIn); | ||||
std::string GetCommand() const; | std::string GetCommand() const; | ||||
bool IsValid() const; | bool IsValid() 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); | ||||
if (s.GetVersion() >= 209) { | if (s.GetVersion() >= 209) { | ||||
READWRITE(nChecksum); | READWRITE(nChecksum); | ||||
} | } | ||||
} | } | ||||
// TODO: make private (improves encapsulation) | // TODO: make private (improves encapsulation) | ||||
public: | public: | ||||
enum { COMMAND_SIZE = 12 }; | enum { COMMAND_SIZE = 12 }; | ||||
char pchMessageStart[sizeof(::pchMessageStart)]; | MessageMagic pchMessageStart; | ||||
char pchCommand[COMMAND_SIZE]; | char pchCommand[COMMAND_SIZE]; | ||||
unsigned int nMessageSize; | unsigned int nMessageSize; | ||||
unsigned int nChecksum; | unsigned int nChecksum; | ||||
}; | }; | ||||
enum ServiceFlags : uint64_t { | enum ServiceFlags : uint64_t { | ||||
NODE_NETWORK = (1 << 0), | NODE_NETWORK = (1 << 0), | ||||
NODE_BLOOM = (1 << 2), | NODE_BLOOM = (1 << 2), | ||||
NODE_XTHIN = (1 << 4), | NODE_XTHIN = (1 << 4), | ||||
NODE_BITCOIN_CASH = (1 << 5), | NODE_BITCOIN_CASH = (1 << 5), | ||||
}; | }; | ||||
class CAddress : public CSeederService { | |||||
public: | |||||
CAddress(); | |||||
CAddress(CSeederService ipIn, | |||||
uint64_t nServicesIn = NODE_NETWORK | NODE_BITCOIN_CASH); | |||||
void Init(); | |||||
ADD_SERIALIZE_METHODS; | |||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
int nVersion = s.GetVersion(); | |||||
CAddress *pthis = const_cast<CAddress *>(this); | |||||
CSeederService *pip = (CSeederService *)pthis; | |||||
if (ser_action.ForRead()) { | |||||
pthis->Init(); | |||||
} | |||||
if (s.GetType() & SER_DISK) { | |||||
READWRITE(nVersion); | |||||
} | |||||
if ((s.GetType() & SER_DISK) || | |||||
(nVersion >= 31402 && !(s.GetType() & SER_GETHASH))) { | |||||
READWRITE(nTime); | |||||
} | |||||
READWRITE(nServices); | |||||
READWRITE(*pip); | |||||
} | |||||
void print() const; | |||||
// TODO: make private (improves encapsulation) | |||||
public: | |||||
uint64_t nServices; | |||||
// disk and network only | |||||
unsigned int nTime; | |||||
}; | |||||
class CInv { | class CInv { | ||||
public: | public: | ||||
CInv(); | CInv(); | ||||
CInv(uint32_t typeIn, const uint256 &hashIn); | CInv(uint32_t typeIn, const uint256 &hashIn); | ||||
CInv(const std::string &strType, const uint256 &hashIn); | CInv(const std::string &strType, const uint256 &hashIn); | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
Show All 20 Lines |