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 extern uint32_t nNetworkID;
22 inline uint16_t GetDefaultPort()
24 return static_cast<uint16_t>(fTestNet ? 17777 : 7777);
28 * (4) network identifier.
37 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
39 std::string GetCommand() const;
44 READWRITE(nNetworkID);
45 READWRITE(FLATDATA(pchCommand));
46 READWRITE(nMessageSize);
50 // TODO: make private (improves encapsulation)
58 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
59 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
62 char pchCommand[COMMAND_SIZE];
63 uint32_t nMessageSize;
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_t nServicesIn=NODE_NETWORK);
82 CAddress* pthis = const_cast<CAddress*>(this);
83 CService* pip = (CService*)pthis;
88 if ((nType & SER_DISK) ||
89 (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
95 // TODO: make private (improves encapsulation)
99 // disk and network only
106 /** inv message data */
111 CInv(int typeIn, const uint256& hashIn);
112 CInv(const std::string& strType, const uint256& hashIn);
120 friend bool operator<(const CInv& a, const CInv& b);
122 bool IsKnownType() const;
123 const char* GetCommand() const;
124 std::string ToString() const;
126 // TODO: make private (improves encapsulation)
132 #endif // __INCLUDED_PROTOCOL_H__