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