]>
Commit | Line | Data |
---|---|---|
507fd9d1 | 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto |
db0e8ccd | 2 | // Copyright (c) 2009-2013 The Bitcoin developers |
507fd9d1 | 3 | // Distributed under the MIT/X11 software license, see the accompanying |
3a25a2b9 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
507fd9d1 GS |
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 | ||
0e4b3175 | 13 | #include "chainparams.h" |
67a42f92 | 14 | #include "netbase.h" |
51ed9ec9 | 15 | #include "serialize.h" |
e4dde849 | 16 | #include "uint256.h" |
507fd9d1 | 17 | |
51ed9ec9 BD |
18 | #include <stdint.h> |
19 | #include <string> | |
20 | ||
6b8de05d PW |
21 | /** Message header. |
22 | * (4) message start. | |
23 | * (12) command. | |
24 | * (4) size. | |
25 | * (4) checksum. | |
26 | */ | |
507fd9d1 GS |
27 | class CMessageHeader |
28 | { | |
29 | public: | |
30 | CMessageHeader(); | |
31 | CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn); | |
32 | ||
33 | std::string GetCommand() const; | |
34 | bool IsValid() const; | |
35 | ||
36 | IMPLEMENT_SERIALIZE | |
37 | ( | |
38 | READWRITE(FLATDATA(pchMessageStart)); | |
39 | READWRITE(FLATDATA(pchCommand)); | |
40 | READWRITE(nMessageSize); | |
507fd9d1 GS |
41 | READWRITE(nChecksum); |
42 | ) | |
43 | ||
44 | // TODO: make private (improves encapsulation) | |
45 | public: | |
24154ed6 | 46 | enum { |
24154ed6 MC |
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, | |
41b052ad PW |
52 | CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE, |
53 | HEADER_SIZE=MESSAGE_START_SIZE+COMMAND_SIZE+MESSAGE_SIZE_SIZE+CHECKSUM_SIZE | |
24154ed6 MC |
54 | }; |
55 | char pchMessageStart[MESSAGE_START_SIZE]; | |
507fd9d1 GS |
56 | char pchCommand[COMMAND_SIZE]; |
57 | unsigned int nMessageSize; | |
58 | unsigned int nChecksum; | |
59 | }; | |
60 | ||
6b8de05d | 61 | /** nServices flags */ |
33e28c99 GS |
62 | enum |
63 | { | |
64 | NODE_NETWORK = (1 << 0), | |
65 | }; | |
66 | ||
6b8de05d | 67 | /** A CService with information about it as peer */ |
67a42f92 | 68 | class CAddress : public CService |
33e28c99 GS |
69 | { |
70 | public: | |
71 | CAddress(); | |
51ed9ec9 | 72 | explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK); |
33e28c99 GS |
73 | |
74 | void Init(); | |
75 | ||
76 | IMPLEMENT_SERIALIZE | |
77 | ( | |
67a42f92 PW |
78 | CAddress* pthis = const_cast<CAddress*>(this); |
79 | CService* pip = (CService*)pthis; | |
33e28c99 | 80 | if (fRead) |
67a42f92 | 81 | pthis->Init(); |
33e28c99 | 82 | if (nType & SER_DISK) |
8b09cd3a JG |
83 | READWRITE(nVersion); |
84 | if ((nType & SER_DISK) || | |
85 | (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH))) | |
86 | READWRITE(nTime); | |
33e28c99 | 87 | READWRITE(nServices); |
67a42f92 | 88 | READWRITE(*pip); |
33e28c99 GS |
89 | ) |
90 | ||
33e28c99 GS |
91 | void print() const; |
92 | ||
93 | // TODO: make private (improves encapsulation) | |
94 | public: | |
51ed9ec9 | 95 | uint64_t nServices; |
33e28c99 GS |
96 | |
97 | // disk and network only | |
98 | unsigned int nTime; | |
99 | ||
100 | // memory only | |
51ed9ec9 | 101 | int64_t nLastTry; |
33e28c99 GS |
102 | }; |
103 | ||
6b8de05d | 104 | /** inv message data */ |
e4dde849 GS |
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 | ||
112 | IMPLEMENT_SERIALIZE | |
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; | |
128 | uint256 hash; | |
129 | }; | |
130 | ||
f3a84c3a LD |
131 | enum |
132 | { | |
133 | MSG_TX = 1, | |
134 | MSG_BLOCK, | |
b02ddbed MC |
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. | |
137 | MSG_FILTERED_BLOCK, | |
f3a84c3a LD |
138 | }; |
139 | ||
507fd9d1 | 140 | #endif // __INCLUDED_PROTOCOL_H__ |