Mercurial > hg > bitcoin
annotate src/protocol.h @ 876:b5abe85df1e7 draft
Start moving protocol-specific code to protocol.[ch]pp
Move CMessageHeader from net.h to protocol.[ch]pp, with the
implementation in the .cpp compilation unit (compiling once is enough).
This commit does *not* and should not modify *any* code, it only moves
it from net.h and splits it across protocol.cpp and protocol.hpp.
Indentation changes aside the closest thing to a modification of code is
the addition of the 'TODO' comment (the execution of which requires code
modifications and thus doesn't belong in this commit).
Signed-off-by: Giel van Schijndel <me@mortis.eu>
author | Giel van Schijndel <me@mortis.eu> |
---|---|
date | Thu, 11 Aug 2011 18:14:53 +0200 |
parents | |
children | aef18cc34b65 |
rev | line source |
---|---|
876
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
1 // Copyright (c) 2009-2010 Satoshi Nakamoto |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
2 // Copyright (c) 2011 The Bitcoin developers |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
3 // Distributed under the MIT/X11 software license, see the accompanying |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php. |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
5 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
6 #ifndef __cplusplus |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
7 # error This header can only be compiled as C++. |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
8 #endif |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
9 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
10 #ifndef __INCLUDED_PROTOCOL_H__ |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
11 #define __INCLUDED_PROTOCOL_H__ |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
12 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
13 #include "serialize.h" |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
14 #include <string> |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
15 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
16 // |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
17 // Message header |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
18 // (4) message start |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
19 // (12) command |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
20 // (4) size |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
21 // (4) checksum |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
22 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
23 extern unsigned char pchMessageStart[4]; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
24 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
25 class CMessageHeader |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
26 { |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
27 public: |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
28 CMessageHeader(); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
29 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
30 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
31 std::string GetCommand() const; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
32 bool IsValid() const; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
33 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
34 IMPLEMENT_SERIALIZE |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
35 ( |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
36 READWRITE(FLATDATA(pchMessageStart)); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
37 READWRITE(FLATDATA(pchCommand)); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
38 READWRITE(nMessageSize); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
39 if (nVersion >= 209) |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
40 READWRITE(nChecksum); |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
41 ) |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
42 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
43 // TODO: make private (improves encapsulation) |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
44 public: |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
45 enum { COMMAND_SIZE=12 }; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
46 char pchMessageStart[sizeof(::pchMessageStart)]; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
47 char pchCommand[COMMAND_SIZE]; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
48 unsigned int nMessageSize; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
49 unsigned int nChecksum; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
50 }; |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
51 |
b5abe85df1e7
Start moving protocol-specific code to protocol.[ch]pp
Giel van Schijndel <me@mortis.eu>
parents:
diff
changeset
|
52 #endif // __INCLUDED_PROTOCOL_H__ |