]> Git Repo - VerusCoin.git/blame - src/protocol.h
Merge pull request #951 from TheBlueMatt/headerslimit
[VerusCoin.git] / src / protocol.h
CommitLineData
507fd9d1 1// Copyright (c) 2009-2010 Satoshi Nakamoto
88216419 2// Copyright (c) 2009-2012 The Bitcoin developers
507fd9d1
GS
3// Distributed under the MIT/X11 software license, see the accompanying
4// file license.txt 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"
67a42f92
PW
14#include "netbase.h"
15#include "util.h"
507fd9d1 16#include <string>
e4dde849 17#include "uint256.h"
507fd9d1 18
33e28c99
GS
19extern bool fTestNet;
20static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
21{
22 return testnet ? 18333 : 8333;
23}
24
507fd9d1
GS
25
26extern unsigned char pchMessageStart[4];
27
6b8de05d
PW
28/** Message header.
29 * (4) message start.
30 * (12) command.
31 * (4) size.
32 * (4) checksum.
33 */
507fd9d1
GS
34class CMessageHeader
35{
36 public:
37 CMessageHeader();
38 CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn);
39
40 std::string GetCommand() const;
41 bool IsValid() const;
42
43 IMPLEMENT_SERIALIZE
44 (
45 READWRITE(FLATDATA(pchMessageStart));
46 READWRITE(FLATDATA(pchCommand));
47 READWRITE(nMessageSize);
507fd9d1
GS
48 READWRITE(nChecksum);
49 )
50
51 // TODO: make private (improves encapsulation)
52 public:
53 enum { COMMAND_SIZE=12 };
54 char pchMessageStart[sizeof(::pchMessageStart)];
55 char pchCommand[COMMAND_SIZE];
56 unsigned int nMessageSize;
57 unsigned int nChecksum;
58};
59
6b8de05d 60/** nServices flags */
33e28c99
GS
61enum
62{
63 NODE_NETWORK = (1 << 0),
64};
65
6b8de05d 66/** A CService with information about it as peer */
67a42f92 67class CAddress : public CService
33e28c99
GS
68{
69 public:
70 CAddress();
c981d768 71 explicit CAddress(CService ipIn, uint64 nServicesIn=NODE_NETWORK);
33e28c99
GS
72
73 void Init();
74
75 IMPLEMENT_SERIALIZE
76 (
67a42f92
PW
77 CAddress* pthis = const_cast<CAddress*>(this);
78 CService* pip = (CService*)pthis;
33e28c99 79 if (fRead)
67a42f92 80 pthis->Init();
33e28c99
GS
81 if (nType & SER_DISK)
82 READWRITE(nVersion);
83 if ((nType & SER_DISK) || (nVersion >= 31402 && !(nType & SER_GETHASH)))
84 READWRITE(nTime);
85 READWRITE(nServices);
67a42f92 86 READWRITE(*pip);
33e28c99
GS
87 )
88
33e28c99
GS
89 void print() const;
90
91 // TODO: make private (improves encapsulation)
92 public:
bde280b9 93 uint64 nServices;
33e28c99
GS
94
95 // disk and network only
96 unsigned int nTime;
97
98 // memory only
5fee401f 99 int64 nLastTry;
33e28c99
GS
100};
101
6b8de05d 102/** inv message data */
e4dde849
GS
103class 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 void print() const;
122
123 // TODO: make private (improves encapsulation)
124 public:
125 int type;
126 uint256 hash;
127};
128
507fd9d1 129#endif // __INCLUDED_PROTOCOL_H__
This page took 0.052454 seconds and 4 git commands to generate.