rippled
Loading...
Searching...
No Matches
InboundLedger.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
21#define RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/ledger/detail/TimeoutCounter.h>
25#include <xrpld/app/main/Application.h>
26#include <xrpld/overlay/PeerSet.h>
27
28#include <xrpl/basics/CountedObject.h>
29
30#include <mutex>
31#include <set>
32#include <utility>
33
34namespace ripple {
35
36// A ledger we are trying to acquire
37class InboundLedger final : public TimeoutCounter,
38 public std::enable_shared_from_this<InboundLedger>,
39 public CountedObject<InboundLedger>
40{
41public:
43
44 // These are the reasons we might acquire a ledger
45 enum class Reason {
46 HISTORY, // Acquiring past ledger
47 GENERIC, // Generic other reasons
48 CONSENSUS // We believe the consensus round requires this ledger
49 };
50
52 Application& app,
53 uint256 const& hash,
54 std::uint32_t seq,
55 Reason reason,
58
60
61 // Called when another attempt is made to fetch this same ledger
62 void
64
66 bool
67 isComplete() const
68 {
69 return complete_;
70 }
71
73 bool
74 isFailed() const
75 {
76 return failed_;
77 }
78
80 getLedger() const
81 {
82 return mLedger;
83 }
84
86 getSeq() const
87 {
88 return mSeq;
89 }
90
91 bool
92 checkLocal();
93 void
94 init(ScopedLockType& collectionLock);
95
96 bool
97 gotData(
100
103
106 getJson(int);
107
108 void
109 runData();
110
111 void
113 {
115 }
116
119 {
120 return mLastAction;
121 }
122
123private:
125
126 void
129 TriggerReason reason);
130
131 void
133
136
137 void
138 addPeers();
139
140 void
142
143 void
144 done();
145
146 void
147 onTimer(bool progress, ScopedLockType& peerSetLock) override;
148
150 getPeerCount() const;
151
153 pmDowncast() override;
154
155 int
156 processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
157
158 bool
159 takeHeader(std::string const& data);
160
161 void
162 receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode&);
163
164 bool
165 takeTxRootNode(Slice const& data, SHAMapAddNode&);
166
167 bool
168 takeAsRootNode(Slice const& data, SHAMapAddNode&);
169
171 neededTxHashes(int max, SHAMapSyncFilter* filter) const;
172
174 neededStateHashes(int max, SHAMapSyncFilter* filter) const;
175
178
187
189
191
192 // Data we have received from peers
199};
200
201} // namespace ripple
202
203#endif
Represents a JSON value.
Definition: json_value.h:150
virtual time_point now() const =0
Returns the current time.
Tracks the number of instances of an object.
Json::Value getJson(int)
Return a Json::objectValue.
void runData()
Process pending TMLedgerData Query the a random sample of the 'best' peers.
std::size_t getPeerCount() const
void trigger(std::shared_ptr< Peer > const &, TriggerReason)
Request more nodes, perhaps from a specific peer.
void init(ScopedLockType &collectionLock)
clock_type::time_point mLastAction
std::set< uint256 > mRecentNodes
void receiveNode(protocol::TMLedgerData &packet, SHAMapAddNode &)
Process node data received from a peer Call with a lock.
bool isComplete() const
Returns true if we got all the data.
Definition: InboundLedger.h:67
bool takeHeader(std::string const &data)
Take ledger header data Call with a lock.
void addPeers()
Add more peers to the set, if possible.
std::shared_ptr< Ledger const > getLedger() const
Definition: InboundLedger.h:80
int processData(std::shared_ptr< Peer > peer, protocol::TMLedgerData &data)
Process one TMLedgerData Returns the number of useful nodes.
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition: InboundLedger.h:42
std::uint32_t getSeq() const
Definition: InboundLedger.h:86
clock_type::time_point getLastAction() const
std::shared_ptr< Ledger > mLedger
std::vector< uint256 > neededTxHashes(int max, SHAMapSyncFilter *filter) const
SHAMapAddNode mStats
void tryDB(NodeStore::Database &srcDB)
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Called with a lock by the PeerSet when the timer expires.
std::vector< uint256 > neededStateHashes(int max, SHAMapSyncFilter *filter) const
bool isFailed() const
Returns false if we failed to get the data.
Definition: InboundLedger.h:74
void filterNodes(std::vector< std::pair< SHAMapNodeID, uint256 > > &nodes, TriggerReason reason)
bool takeAsRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
bool takeTxRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
std::vector< std::pair< std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > > > mReceivedData
bool gotData(std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > const &)
Stash a TMLedgerData received from a peer for later processing Returns 'true' if we need to dispatch.
std::vector< neededHash_t > getNeededHashes()
std::mutex mReceivedDataLock
void update(std::uint32_t seq)
std::unique_ptr< PeerSet > mPeerSet
Persistency layer for NodeObject.
Definition: Database.h:52
An immutable linear range of bytes.
Definition: Slice.h:46
This class is an "active" object.
std::unique_lock< std::recursive_mutex > ScopedLockType
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26