Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
node
timeoffsets.h
Go to the documentation of this file.
1
// Copyright (c) 2024-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_NODE_TIMEOFFSETS_H
6
#define BITCOIN_NODE_TIMEOFFSETS_H
7
8
#include <
sync.h
>
9
10
#include <chrono>
11
#include <cstddef>
12
#include <deque>
13
14
namespace
node
{
15
class
Warnings
;
16
}
// namespace node
17
18
class
TimeOffsets
19
{
20
public
:
21
TimeOffsets
(
node::Warnings
& warnings) :
m_warnings
{warnings} {}
22
23
private
:
25
static
constexpr
size_t
MAX_SIZE
{50};
27
static
constexpr
std::chrono::minutes
WARN_THRESHOLD
{10};
28
29
mutable
Mutex
m_mutex
;
32
std::deque<std::chrono::seconds> m_offsets
GUARDED_BY
(
m_mutex
){};
33
34
node::Warnings
&
m_warnings
;
35
36
public
:
38
void
Add
(std::chrono::seconds offset)
EXCLUSIVE_LOCKS_REQUIRED
(!
m_mutex
);
39
42
std::chrono::seconds
Median
() const
EXCLUSIVE_LOCKS_REQUIRED
(!
m_mutex
);
43
46
bool
WarnIfOutOfSync
() const
EXCLUSIVE_LOCKS_REQUIRED
(!
m_mutex
);
47
};
48
49
#endif
// BITCOIN_NODE_TIMEOFFSETS_H
TimeOffsets::Add
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a new time offset sample.
Definition
timeoffsets.cpp:22
TimeOffsets::MAX_SIZE
static constexpr size_t MAX_SIZE
Maximum number of timeoffsets stored.
Definition
timeoffsets.h:25
TimeOffsets::m_warnings
node::Warnings & m_warnings
Definition
timeoffsets.h:34
TimeOffsets::WarnIfOutOfSync
bool WarnIfOutOfSync() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Raise warnings if the median time offset exceeds the warnings threshold.
Definition
timeoffsets.cpp:46
TimeOffsets::m_mutex
Mutex m_mutex
Definition
timeoffsets.h:29
TimeOffsets::Median
std::chrono::seconds Median() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Compute and return the median of the collected time offset samples.
Definition
timeoffsets.cpp:34
TimeOffsets::TimeOffsets
TimeOffsets(node::Warnings &warnings)
Definition
timeoffsets.h:21
TimeOffsets::GUARDED_BY
std::deque< std::chrono::seconds > m_offsets GUARDED_BY(m_mutex)
The observed time differences between our local clock and those of our outbound peers.
Definition
timeoffsets.h:32
TimeOffsets::WARN_THRESHOLD
static constexpr std::chrono::minutes WARN_THRESHOLD
Minimum difference between system and network time for a warning to be raised.
Definition
timeoffsets.h:27
node::Warnings
Manages warning messages within a node.
Definition
warnings.h:40
node
Definition
messages.h:21
sync.h
Mutex
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
Definition
sync.h:123
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition
threadsafety.h:51
Generated on
for Bitcoin Core by
1.17.0