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#include <xrpl/basics/CountedObject.h>
28
29#include <mutex>
30#include <set>
31#include <utility>
32
33namespace ripple {
34
35// A ledger we are trying to acquire
36class InboundLedger final : public TimeoutCounter,
37 public std::enable_shared_from_this<InboundLedger>,
38 public CountedObject<InboundLedger>
39{
40public:
42
43 // These are the reasons we might acquire a ledger
44 enum class Reason {
45 HISTORY, // Acquiring past ledger
46 GENERIC, // Generic other reasons
47 CONSENSUS // We believe the consensus round requires this ledger
48 };
49
51 Application& app,
52 uint256 const& hash,
53 std::uint32_t seq,
54 Reason reason,
57
59
60 // Called when another attempt is made to fetch this same ledger
61 void
63
65 bool
66 isComplete() const
67 {
68 return complete_;
69 }
70
72 bool
73 isFailed() const
74 {
75 return failed_;
76 }
77
79 getLedger() const
80 {
81 return mLedger;
82 }
83
85 getSeq() const
86 {
87 return mSeq;
88 }
89
90 bool
91 checkLocal();
92 void
93 init(ScopedLockType& collectionLock);
94
95 bool
96 gotData(
99
102
105 getJson(int);
106
107 void
108 runData();
109
110 void
112 {
114 }
115
118 {
119 return mLastAction;
120 }
121
122private:
124
125 void
128 TriggerReason reason);
129
130 void
132
135
136 void
137 addPeers();
138
139 void
141
142 void
143 done();
144
145 void
146 onTimer(bool progress, ScopedLockType& peerSetLock) override;
147
149 getPeerCount() const;
150
152 pmDowncast() override;
153
154 int
155 processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
156
157 bool
158 takeHeader(std::string const& data);
159
160 void
161 receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode&);
162
163 bool
164 takeTxRootNode(Slice const& data, SHAMapAddNode&);
165
166 bool
167 takeAsRootNode(Slice const& data, SHAMapAddNode&);
168
170 neededTxHashes(int max, SHAMapSyncFilter* filter) const;
171
173 neededStateHashes(int max, SHAMapSyncFilter* filter) const;
174
177
186
188
190
191 // Data we have received from peers
198};
199
200} // namespace ripple
201
202#endif
Represents a JSON value.
Definition: json_value.h:148
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:66
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:79
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:41
std::uint32_t getSeq() const
Definition: InboundLedger.h:85
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:73
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:50
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