X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fprotocol.h;h=352a2472111f99e1ba591d11a82015950e6ca67d;hb=e6bfe9cb90f52486b97b80bd0528626042ea1582;hp=b70dd71b82d91635a28c27d29ce9a4b2fdacfb41;hpb=18c0fa97d0408a3ee8e4cb39c08156f7667f99ac;p=novacoin.git diff --git a/src/protocol.h b/src/protocol.h index b70dd71..352a247 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,36 +1,30 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. - -#ifndef __cplusplus -# error This header can only be compiled as C++. -#endif +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef __INCLUDED_PROTOCOL_H__ #define __INCLUDED_PROTOCOL_H__ #include "serialize.h" #include "netbase.h" -#include "util.h" #include +#include +#include #include "uint256.h" +extern uint32_t nNetworkID; extern bool fTestNet; -static inline unsigned short GetDefaultPort(const bool testnet = fTestNet) +inline uint16_t GetDefaultPort() { - return testnet ? 18333 : 8333; + return static_cast(fTestNet ? 17777 : 7777); } -// -// Message header -// (4) message start -// (12) command -// (4) size -// (4) checksum - -extern unsigned char pchMessageStart[4]; - +// Message header. +// (4) network identifier. +// (12) command. +// (4) size. +// (4) checksum. class CMessageHeader { public: @@ -42,7 +36,7 @@ class CMessageHeader IMPLEMENT_SERIALIZE ( - READWRITE(FLATDATA(pchMessageStart)); + READWRITE(nNetworkID); READWRITE(FLATDATA(pchCommand)); READWRITE(nMessageSize); READWRITE(nChecksum); @@ -50,25 +44,33 @@ class CMessageHeader // TODO: make private (improves encapsulation) public: - enum { COMMAND_SIZE=12 }; - char pchMessageStart[sizeof(::pchMessageStart)]; + 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 */ 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 ( @@ -77,26 +79,26 @@ class CAddress : public CService if (fRead) pthis->Init(); if (nType & SER_DISK) - READWRITE(nVersion); - if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH))) - READWRITE(nTime); + READWRITE(nVersion); + if ((nType & SER_DISK) || + (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH))) + READWRITE(nTime); READWRITE(nServices); 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 - unsigned int nLastTry; + int64_t nLastTry; }; +/** inv message data */ class CInv { public: @@ -115,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__