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"
19 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
21 return testnet ? 18333 : 8333;
25 extern unsigned char pchMessageStart[4];
37 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
39 std::string GetCommand() const;
44 READWRITE(FLATDATA(pchMessageStart));
45 READWRITE(FLATDATA(pchCommand));
46 READWRITE(nMessageSize);
50 // TODO: make private (improves encapsulation)
53 MESSAGE_START_SIZE=sizeof(::pchMessageStart),
55 MESSAGE_SIZE_SIZE=sizeof(int),
56 CHECKSUM_SIZE=sizeof(int),
58 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
59 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
61 char pchMessageStart[MESSAGE_START_SIZE];
62 char pchCommand[COMMAND_SIZE];
63 unsigned int nMessageSize;
64 unsigned int nChecksum;
67 /** nServices flags */
70 NODE_NETWORK = (1 << 0),
73 /** A CService with information about it as peer */
74 class CAddress : public CService
78 explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
84 CAddress* pthis = const_cast<CAddress*>(this);
85 CService* pip = (CService*)pthis;
90 if ((nType & SER_DISK) ||
91 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
99 // TODO: make private (improves encapsulation)
103 // disk and network only
110 /** inv message data */
115 CInv(int typeIn, const uint256& hashIn);
116 CInv(const std::string& strType, const uint256& hashIn);
124 friend bool operator<(const CInv& a, const CInv& b);
126 bool IsKnownType() const;
127 const char* GetCommand() const;
128 std::string ToString() const;
131 // TODO: make private (improves encapsulation)
137 #endif // __INCLUDED_PROTOCOL_H__