raw
experimental-genesis    1 //  /****************************\
experimental-genesis 2 // * EXPERIMENTAL BRANCH. *
experimental-genesis 3 // * FOR LABORATORY USE ONLY. *
experimental-genesis 4 // ********************************
experimental-genesis 5 // ************
experimental-genesis 6 // **************
experimental-genesis 7 // ****************
experimental-genesis 8 // **** **** ****
experimental-genesis 9 // *** *** ***
experimental-genesis 10 // *** *** ***
experimental-genesis 11 // *** * * **
experimental-genesis 12 // ******** ********
experimental-genesis 13 // ******* ******
experimental-genesis 14 // *** **
experimental-genesis 15 // * ******* **
experimental-genesis 16 // ** * * * * *
experimental-genesis 17 // ** * * ***
experimental-genesis 18 // **** * * * * ****
experimental-genesis 19 // **** *** * * ** ***
experimental-genesis 20 // **** ********* ******
experimental-genesis 21 // ******* ***** *******
experimental-genesis 22 // ********* ****** **
experimental-genesis 23 // ** ****** ******
experimental-genesis 24 // ** ******* **
experimental-genesis 25 // ** ******* ***
experimental-genesis 26 // **** ******** ************
experimental-genesis 27 // ************ ************
experimental-genesis 28 // ******** *******
experimental-genesis 29 // ****** ****
experimental-genesis 30 // *** ***
experimental-genesis 31 // ********************************
experimental-genesis 32 // Copyright (c) 2009-2010 Satoshi Nakamoto
experimental-genesis 33 // Copyright (c) 2011 The Bitcoin developers
experimental-genesis 34 // Distributed under the MIT/X11 software license, see the accompanying
experimental-genesis 35 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
experimental-genesis 36
experimental-genesis 37 #ifndef __cplusplus
experimental-genesis 38 # error This header can only be compiled as C++.
experimental-genesis 39 #endif
experimental-genesis 40
experimental-genesis 41 #ifndef __INCLUDED_PROTOCOL_H__
experimental-genesis 42 #define __INCLUDED_PROTOCOL_H__
experimental-genesis 43
experimental-genesis 44 #include "serialize.h"
experimental-genesis 45 #include <string>
experimental-genesis 46 #include "uint256.h"
experimental-genesis 47
experimental-genesis 48 extern bool fTestNet;
experimental-genesis 49 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
experimental-genesis 50 {
experimental-genesis 51 return testnet ? 18333 : 8333;
experimental-genesis 52 }
experimental-genesis 53
experimental-genesis 54 //
experimental-genesis 55 // Message header
experimental-genesis 56 // (4) message start
experimental-genesis 57 // (12) command
experimental-genesis 58 // (4) size
experimental-genesis 59 // (4) checksum
experimental-genesis 60
experimental-genesis 61 extern unsigned char pchMessageStart[4];
experimental-genesis 62
experimental-genesis 63 class CMessageHeader
experimental-genesis 64 {
experimental-genesis 65 public:
experimental-genesis 66 CMessageHeader();
experimental-genesis 67 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
experimental-genesis 68
experimental-genesis 69 std::string GetCommand() const;
experimental-genesis 70 bool IsValid() const;
experimental-genesis 71
experimental-genesis 72 IMPLEMENT_SERIALIZE
experimental-genesis 73 (
experimental-genesis 74 READWRITE(FLATDATA(pchMessageStart));
experimental-genesis 75 READWRITE(FLATDATA(pchCommand));
experimental-genesis 76 READWRITE(nMessageSize);
experimental-genesis 77 if (nVersion >= 209)
experimental-genesis 78 READWRITE(nChecksum);
experimental-genesis 79 )
experimental-genesis 80
experimental-genesis 81 // TODO: make private (improves encapsulation)
experimental-genesis 82 public:
experimental-genesis 83 enum { COMMAND_SIZE=12 };
experimental-genesis 84 char pchMessageStart[sizeof(::pchMessageStart)];
experimental-genesis 85 char pchCommand[COMMAND_SIZE];
experimental-genesis 86 unsigned int nMessageSize;
experimental-genesis 87 unsigned int nChecksum;
experimental-genesis 88 };
experimental-genesis 89
experimental-genesis 90 enum
experimental-genesis 91 {
experimental-genesis 92 NODE_NETWORK = (1 << 0),
experimental-genesis 93 };
experimental-genesis 94
experimental-genesis 95 class CAddress
experimental-genesis 96 {
experimental-genesis 97 public:
experimental-genesis 98 CAddress();
experimental-genesis 99 CAddress(unsigned int ipIn, unsigned short portIn=0, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 100 explicit CAddress(const struct sockaddr_in& sockaddr, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 101 explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 102 explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 103 explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 104 explicit CAddress(std::string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
experimental-genesis 105
experimental-genesis 106 void Init();
experimental-genesis 107
experimental-genesis 108 IMPLEMENT_SERIALIZE
experimental-genesis 109 (
experimental-genesis 110 if (fRead)
experimental-genesis 111 const_cast<CAddress*>(this)->Init();
experimental-genesis 112 if (nType & SER_DISK)
experimental-genesis 113 READWRITE(nVersion);
experimental-genesis 114 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
experimental-genesis 115 READWRITE(nTime);
experimental-genesis 116 READWRITE(nServices);
experimental-genesis 117 READWRITE(FLATDATA(pchReserved)); // for IPv6
experimental-genesis 118 READWRITE(ip);
experimental-genesis 119 READWRITE(port);
experimental-genesis 120 )
experimental-genesis 121
experimental-genesis 122 friend bool operator==(const CAddress& a, const CAddress& b);
experimental-genesis 123 friend bool operator!=(const CAddress& a, const CAddress& b);
experimental-genesis 124 friend bool operator<(const CAddress& a, const CAddress& b);
experimental-genesis 125
experimental-genesis 126 std::vector<unsigned char> GetKey() const;
experimental-genesis 127 struct sockaddr_in GetSockAddr() const;
experimental-genesis 128 bool IsIPv4() const;
experimental-genesis 129 bool IsRFC1918() const;
experimental-genesis 130 bool IsRFC3927() const;
experimental-genesis 131 bool IsLocal() const;
experimental-genesis 132 bool IsRoutable() const;
experimental-genesis 133 bool IsValid() const;
experimental-genesis 134 unsigned char GetByte(int n) const;
experimental-genesis 135 std::string ToStringIPPort() const;
experimental-genesis 136 std::string ToStringIP() const;
experimental-genesis 137 std::string ToStringPort() const;
experimental-genesis 138 std::string ToString() const;
experimental-genesis 139 void print() const;
experimental-genesis 140
experimental-genesis 141 // TODO: make private (improves encapsulation)
experimental-genesis 142 public:
experimental-genesis 143 uint64 nServices;
experimental-genesis 144 unsigned char pchReserved[12];
experimental-genesis 145 unsigned int ip;
experimental-genesis 146 unsigned short port;
experimental-genesis 147
experimental-genesis 148 // disk and network only
experimental-genesis 149 unsigned int nTime;
experimental-genesis 150
experimental-genesis 151 // memory only
experimental-genesis 152 unsigned int nLastTry;
experimental-genesis 153 };
experimental-genesis 154
experimental-genesis 155 class CInv
experimental-genesis 156 {
experimental-genesis 157 public:
experimental-genesis 158 CInv();
experimental-genesis 159 CInv(int typeIn, const uint256& hashIn);
experimental-genesis 160 CInv(const std::string& strType, const uint256& hashIn);
experimental-genesis 161
experimental-genesis 162 IMPLEMENT_SERIALIZE
experimental-genesis 163 (
experimental-genesis 164 READWRITE(type);
experimental-genesis 165 READWRITE(hash);
experimental-genesis 166 )
experimental-genesis 167
experimental-genesis 168 friend bool operator<(const CInv& a, const CInv& b);
experimental-genesis 169
experimental-genesis 170 bool IsKnownType() const;
experimental-genesis 171 const char* GetCommand() const;
experimental-genesis 172 std::string ToString() const;
experimental-genesis 173 void print() const;
experimental-genesis 174
experimental-genesis 175 // TODO: make private (improves encapsulation)
experimental-genesis 176 public:
experimental-genesis 177 int type;
experimental-genesis 178 uint256 hash;
experimental-genesis 179 };
experimental-genesis 180
experimental-genesis 181 #endif // __INCLUDED_PROTOCOL_H__