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"
17 #define PPCOIN_PORT 9901
19 #define TESTNET_PORT 9903
23 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
25 return testnet ? TESTNET_PORT : PPCOIN_PORT;
35 extern unsigned char pchMessageStart[4];
41 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
43 std::string GetCommand() const;
48 READWRITE(FLATDATA(pchMessageStart));
49 READWRITE(FLATDATA(pchCommand));
50 READWRITE(nMessageSize);
55 // TODO: make private (improves encapsulation)
57 enum { COMMAND_SIZE=12 };
58 char pchMessageStart[sizeof(::pchMessageStart)];
59 char pchCommand[COMMAND_SIZE];
60 unsigned int nMessageSize;
61 unsigned int nChecksum;
66 NODE_NETWORK = (1 << 0),
73 CAddress(unsigned int ipIn, unsigned short portIn=0, uint64 nServicesIn=NODE_NETWORK);
74 explicit CAddress(const struct sockaddr_in& sockaddr, uint64 nServicesIn=NODE_NETWORK);
75 explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
76 explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
77 explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
78 explicit CAddress(std::string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
85 const_cast<CAddress*>(this)->Init();
88 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
91 READWRITE(FLATDATA(pchReserved)); // for IPv6
96 friend bool operator==(const CAddress& a, const CAddress& b);
97 friend bool operator!=(const CAddress& a, const CAddress& b);
98 friend bool operator<(const CAddress& a, const CAddress& b);
100 std::vector<unsigned char> GetKey() const;
101 struct sockaddr_in GetSockAddr() const;
103 bool IsRFC1918() const;
104 bool IsRFC3927() const;
105 bool IsLocal() const;
106 bool IsRoutable() const;
107 bool IsValid() const;
108 unsigned char GetByte(int n) const;
109 std::string ToStringIPPort() const;
110 std::string ToStringIP() const;
111 std::string ToStringPort() const;
112 std::string ToString() const;
115 // TODO: make private (improves encapsulation)
118 unsigned char pchReserved[12];
122 // disk and network only
126 unsigned int nLastTry;
133 CInv(int typeIn, const uint256& hashIn);
134 CInv(const std::string& strType, const uint256& hashIn);
142 friend bool operator<(const CInv& a, const CInv& b);
144 bool IsKnownType() const;
145 const char* GetCommand() const;
146 std::string ToString() const;
149 // TODO: make private (improves encapsulation)
155 #endif // __INCLUDED_PROTOCOL_H__