1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef __INCLUDED_PROTOCOL_H__
7 #define __INCLUDED_PROTOCOL_H__
16 extern uint32_t nNetworkID;
18 inline uint16_t GetDefaultPort()
20 return static_cast<uint16_t>(fTestNet ? 17777 : 7777);
24 // (4) network identifier.
32 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
34 std::string GetCommand() const;
39 READWRITE(nNetworkID);
40 READWRITE(FLATDATA(pchCommand));
41 READWRITE(nMessageSize);
45 // TODO: make private (improves encapsulation)
53 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
54 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
57 char pchCommand[COMMAND_SIZE];
58 uint32_t nMessageSize;
62 /** nServices flags */
65 NODE_NETWORK = (1 << 0)
68 /** A CService with information about it as peer */
69 class CAddress : public CService
73 explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
77 CAddress* pthis = const_cast<CAddress*>(this);
78 CService* pip = (CService*)pthis;
83 if ((nType & SER_DISK) ||
84 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
90 // TODO: make private (improves encapsulation)
94 // disk and network only
101 /** inv message data */
106 CInv(int typeIn, const uint256& hashIn);
107 CInv(const std::string& strType, const uint256& hashIn);
115 friend bool operator<(const CInv& a, const CInv& b);
117 bool IsKnownType() const;
118 const char* GetCommand() const;
119 std::string ToString() const;
121 int GetType() const { return type; }
122 uint256 GetHash() const { return hash; }
124 // TODO: make private (improves encapsulation)
130 #endif // __INCLUDED_PROTOCOL_H__