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.
7 # error This header can only be compiled as C++.
10 #ifndef __INCLUDED_PROTOCOL_H__
11 #define __INCLUDED_PROTOCOL_H__
13 #include "serialize.h"
20 inline unsigned short GetDefaultPort()
22 return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
26 extern unsigned char pchMessageStart[4];
38 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
40 std::string GetCommand() const;
45 READWRITE(FLATDATA(pchMessageStart));
46 READWRITE(FLATDATA(pchCommand));
47 READWRITE(nMessageSize);
51 // TODO: make private (improves encapsulation)
54 MESSAGE_START_SIZE=sizeof(::pchMessageStart),
56 MESSAGE_SIZE_SIZE=sizeof(int),
57 CHECKSUM_SIZE=sizeof(int),
59 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
60 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
62 char pchMessageStart[MESSAGE_START_SIZE];
63 char pchCommand[COMMAND_SIZE];
64 unsigned int nMessageSize;
65 unsigned int nChecksum;
68 /** nServices flags */
71 NODE_NETWORK = (1 << 0)
74 /** A CService with information about it as peer */
75 class CAddress : public CService
79 explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
83 CAddress* pthis = const_cast<CAddress*>(this);
84 CService* pip = (CService*)pthis;
89 if ((nType & SER_DISK) ||
90 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
96 // TODO: make private (improves encapsulation)
100 // disk and network only
107 /** inv message data */
112 CInv(int typeIn, const uint256& hashIn);
113 CInv(const std::string& strType, const uint256& hashIn);
121 friend bool operator<(const CInv& a, const CInv& b);
123 bool IsKnownType() const;
124 const char* GetCommand() const;
125 std::string ToString() const;
127 // TODO: make private (improves encapsulation)
133 #endif // __INCLUDED_PROTOCOL_H__