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"
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)
52 enum { COMMAND_SIZE=12 };
53 char pchMessageStart[sizeof(::pchMessageStart)];
54 char pchCommand[COMMAND_SIZE];
55 unsigned int nMessageSize;
56 unsigned int nChecksum;
59 /** nServices flags */
62 NODE_NETWORK = (1 << 0),
65 /** A CService with information about it as peer */
66 class CAddress : public CService
70 explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
76 CAddress* pthis = const_cast<CAddress*>(this);
77 CService* pip = (CService*)pthis;
82 if ((nType & SER_DISK) ||
83 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
91 // TODO: make private (improves encapsulation)
95 // disk and network only
102 /** inv message data */
107 CInv(int typeIn, const uint256& hashIn);
108 CInv(const std::string& strType, const uint256& hashIn);
116 friend bool operator<(const CInv& a, const CInv& b);
118 bool IsKnownType() const;
119 const char* GetCommand() const;
120 std::string ToString() const;
123 // TODO: make private (improves encapsulation)
129 #endif // __INCLUDED_PROTOCOL_H__