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.
6 #ifndef __INCLUDED_PROTOCOL_H__
7 #define __INCLUDED_PROTOCOL_H__
15 inline unsigned short GetDefaultPort()
17 return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
21 extern unsigned char pchMessageStart[4];
33 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
35 std::string GetCommand() const;
40 READWRITE(FLATDATA(pchMessageStart));
41 READWRITE(FLATDATA(pchCommand));
42 READWRITE(nMessageSize);
46 // TODO: make private (improves encapsulation)
49 MESSAGE_START_SIZE=sizeof(::pchMessageStart),
51 MESSAGE_SIZE_SIZE=sizeof(int),
52 CHECKSUM_SIZE=sizeof(int),
54 MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
55 CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
57 char pchMessageStart[MESSAGE_START_SIZE];
58 char pchCommand[COMMAND_SIZE];
59 unsigned int nMessageSize;
60 unsigned int nChecksum;
63 /** nServices flags */
66 NODE_NETWORK = (1 << 0)
69 /** A CService with information about it as peer */
70 class CAddress : public CService
74 explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
78 CAddress* pthis = const_cast<CAddress*>(this);
79 CService* pip = (CService*)pthis;
84 if ((nType & SER_DISK) ||
85 (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;
122 // TODO: make private (improves encapsulation)
128 #endif // __INCLUDED_PROTOCOL_H__