21 #include <libp2p/Capability.h> 22 #include <libp2p/CapabilityHost.h> 28 class SnapshotStorageFace;
86 u256 const& _networkId, boost::filesystem::path
const& _snapshotDownloadPath,
87 std::shared_ptr<SnapshotStorageFace> _snapshotStorage);
89 std::string
name()
const override {
return "par"; }
106 u256 const& _hostNetworkId,
u256 const& _chainTotalDifficulty,
107 h256 const& _chainCurrentHash,
h256 const& _chainGenesisHash,
108 h256 const& _snapshotBlockHash,
u256 const& _snapshotBlockNumber);
110 unsigned _skip,
bool _reverse);
116 std::vector<unsigned>
const& _protocolVersions,
u256 const& _networkId);
121 std::shared_ptr<WarpPeerObserverFace> createPeerObserver(
122 boost::filesystem::path
const& _snapshotDownloadPath);
124 void doBackgroundWork();
130 std::shared_ptr<p2p::CapabilityHostFace> m_host;
132 BlockChain
const& m_blockChain;
133 u256 const m_networkId;
135 std::shared_ptr<SnapshotStorageFace> m_snapshot;
136 std::shared_ptr<WarpPeerObserverFace> m_peerObserver;
138 std::unordered_map<NodeID, WarpPeerStatus> m_peers;
140 std::atomic<bool> m_backgroundWorkEnabled = {
false};
void disablePeer(NodeID const &_peerID, std::string const &_problem)
bool interpretCapabilityPacket(NodeID const &_peerID, unsigned _id, RLP const &) override
virtual void onPeerDisconnect(NodeID const &_peerID, Asking _asking)=0
WarpSubprotocolPacketType
unsigned protocolVersion() const
WarpCapability(std::shared_ptr< p2p::CapabilityHostFace > _host, BlockChain const &_blockChain, u256 const &_networkId, boost::filesystem::path const &_snapshotDownloadPath, std::shared_ptr< SnapshotStorageFace > _snapshotStorage)
Implements the blockchain database. All data this gives is disk-backed. .
void onStarting() override
u256 m_totalDifficulty
Peer's latest block's total difficulty.
Asking m_asking
What, if anything, we last asked the other peer for.
virtual void onPeerBlockHeaders(NodeID const &_peerID, RLP const &_r)=0
h256 m_genesisHash
Peer's genesis hash.
void requestBlockHeaders(NodeID const &_peerID, unsigned _startNumber, unsigned _count, unsigned _skip, bool _reverse)
time_t m_lastAsk
When we asked for it. Allows a time out.
void onStopping() override
void requestManifest(NodeID const &_peerID)
h256 m_latestHash
These are determined through either a Status message.
virtual ~WarpPeerObserverFace()
unsigned m_protocolVersion
Peer's protocol version.
virtual void onPeerData(NodeID const &_peerID, RLP const &_r)=0
u256 version() const override
void onConnect(NodeID const &_peerID, u256 const &_peerCapabilityVersion) override
p2p::CapabilityHostFace & capabilityHost()
unsigned const c_WarpProtocolVersion
void onDisconnect(NodeID const &_peerID) override
void requestStatus(NodeID const &_peerID, unsigned _hostProtocolVersion, u256 const &_hostNetworkId, u256 const &_chainTotalDifficulty, h256 const &_chainCurrentHash, h256 const &_chainGenesisHash, h256 const &_snapshotBlockHash, u256 const &_snapshotBlockNumber)
bool validateStatus(NodeID const &_peerID, h256 const &_genesisHash, std::vector< unsigned > const &_protocolVersions, u256 const &_networkId)
Validates whether peer is able to communicate with the host, disables peer if not.
unsigned messageCount() const override
virtual void onPeerManifest(NodeID const &_peerID, RLP const &_r)=0
u256 m_networkId
Peer's network id.
std::string name() const override
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
virtual void onPeerStatus(NodeID const &_peerID)=0
bool requestData(NodeID const &_peerID, h256 const &_chunkHash)