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 license.txt 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 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
22 return testnet ? 18333 : 8333;
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)
53 enum { COMMAND_SIZE=12 };
54 char pchMessageStart[sizeof(::pchMessageStart)];
55 char pchCommand[COMMAND_SIZE];
56 unsigned int nMessageSize;
57 unsigned int nChecksum;
60 /** nServices flags */
63 NODE_NETWORK = (1 << 0),
66 /** A CService with information about it as peer */
67 class CAddress : public CService
71 explicit CAddress(CService ipIn, uint64 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)))
92 // TODO: make private (improves encapsulation)
96 // disk and network only
103 /** inv message data */
108 CInv(int typeIn, const uint256& hashIn);
109 CInv(const std::string& strType, const uint256& hashIn);
117 friend bool operator<(const CInv& a, const CInv& b);
119 bool IsKnownType() const;
120 const char* GetCommand() const;
121 std::string ToString() const;
124 // TODO: make private (improves encapsulation)
130 #endif // __INCLUDED_PROTOCOL_H__