rippled
Loading...
Searching...
No Matches
SkipListAcquire.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2020 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_SKIPLISTACQUIRE_H_INCLUDED
21#define RIPPLE_APP_LEDGER_SKIPLISTACQUIRE_H_INCLUDED
22
23#include <xrpld/app/ledger/InboundLedger.h>
24#include <xrpld/app/ledger/Ledger.h>
25#include <xrpld/app/ledger/detail/TimeoutCounter.h>
26#include <xrpld/app/main/Application.h>
27#include <xrpld/shamap/SHAMap.h>
28
29namespace ripple {
30class InboundLedgers;
31class PeerSet;
32namespace test {
33class LedgerReplayClient;
34} // namespace test
35
40class SkipListAcquire final
41 : public TimeoutCounter,
42 public std::enable_shared_from_this<SkipListAcquire>,
43 public CountedObject<SkipListAcquire>
44{
45public:
52 std::function<void(bool successful, uint256 const& hash)>;
53
66
75 Application& app,
76 InboundLedgers& inboundLedgers,
77 uint256 const& ledgerHash,
79
80 ~SkipListAcquire() override;
81
86 void
87 init(int numPeers);
88
95 void
97 std::uint32_t ledgerSeq,
98 boost::intrusive_ptr<SHAMapItem const> const& item);
99
105 void
107
109 getData() const;
110
111private:
112 void
113 onTimer(bool progress, ScopedLockType& peerSetLock) override;
114
116 pmDowncast() override;
117
123 void
125
131 void
133 std::shared_ptr<Ledger const> const& ledger,
134 ScopedLockType& sl);
135
142 void
144 std::vector<uint256> const& skipList,
145 std::uint32_t ledgerSeq,
146 ScopedLockType& sl);
147
152 void
154
160 bool fallBack_ = false;
161
163};
164
165} // namespace ripple
166
167#endif
Tracks the number of instances of an object.
Manages the lifetime of inbound ledgers.
Manage the retrieval of a skip list in a ledger from the network.
void init(int numPeers)
Start the SkipListAcquire task.
void addDataCallback(OnSkipListDataCB &&cb)
Add a callback that will be called when the skipList is ready or failed.
std::function< void(bool successful, uint256 const &hash)> OnSkipListDataCB
A callback used to notify that the SkipList is ready or failed.
InboundLedgers & inboundLedgers_
std::shared_ptr< SkipListData const > getData() const
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Hook called from invokeOnTimer().
void notify(ScopedLockType &sl)
Call the OnSkipListDataCB callbacks.
void retrieveSkipList(std::shared_ptr< Ledger const > const &ledger, ScopedLockType &sl)
Retrieve the skip list from the ledger.
void trigger(std::size_t limit, ScopedLockType &sl)
Trigger another round.
std::shared_ptr< SkipListData const > data_
void processData(std::uint32_t ledgerSeq, boost::intrusive_ptr< SHAMapItem const > const &item)
Process the data extracted from a peer's reply.
void onSkipListAcquired(std::vector< uint256 > const &skipList, std::uint32_t ledgerSeq, ScopedLockType &sl)
Process the skip list.
std::vector< OnSkipListDataCB > dataReadyCallbacks_
std::unique_ptr< PeerSet > peerSet_
std::uint32_t noFeaturePeerCount_
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:25
SkipListData(std::uint32_t const ledgerSeq, std::vector< ripple::uint256 > const &skipList)
std::vector< ripple::uint256 > const skipList