rippled
ripple
rpc
impl
ShardVerificationScheduler.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 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
#include <ripple/app/ledger/LedgerMaster.h>
21
#include <ripple/rpc/ShardVerificationScheduler.h>
22
23
namespace
ripple
{
24
namespace
RPC {
25
26
ShardVerificationScheduler::ShardVerificationScheduler
(
27
std::chrono::seconds
retryInterval,
28
std::uint32_t
maxAttempts)
29
: retryInterval_(
30
(retryInterval ==
std
::chrono::seconds(0) ? defaultRetryInterval_
31
: retryInterval))
32
, maxAttempts_(maxAttempts == 0 ? defaultmaxAttempts_ : maxAttempts)
33
{
34
}
35
36
bool
37
ShardVerificationScheduler::retry
(
38
Application
& app,
39
bool
shouldHaveHash,
40
retryFunction
f)
41
{
42
if
(
numAttempts_
>=
maxAttempts_
)
43
return
false
;
44
45
// Retry attempts only count when we
46
// have a validated ledger with a
47
// sequence later than the shard's
48
// last ledger.
49
if
(shouldHaveHash)
50
++
numAttempts_
;
51
52
if
(!
timer_
)
53
timer_
= std::make_unique<waitable_timer>(app.
getIOService
());
54
55
timer_
->expires_from_now(
retryInterval_
);
56
timer_
->async_wait(f);
57
58
return
true
;
59
}
60
61
void
62
ShardVerificationScheduler::reset
()
63
{
64
numAttempts_
= 0;
65
}
66
67
}
// namespace RPC
68
}
// namespace ripple
ripple::Application
Definition:
Application.h:115
ripple::RPC::ShardVerificationScheduler::ShardVerificationScheduler
ShardVerificationScheduler()=default
ripple::RPC::ShardVerificationScheduler::reset
void reset()
Definition:
ShardVerificationScheduler.cpp:62
std::chrono::seconds
ripple::RPC::ShardVerificationScheduler::timer_
std::unique_ptr< waitable_timer > timer_
Definition:
ShardVerificationScheduler.h:75
std::function
ripple::RPC::ShardVerificationScheduler::maxAttempts_
const std::uint32_t maxAttempts_
Definition:
ShardVerificationScheduler.h:73
std::uint32_t
ripple::RPC::ShardVerificationScheduler::retry
bool retry(Application &app, bool shouldHaveHash, retryFunction f)
Definition:
ShardVerificationScheduler.cpp:37
ripple::RPC::ShardVerificationScheduler::retryInterval_
const std::chrono::seconds retryInterval_
Definition:
ShardVerificationScheduler.h:70
ripple::Application::getIOService
virtual boost::asio::io_service & getIOService()=0
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
std
STL namespace.
ripple::RPC::ShardVerificationScheduler::numAttempts_
std::uint32_t numAttempts_
Definition:
ShardVerificationScheduler.h:78
Generated by
1.8.17