Update CMakeLists.txt - play with openssl
[novacoin.git] / src / protocol.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 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 __INCLUDED_PROTOCOL_H__
7 #define __INCLUDED_PROTOCOL_H__
8
9 #include "serialize.h"
10 #include "netbase.h"
11 #include "uint256.h"
12 #include "version.h"
13
14 extern bool fTestNet;
15 inline unsigned short GetDefaultPort()
16 {
17     return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
18 }
19
20
21 extern unsigned char pchMessageStart[4];
22
23 /** Message header.
24  * (4) message start.
25  * (12) command.
26  * (4) size.
27  * (4) checksum.
28  */
29 class CMessageHeader
30 {
31     public:
32         CMessageHeader();
33         CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
34
35         std::string GetCommand() const;
36         bool IsValid() const;
37
38         IMPLEMENT_SERIALIZE
39             (
40              READWRITE(FLATDATA(pchMessageStart));
41              READWRITE(FLATDATA(pchCommand));
42              READWRITE(nMessageSize);
43              READWRITE(nChecksum);
44             )
45
46     // TODO: make private (improves encapsulation)
47     public:
48         enum {
49             MESSAGE_START_SIZE=sizeof(::pchMessageStart),
50             COMMAND_SIZE=12,
51             MESSAGE_SIZE_SIZE=sizeof(int),
52             CHECKSUM_SIZE=sizeof(int),
53
54             MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
55             CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE
56         };
57         char pchMessageStart[MESSAGE_START_SIZE];
58         char pchCommand[COMMAND_SIZE];
59         unsigned int nMessageSize;
60         unsigned int nChecksum;
61 };
62
63 /** nServices flags */
64 enum
65 {
66     NODE_NETWORK = (1 << 0)
67 };
68
69 /** A CService with information about it as peer */
70 class CAddress : public CService
71 {
72     public:
73         CAddress();
74         explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
75
76         IMPLEMENT_SERIALIZE
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)))
86                  READWRITE(nTime);
87              READWRITE(nServices);
88              READWRITE(*pip);
89             )
90
91     // TODO: make private (improves encapsulation)
92     public:
93         uint64_t nServices;
94
95         // disk and network only
96         unsigned int nTime;
97
98         // memory only
99         int64_t nLastTry;
100 };
101
102 /** inv message data */
103 class CInv
104 {
105     public:
106         CInv();
107         CInv(int typeIn, const uint256& hashIn);
108         CInv(const std::string& strType, const uint256& hashIn);
109
110         IMPLEMENT_SERIALIZE
111         (
112             READWRITE(type);
113             READWRITE(hash);
114         )
115
116         friend bool operator<(const CInv& a, const CInv& b);
117
118         bool IsKnownType() const;
119         const char* GetCommand() const;
120         std::string ToString() const;
121
122     // TODO: make private (improves encapsulation)
123     public:
124         int type;
125         uint256 hash;
126 };
127
128 #endif // __INCLUDED_PROTOCOL_H__