Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TimeOffsets Class Reference

#include <timeoffsets.h>

Collaboration diagram for TimeOffsets:
[legend]

Public Member Functions

 TimeOffsets (node::Warnings &warnings)
 
void Add (std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Add a new time offset sample. More...
 
std::chrono::seconds Median () const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Compute and return the median of the collected time offset samples. More...
 
bool WarnIfOutOfSync () const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
 Raise warnings if the median time offset exceeds the warnings threshold. More...
 

Private Member Functions

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. More...
 

Private Attributes

Mutex m_mutex
 
node::Warningsm_warnings
 

Static Private Attributes

static constexpr size_t MAX_SIZE {50}
 Maximum number of timeoffsets stored. More...
 
static constexpr std::chrono::minutes WARN_THRESHOLD {10}
 Minimum difference between system and network time for a warning to be raised. More...
 

Detailed Description

Definition at line 18 of file timeoffsets.h.

Constructor & Destructor Documentation

◆ TimeOffsets()

TimeOffsets::TimeOffsets ( node::Warnings warnings)
inline

Definition at line 21 of file timeoffsets.h.

Member Function Documentation

◆ Add()

void TimeOffsets::Add ( std::chrono::seconds  offset)

Add a new time offset sample.

Definition at line 22 of file timeoffsets.cpp.

◆ GUARDED_BY()

std::deque< std::chrono::seconds > m_offsets TimeOffsets::GUARDED_BY ( m_mutex  )
inlineprivate

The observed time differences between our local clock and those of our outbound peers.

A positive offset means our peer's clock is ahead of our local clock.

Definition at line 32 of file timeoffsets.h.

◆ Median()

std::chrono::seconds TimeOffsets::Median ( ) const

Compute and return the median of the collected time offset samples.

The median is returned as 0 when there are less than 5 samples.

Definition at line 34 of file timeoffsets.cpp.

Here is the caller graph for this function:

◆ WarnIfOutOfSync()

bool TimeOffsets::WarnIfOutOfSync ( ) const

Raise warnings if the median time offset exceeds the warnings threshold.

Returns true if warnings were raised.

Definition at line 46 of file timeoffsets.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_mutex

Mutex TimeOffsets::m_mutex
mutableprivate

Definition at line 29 of file timeoffsets.h.

◆ m_warnings

node::Warnings& TimeOffsets::m_warnings
private

Definition at line 34 of file timeoffsets.h.

◆ MAX_SIZE

constexpr size_t TimeOffsets::MAX_SIZE {50}
staticconstexprprivate

Maximum number of timeoffsets stored.

Definition at line 25 of file timeoffsets.h.

◆ WARN_THRESHOLD

constexpr std::chrono::minutes TimeOffsets::WARN_THRESHOLD {10}
staticconstexprprivate

Minimum difference between system and network time for a warning to be raised.

Definition at line 27 of file timeoffsets.h.


The documentation for this class was generated from the following files: