Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
protocol.h
Go to the documentation of this file.
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 __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 "serialize.h"
14 #include "netbase.h"
15 #include <string>
16 #include "uint256.h"
17 
18 extern bool fTestNet;
19 static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
20 {
21  return testnet ? 19336 : 9336;
22 }
23 
24 
25 extern unsigned char pchMessageStart[4];
26 
34 {
35  public:
37  CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
38 
39  std::string GetCommand() const;
40  bool IsValid() const;
41 
43  (
48  )
49 
50  // TODO: make private (improves encapsulation)
51  public:
52  enum {
53  MESSAGE_START_SIZE=sizeof(::pchMessageStart),
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  };
62  char pchMessageStart[MESSAGE_START_SIZE];
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 
76 class CAddress : public CService
77 {
78  public:
79  CAddress();
80  explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
81 
82  void Init();
83 
85  (
86  CAddress* pthis = const_cast<CAddress*>(this);
87  CService* pip = (CService*)pthis;
88  if (fRead)
89  pthis->Init();
90  if (nType & SER_DISK)
91  READWRITE(nVersion);
92  if ((nType & SER_DISK) ||
93  (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
94  READWRITE(nTime);
95  READWRITE(nServices);
96  READWRITE(*pip);
97  )
98 
99  void print() const;
100 
101  // TODO: make private (improves encapsulation)
102  public:
104 
105  // disk and network only
106  unsigned int nTime;
107 
108  // memory only
110 };
111 
113 class CInv
114 {
115  public:
116  CInv();
117  CInv(int typeIn, const uint256& hashIn);
118  CInv(const std::string& strType, const uint256& hashIn);
119 
121  (
122  READWRITE(type);
123  READWRITE(hash);
124  )
125 
126  friend bool operator<(const CInv& a, const CInv& b);
127 
128  bool IsKnownType() const;
129  const char* GetCommand() const;
130  std::string ToString() const;
131  void print() const;
132 
133  // TODO: make private (improves encapsulation)
134  public:
135  int type;
137 };
138 
139 enum
140 {
141  MSG_TX = 1,
143  // Nodes may always request a MSG_FILTERED_BLOCK in a getdata, however,
144  // MSG_FILTERED_BLOCK should not appear in any invs except as a part of getdata.
146 };
147 
148 #endif // __INCLUDED_PROTOCOL_H__
uint64 nServices
Definition: protocol.h:103
#define READWRITE(obj)
Definition: serialize.h:93
inv message data
Definition: protocol.h:113
void Init()
Definition: netbase.cpp:967
char pchCommand[COMMAND_SIZE]
Definition: protocol.h:63
#define IMPLEMENT_SERIALIZE(statements)
Definition: serialize.h:55
unsigned long long uint64
Definition: serialize.h:26
#define FLATDATA(obj)
Definition: serialize.h:304
unsigned int nChecksum
Definition: protocol.h:65
unsigned char pchMessageStart[4]
Definition: main.cpp:3178
bool fTestNet
Definition: util.cpp:81
int type
Definition: protocol.h:135
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:90
A CService with information about it as peer.
Definition: protocol.h:76
uint256 hash
Definition: protocol.h:136
int64 nLastTry
Definition: protocol.h:109
std::string GetCommand() const
Definition: protocol.cpp:40
IMPLEMENT_SERIALIZE(READWRITE(FLATDATA(pchMessageStart));READWRITE(FLATDATA(pchCommand));READWRITE(nMessageSize);READWRITE(nChecksum);) public char pchMessageStart[MESSAGE_START_SIZE]
Definition: protocol.h:43
256-bit unsigned integer
Definition: uint256.h:537
unsigned int nTime
Definition: protocol.h:106
unsigned int nMessageSize
Definition: protocol.h:64
uint32_t hash
Definition: cache.cc:34
bool IsValid() const
Definition: protocol.cpp:48
Message header.
Definition: protocol.h:33
long long int64
Definition: serialize.h:25