X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fprotocol.h;h=352a2472111f99e1ba591d11a82015950e6ca67d;hb=e6bfe9cb90f52486b97b80bd0528626042ea1582;hp=ed2ca59b30d8dd32e44f860f9db1571aeda40798;hpb=83e34b29071b58d6578b197430d12c55d277a515;p=novacoin.git diff --git a/src/protocol.h b/src/protocol.h index ed2ca59..352a247 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -3,38 +3,28 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __cplusplus -# error This header can only be compiled as C++. -#endif - #ifndef __INCLUDED_PROTOCOL_H__ #define __INCLUDED_PROTOCOL_H__ #include "serialize.h" #include "netbase.h" #include +#include +#include #include "uint256.h" -#define PPCOIN_PORT 7777 -#define RPC_PORT 8344 -#define TESTNET_PORT 17777 - +extern uint32_t nNetworkID; extern bool fTestNet; - -void GetMessageStart(unsigned char pchMessageStart[], bool fPersistent = false); - -static inline unsigned short GetDefaultPort(const bool testnet = fTestNet) +inline uint16_t GetDefaultPort() { - return testnet ? TESTNET_PORT : PPCOIN_PORT; + return static_cast(fTestNet ? 17777 : 7777); } - -/** Message header. - * (4) message start. - * (12) command. - * (4) size. - * (4) checksum. - */ +// Message header. +// (4) network identifier. +// (12) command. +// (4) size. +// (4) checksum. class CMessageHeader { public: @@ -46,7 +36,7 @@ class CMessageHeader IMPLEMENT_SERIALIZE ( - READWRITE(FLATDATA(pchMessageStart)); + READWRITE(nNetworkID); READWRITE(FLATDATA(pchCommand)); READWRITE(nMessageSize); READWRITE(nChecksum); @@ -54,17 +44,25 @@ class CMessageHeader // TODO: make private (improves encapsulation) public: - enum { COMMAND_SIZE=12 }; - unsigned char pchMessageStart[4]; + enum { + MESSAGE_START_SIZE=4, + COMMAND_SIZE=12, + MESSAGE_SIZE_SIZE=4, + CHECKSUM_SIZE=4, + + MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE, + CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE + }; + uint32_t nNetworkID; char pchCommand[COMMAND_SIZE]; - unsigned int nMessageSize; - unsigned int nChecksum; + uint32_t nMessageSize; + uint32_t nChecksum; }; /** nServices flags */ enum { - NODE_NETWORK = (1 << 0), + NODE_NETWORK = (1 << 0) }; /** A CService with information about it as peer */ @@ -72,9 +70,7 @@ class CAddress : public CService { public: CAddress(); - explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK); - - void Init(); + explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK); IMPLEMENT_SERIALIZE ( @@ -91,17 +87,15 @@ class CAddress : public CService READWRITE(*pip); ) - void print() const; - // TODO: make private (improves encapsulation) public: - uint64 nServices; + uint64_t nServices; // disk and network only unsigned int nTime; // memory only - int64 nLastTry; + int64_t nLastTry; }; /** inv message data */ @@ -123,12 +117,14 @@ class CInv bool IsKnownType() const; const char* GetCommand() const; std::string ToString() const; - void print() const; + + int GetType() const { return type; } + uint256 GetHash() const { return hash; } // TODO: make private (improves encapsulation) - public: - int type; - uint256 hash; + private: + int type = 0; + uint256 hash = 0; }; #endif // __INCLUDED_PROTOCOL_H__