1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2011 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__
15 #include "serialize.h"
20 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
22 return testnet ? 18333 : 8333;
32 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);
52 // TODO: make private (improves encapsulation)
54 enum { COMMAND_SIZE=12 };
55 char pchMessageStart[sizeof(::pchMessageStart)];
56 char pchCommand[COMMAND_SIZE];
57 unsigned int nMessageSize;
58 unsigned int nChecksum;
63 NODE_NETWORK = (1 << 0),
70 CAddress(unsigned int ipIn, unsigned short portIn=0, uint64_t nServicesIn=NODE_NETWORK);
71 explicit CAddress(const struct sockaddr_in& sockaddr, uint64_t nServicesIn=NODE_NETWORK);
72 explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64_t nServicesIn=NODE_NETWORK);
73 explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64_t nServicesIn=NODE_NETWORK);
74 explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64_t nServicesIn=NODE_NETWORK);
75 explicit CAddress(std::string strIn, bool fNameLookup = false, uint64_t nServicesIn=NODE_NETWORK);
82 const_cast<CAddress*>(this)->Init();
85 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
88 READWRITE(FLATDATA(pchReserved)); // for IPv6
93 friend bool operator==(const CAddress& a, const CAddress& b);
94 friend bool operator!=(const CAddress& a, const CAddress& b);
95 friend bool operator<(const CAddress& a, const CAddress& b);
97 std::vector<unsigned char> GetKey() const;
98 struct sockaddr_in GetSockAddr() const;
100 bool IsRFC1918() const;
101 bool IsRFC3927() const;
102 bool IsLocal() const;
103 bool IsRoutable() const;
104 bool IsValid() const;
105 unsigned char GetByte(int n) const;
106 std::string ToStringIPPort() const;
107 std::string ToStringIP() const;
108 std::string ToStringPort() const;
109 std::string ToString() const;
112 // TODO: make private (improves encapsulation)
115 unsigned char pchReserved[12];
119 // disk and network only
123 unsigned int nLastTry;
130 CInv(int typeIn, const uint256& hashIn);
131 CInv(const std::string& strType, const uint256& hashIn);
139 friend bool operator<(const CInv& a, const CInv& b);
141 bool IsKnownType() const;
142 const char* GetCommand() const;
143 std::string ToString() const;
146 // TODO: make private (improves encapsulation)
152 #endif // __INCLUDED_PROTOCOL_H__