forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonNet.h
116 lines (96 loc) · 3.53 KB
/
CommonNet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file CommonNet.h
* @author Gav Wood <[email protected]>
* @date 2014
*
* Miscellanea required for the PeerServer/Session classes.
*/
#pragma once
#include <string>
#include <chrono>
#include <libdevcore/Common.h>
namespace dev
{
class OverlayDB;
namespace eth
{
#if ETH_DEBUG
static const unsigned c_maxHeaders = 2048; ///< Maximum number of hashes BlockHashes will ever send.
static const unsigned c_maxHeadersAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for.
static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send.
static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
static const unsigned c_maxPayload = 262144; ///< Maximum size of packet for us to send.
#else
static const unsigned c_maxHeaders = 2048; ///< Maximum number of hashes BlockHashes will ever send.
static const unsigned c_maxHeadersAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for.
static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send.
static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
static const unsigned c_maxPayload = 262144; ///< Maximum size of packet for us to send.
#endif
static const unsigned c_maxNodes = c_maxBlocks; ///< Maximum number of nodes will ever send.
static const unsigned c_maxReceipts = c_maxBlocks; ///< Maximum number of receipts will ever send.
class BlockChain;
class TransactionQueue;
class EthereumHost;
class EthereumPeer;
enum SubprotocolPacketType : byte
{
StatusPacket = 0x00,
NewBlockHashesPacket = 0x01,
TransactionsPacket = 0x02,
GetBlockHeadersPacket = 0x03,
BlockHeadersPacket = 0x04,
GetBlockBodiesPacket = 0x05,
BlockBodiesPacket = 0x06,
NewBlockPacket = 0x07,
GetNodeDataPacket = 0x0d,
NodeDataPacket = 0x0e,
GetReceiptsPacket = 0x0f,
ReceiptsPacket = 0x10,
//同步配置
NodeInfoSync = 0x11, //增加节点信息
DelNodeInfoSync = 0x12, //删除节点信息
PacketCount
};
enum class Asking
{
State,
BlockHeaders,
BlockBodies,
NodeData,
Receipts,
Nothing
};
enum class SyncState
{
NotSynced, ///< Initial chain sync has not started yet
Idle, ///< Initial chain sync complete. Waiting for new packets
Waiting, ///< Block downloading paused. Waiting for block queue to process blocks and free space
Blocks, ///< Downloading blocks
State, ///< Downloading state
NewBlocks, ///< Downloading blocks learned from NewHashes packet
Size /// Must be kept last
};
struct SyncStatus
{
SyncState state = SyncState::Idle;
unsigned protocolVersion = 0;
unsigned startBlockNumber;
unsigned currentBlockNumber;
unsigned highestBlockNumber;
bool majorSyncing = false;
};
}
}