-
+ C4317F321DC7BD4073E53063DA77FC75DF4D994406456B3E52179A9ABBAEE6ED9731D37442E71F381692FD07CFF5E68A80C7473E6E8A29536944EEBDDB6813E2
bitcoin/src/protocol.h
(0 . 0)(1 . 181)
18879 // /****************************\
18880 // * EXPERIMENTAL BRANCH. *
18881 // * FOR LABORATORY USE ONLY. *
18882 // ********************************
18883 // ************
18884 // **************
18885 // ****************
18886 // **** **** ****
18887 // *** *** ***
18888 // *** *** ***
18889 // *** * * **
18890 // ******** ********
18891 // ******* ******
18892 // *** **
18893 // * ******* **
18894 // ** * * * * *
18895 // ** * * ***
18896 // **** * * * * ****
18897 // **** *** * * ** ***
18898 // **** ********* ******
18899 // ******* ***** *******
18900 // ********* ****** **
18901 // ** ****** ******
18902 // ** ******* **
18903 // ** ******* ***
18904 // **** ******** ************
18905 // ************ ************
18906 // ******** *******
18907 // ****** ****
18908 // *** ***
18909 // ********************************
18910 // Copyright (c) 2009-2010 Satoshi Nakamoto
18911 // Copyright (c) 2011 The Bitcoin developers
18912 // Distributed under the MIT/X11 software license, see the accompanying
18913 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
18914
18915 #ifndef __cplusplus
18916 # error This header can only be compiled as C++.
18917 #endif
18918
18919 #ifndef __INCLUDED_PROTOCOL_H__
18920 #define __INCLUDED_PROTOCOL_H__
18921
18922 #include "serialize.h"
18923 #include <string>
18924 #include "uint256.h"
18925
18926 extern bool fTestNet;
18927 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
18928 {
18929 return testnet ? 18333 : 8333;
18930 }
18931
18932 //
18933 // Message header
18934 // (4) message start
18935 // (12) command
18936 // (4) size
18937 // (4) checksum
18938
18939 extern unsigned char pchMessageStart[4];
18940
18941 class CMessageHeader
18942 {
18943 public:
18944 CMessageHeader();
18945 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
18946
18947 std::string GetCommand() const;
18948 bool IsValid() const;
18949
18950 IMPLEMENT_SERIALIZE
18951 (
18952 READWRITE(FLATDATA(pchMessageStart));
18953 READWRITE(FLATDATA(pchCommand));
18954 READWRITE(nMessageSize);
18955 if (nVersion >= 209)
18956 READWRITE(nChecksum);
18957 )
18958
18959 // TODO: make private (improves encapsulation)
18960 public:
18961 enum { COMMAND_SIZE=12 };
18962 char pchMessageStart[sizeof(::pchMessageStart)];
18963 char pchCommand[COMMAND_SIZE];
18964 unsigned int nMessageSize;
18965 unsigned int nChecksum;
18966 };
18967
18968 enum
18969 {
18970 NODE_NETWORK = (1 << 0),
18971 };
18972
18973 class CAddress
18974 {
18975 public:
18976 CAddress();
18977 CAddress(unsigned int ipIn, unsigned short portIn=0, uint64 nServicesIn=NODE_NETWORK);
18978 explicit CAddress(const struct sockaddr_in& sockaddr, uint64 nServicesIn=NODE_NETWORK);
18979 explicit CAddress(const char* pszIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
18980 explicit CAddress(const char* pszIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
18981 explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
18982 explicit CAddress(std::string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK);
18983
18984 void Init();
18985
18986 IMPLEMENT_SERIALIZE
18987 (
18988 if (fRead)
18989 const_cast<CAddress*>(this)->Init();
18990 if (nType & SER_DISK)
18991 READWRITE(nVersion);
18992 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
18993 READWRITE(nTime);
18994 READWRITE(nServices);
18995 READWRITE(FLATDATA(pchReserved)); // for IPv6
18996 READWRITE(ip);
18997 READWRITE(port);
18998 )
18999
19000 friend bool operator==(const CAddress& a, const CAddress& b);
19001 friend bool operator!=(const CAddress& a, const CAddress& b);
19002 friend bool operator<(const CAddress& a, const CAddress& b);
19003
19004 std::vector<unsigned char> GetKey() const;
19005 struct sockaddr_in GetSockAddr() const;
19006 bool IsIPv4() const;
19007 bool IsRFC1918() const;
19008 bool IsRFC3927() const;
19009 bool IsLocal() const;
19010 bool IsRoutable() const;
19011 bool IsValid() const;
19012 unsigned char GetByte(int n) const;
19013 std::string ToStringIPPort() const;
19014 std::string ToStringIP() const;
19015 std::string ToStringPort() const;
19016 std::string ToString() const;
19017 void print() const;
19018
19019 // TODO: make private (improves encapsulation)
19020 public:
19021 uint64 nServices;
19022 unsigned char pchReserved[12];
19023 unsigned int ip;
19024 unsigned short port;
19025
19026 // disk and network only
19027 unsigned int nTime;
19028
19029 // memory only
19030 unsigned int nLastTry;
19031 };
19032
19033 class CInv
19034 {
19035 public:
19036 CInv();
19037 CInv(int typeIn, const uint256& hashIn);
19038 CInv(const std::string& strType, const uint256& hashIn);
19039
19040 IMPLEMENT_SERIALIZE
19041 (
19042 READWRITE(type);
19043 READWRITE(hash);
19044 )
19045
19046 friend bool operator<(const CInv& a, const CInv& b);
19047
19048 bool IsKnownType() const;
19049 const char* GetCommand() const;
19050 std::string ToString() const;
19051 void print() const;
19052
19053 // TODO: make private (improves encapsulation)
19054 public:
19055 int type;
19056 uint256 hash;
19057 };
19058
19059 #endif // __INCLUDED_PROTOCOL_H__