Bitcoin Core  27.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

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
 

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 14 of file timeoffsets.h.

Member Function Documentation

◆ Add()

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

Add a new time offset sample.

Definition at line 23 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 24 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 35 of file timeoffsets.cpp.

◆ 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 47 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 21 of file timeoffsets.h.

◆ MAX_SIZE

constexpr size_t TimeOffsets::MAX_SIZE {50}
staticconstexprprivate

Maximum number of timeoffsets stored.

Definition at line 17 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 19 of file timeoffsets.h.


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