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__
13 #include "serialize.h"
18 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
20 return testnet ? 18333 : 8333;
30 extern unsigned char pchMessageStart[4];
36 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
38 std::string GetCommand() const;
43 READWRITE(FLATDATA(pchMessageStart));
44 READWRITE(FLATDATA(pchCommand));
45 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;
61 NODE_NETWORK = (1 << 0),
68 CAddress(unsigned int ipIn, unsigned short portIn=0, uint64 nServicesIn=NODE_NETWORK);
69 explicit CAddress(const struct sockaddr_in& sockaddr, uint64 nServicesIn=NODE_NETWORK);
70 explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
71 explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
72 explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
73 explicit CAddress(std::string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
80 const_cast<CAddress*>(this)->Init();
83 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
86 READWRITE(FLATDATA(pchReserved)); // for IPv6
91 friend bool operator==(const CAddress& a, const CAddress& b);
92 friend bool operator!=(const CAddress& a, const CAddress& b);
93 friend bool operator<(const CAddress& a, const CAddress& b);
95 std::vector<unsigned char> GetKey() const;
96 struct sockaddr_in GetSockAddr() const;
98 bool IsRFC1918() const;
99 bool IsRFC3927() const;
100 bool IsLocal() const;
101 bool IsRoutable() const;
102 bool IsValid() const;
103 unsigned char GetByte(int n) const;
104 std::string ToStringIPPort() const;
105 std::string ToStringIP() const;
106 std::string ToStringPort() const;
107 std::string ToString() const;
110 // TODO: make private (improves encapsulation)
113 unsigned char pchReserved[12];
117 // disk and network only
121 unsigned int nLastTry;
128 CInv(int typeIn, const uint256& hashIn);
129 CInv(const std::string& strType, const uint256& hashIn);
137 friend bool operator<(const CInv& a, const CInv& b);
139 bool IsKnownType() const;
140 const char* GetCommand() const;
141 std::string ToString() const;
144 // TODO: make private (improves encapsulation)
150 #endif // __INCLUDED_PROTOCOL_H__