Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
protocol.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef __cplusplus
7 # error This header can only be compiled as C++.
8 #endif
9 
10 #ifndef __INCLUDED_PROTOCOL_H__
11 #define __INCLUDED_PROTOCOL_H__
12 
13 #include "chainparams.h"
14 #include "netbase.h"
15 #include "serialize.h"
16 #include "uint256.h"
17 
18 #include <stdint.h>
19 #include <string>
20 
28 {
29  public:
31  CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
32 
33  std::string GetCommand() const;
34  bool IsValid() const;
35 
37  (
42  )
43 
44  // TODO: make private (improves encapsulation)
45  public:
46  enum {
47  COMMAND_SIZE=12,
48  MESSAGE_SIZE_SIZE=sizeof(int),
49  CHECKSUM_SIZE=sizeof(int),
50 
51  MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
52  CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE,
53  HEADER_SIZE=MESSAGE_START_SIZE+COMMAND_SIZE+MESSAGE_SIZE_SIZE+CHECKSUM_SIZE
54  };
56  char pchCommand[COMMAND_SIZE];
57  unsigned int nMessageSize;
58  unsigned int nChecksum;
59 };
60 
62 enum
63 {
64  NODE_NETWORK = (1 << 0),
65 };
66 
68 class CAddress : public CService
69 {
70  public:
71  CAddress();
72  explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
73 
74  void Init();
75 
77  (
78  CAddress* pthis = const_cast<CAddress*>(this);
79  CService* pip = (CService*)pthis;
80  if (fRead)
81  pthis->Init();
82  if (nType & SER_DISK)
83  READWRITE(nVersion);
84  if ((nType & SER_DISK) ||
85  (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
88  READWRITE(*pip);
89  )
90 
91  void print() const;
92 
93  // TODO: make private (improves encapsulation)
94  public:
95  uint64_t nServices;
96 
97  // disk and network only
98  unsigned int nTime;
99 
100  // memory only
101  int64_t nLastTry;
102 };
103 
105 class CInv
106 {
107  public:
108  CInv();
109  CInv(int typeIn, const uint256& hashIn);
110  CInv(const std::string& strType, const uint256& hashIn);
111 
113  (
114  READWRITE(type);
115  READWRITE(hash);
116  )
117 
118  friend bool operator<(const CInv& a, const CInv& b);
119 
120  bool IsKnownType() const;
121  const char* GetCommand() const;
122  std::string ToString() const;
123  void print() const;
124 
125  // TODO: make private (improves encapsulation)
126  public:
127  int type;
129 };
130 
131 enum
132 {
133  MSG_TX = 1,
135  // Nodes may always request a MSG_FILTERED_BLOCK in a getdata, however,
136  // MSG_FILTERED_BLOCK should not appear in any invs except as a part of getdata.
138 };
139 
140 #endif // __INCLUDED_PROTOCOL_H__
IMPLEMENT_SERIALIZE(CAddress *pthis=const_cast< CAddress * >(this);CService *pip=(CService *) pthis;if(fRead) pthis->Init();if(nType &SER_DISK) READWRITE(nVersion);if((nType &SER_DISK)||(nVersion >=CADDR_TIME_VERSION &&!(nType &SER_GETHASH))) READWRITE(nTime);READWRITE(nServices);READWRITE(*pip);) void print() const
uint64_t nServices
Definition: protocol.h:95
#define READWRITE(obj)
Definition: serialize.h:92
const char * GetCommand() const
Definition: protocol.cpp:135
void print() const
Definition: protocol.cpp:147
void Init()
Definition: protocol.cpp:90
const CInv & b
Definition: protocol.h:118
IMPLEMENT_SERIALIZE(READWRITE(type);READWRITE(hash);) friend bool operator<(const CInv &a
inv message data
Definition: protocol.h:105
void Init()
Definition: netbase.cpp:960
char pchCommand[COMMAND_SIZE]
Definition: protocol.h:56
bool IsKnownType() const
Definition: protocol.cpp:130
#define IMPLEMENT_SERIALIZE(statements)
Definition: serialize.h:54
#define FLATDATA(obj)
Definition: serialize.h:309
unsigned int nChecksum
Definition: protocol.h:58
#define MESSAGE_START_SIZE
Definition: chainparams.h:16
int type
Definition: protocol.h:127
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:94
int64_t nLastTry
Definition: protocol.h:101
A CService with information about it as peer.
Definition: protocol.h:68
uint256 hash
Definition: protocol.h:128
std::string GetCommand() const
Definition: protocol.cpp:39
IMPLEMENT_SERIALIZE(READWRITE(FLATDATA(pchMessageStart));READWRITE(FLATDATA(pchCommand));READWRITE(nMessageSize);READWRITE(nChecksum);) public char pchMessageStart[MESSAGE_START_SIZE]
Definition: protocol.h:37
void print() const
Definition: netbase.cpp:1116
256-bit unsigned integer
Definition: uint256.h:531
unsigned int nTime
Definition: protocol.h:98
CAddress()
Definition: protocol.cpp:79
unsigned int nMessageSize
Definition: protocol.h:57
static const int CADDR_TIME_VERSION
Definition: version.h:39
CInv()
Definition: protocol.cpp:97
std::string ToString() const
Definition: protocol.cpp:142
bool IsValid() const
Definition: protocol.cpp:47
Message header.
Definition: protocol.h:27