CommonNet.h 3.3 KB

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