Anoncoin  0.9.4
P2P Digital Currency
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 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 // Many builder specific things set in the config file, ENABLE_WALLET is a good example. Included here in the header, we need ENABLE_I2PSAM some...
8 // That is if you want I2P support enabled and declared as a new type of available service.
9 #if defined(HAVE_CONFIG_H)
10 #include "config/anoncoin-config.h"
11 #endif
12 
13 #ifndef __cplusplus
14 # error This header can only be compiled as C++.
15 #endif
16 
17 #ifndef __INCLUDED_PROTOCOL_H__
18 #define __INCLUDED_PROTOCOL_H__
19 
20 #include "chainparams.h"
21 #include "netbase.h"
22 #include "serialize.h"
23 #include "uint256.h"
24 
25 #include <stdint.h>
26 #include <string>
27 
35 {
36  public:
38  CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
39 
40  std::string GetCommand() const;
41  bool IsValid() const;
42 
44  (
49  )
50 
51  // TODO: make private (improves encapsulation)
52  public:
53  enum {
54  COMMAND_SIZE=12,
55  MESSAGE_SIZE_SIZE=sizeof(int),
56  CHECKSUM_SIZE=sizeof(int),
57 
58  MESSAGE_SIZE_OFFSET=MESSAGE_START_SIZE+COMMAND_SIZE,
59  CHECKSUM_OFFSET=MESSAGE_SIZE_OFFSET+MESSAGE_SIZE_SIZE,
60  HEADER_SIZE=MESSAGE_START_SIZE+COMMAND_SIZE+MESSAGE_SIZE_SIZE+CHECKSUM_SIZE
61  };
63  char pchCommand[COMMAND_SIZE];
64  unsigned int nMessageSize;
65  unsigned int nChecksum;
66 };
67 
69 enum
70 {
71  NODE_NETWORK = (1 << 0),
72  NODE_BLOOM = (1 << 1),
73 
74  // Bits 24-31 are reserved for temporary experiments. Just pick a bit that
75  // isn't getting used, or one not being used much, and notify the
76  // bitcoin-development mailing list. Remember that service bits are just
77  // unauthenticated advertisements, so your code must be robust against
78  // collisions and other cases where nodes may be advertising a service they
79  // do not actually support. Other service bits should be allocated via the
80  // BIP process.
81 
82 // Todo: Check/consider the above new commentary. Perhaps we should move the I2P service bit over even more.
83 // However, for compatibility with existing nodes running 0.8.5 we need to establish this position as indicating
84 // the I2P network. Consider the possibly of requesting it's allocation via the BIP process, as mentioned above.
85 #ifdef ENABLE_I2PSAM
86  NODE_I2P = (1 << 7),
87 #endif
88 };
89 
91 class CAddress : public CService
92 {
93  public:
94  CAddress();
95  explicit CAddress(CService ipIn, uint64_t nServicesIn=NODE_NETWORK);
96 
97  void Init();
98 
100  (
101  CAddress* pthis = const_cast<CAddress*>(this);
102  CService* pip = (CService*)pthis;
103  if (fRead)
104  pthis->Init();
105  if (nType & SER_DISK)
106  READWRITE(nVersion);
107  if ((nType & SER_DISK) ||
108  (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
109  READWRITE(nTime);
111  READWRITE(*pip);
112  )
113 
114  void print() const;
115 
116  // TODO: make private (improves encapsulation)
117  public:
118  uint64_t nServices;
119 
120  // disk and network only
121  unsigned int nTime;
122 
123  // memory only
124  int64_t nLastTry;
125 };
126 
128 class CInv
129 {
130  public:
131  CInv();
132  CInv(int typeIn, const uint256& hashIn);
133  CInv(const std::string& strType, const uint256& hashIn);
134 
136  (
137  READWRITE(type);
138  READWRITE(hash);
139  )
140 
141  friend bool operator<(const CInv& a, const CInv& b);
142 
143  bool IsKnownType() const;
144  const char* GetCommand() const;
145  std::string ToString() const;
146  void print() const;
147 
148  // TODO: make private (improves encapsulation)
149  public:
150  int type;
152 };
153 
154 enum
155 {
156  MSG_TX = 1,
158  // Nodes may always request a MSG_FILTERED_BLOCK in a getdata, however,
159  // MSG_FILTERED_BLOCK should not appear in any invs except as a part of getdata.
161 };
162 
163 #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:118
#define READWRITE(obj)
Definition: serialize.h:101
const char * GetCommand() const
Definition: protocol.cpp:137
void print() const
Definition: protocol.cpp:149
void Init()
Definition: protocol.cpp:92
const CInv & b
Definition: protocol.h:141
IMPLEMENT_SERIALIZE(READWRITE(type);READWRITE(hash);) friend bool operator<(const CInv &a
inv message data
Definition: protocol.h:128
void Init()
Definition: netbase.cpp:1138
char pchCommand[COMMAND_SIZE]
Definition: protocol.h:63
bool IsKnownType() const
Definition: protocol.cpp:132
#define IMPLEMENT_SERIALIZE(statements)
Definition: serialize.h:63
#define FLATDATA(obj)
Definition: serialize.h:318
unsigned int nChecksum
Definition: protocol.h:65
#define MESSAGE_START_SIZE
Definition: chainparams.h:25
int type
Definition: protocol.h:150
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:109
int64_t nLastTry
Definition: protocol.h:124
A CService with information about it as peer.
Definition: protocol.h:91
uint256 hash
Definition: protocol.h:151
std::string GetCommand() const
Definition: protocol.cpp:41
IMPLEMENT_SERIALIZE(READWRITE(FLATDATA(pchMessageStart));READWRITE(FLATDATA(pchCommand));READWRITE(nMessageSize);READWRITE(nChecksum);) public char pchMessageStart[MESSAGE_START_SIZE]
Definition: protocol.h:44
void print() const
Definition: netbase.cpp:1330
256-bit unsigned integer
Definition: uint256.h:532
unsigned int nTime
Definition: protocol.h:121
CAddress()
Definition: protocol.cpp:81
unsigned int nMessageSize
Definition: protocol.h:64
CInv()
Definition: protocol.cpp:99
std::string ToString() const
Definition: protocol.cpp:144
bool IsValid() const
Definition: protocol.cpp:49
Message header.
Definition: protocol.h:34