xrpld
Loading...
Searching...
No Matches
xrpl::reduce_relay::Slots< ClockType > Class Template Reference

Slots is a container for validator's Slot and handles Slot update when a message is received from a validator. More...

#include <Slot.h>

Collaboration diagram for xrpl::reduce_relay::Slots< ClockType >:

Public Member Functions

 Slots (ServiceRegistry &registry, SquelchHandler const &handler, Config const &config)
 ~Slots ()=default
bool baseSquelchReady ()
 Check if base squelching feature is enabled and ready.
bool reduceRelayReady ()
 Check if reduce_relay::kWaitOnBootup time passed since startup.
void updateSlotAndSquelch (uint256 const &key, PublicKey const &validator, id_t id, protocol::MessageType type)
 Calls Slot::update of Slot associated with the validator, with a noop callback.
void updateSlotAndSquelch (uint256 const &key, PublicKey const &validator, id_t id, protocol::MessageType type, Slot< ClockType >::ignored_squelch_callback callback)
 Calls Slot::update of Slot associated with the validator.
void deleteIdlePeers ()
 Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.
std::optional< std::uint16_tinState (PublicKey const &validator, PeerState state) const
 Return number of peers in state.
std::optional< std::uint16_tnotInState (PublicKey const &validator, PeerState state) const
 Return number of peers not in state.
bool inState (PublicKey const &validator, SlotState state) const
 Return true if Slot is in state.
std::set< id_tgetSelected (PublicKey const &validator)
 Get selected peers.
std::unordered_map< Peer::id_t, std::tuple< PeerState, uint16_t, uint32_t, std::uint32_t > > getPeers (PublicKey const &validator)
 Get peers info.
std::optional< SlotStategetState (PublicKey const &validator)
 Get Slot's state.
void deletePeer (id_t id, bool erase)
 Called when a peer is deleted.

Private Types

using time_point = ClockType::time_point
using id_t = Peer::id_t
using messages

Private Member Functions

bool addPeerMessage (uint256 const &key, id_t id)
 Add message/peer if have not seen this message from the peer.

Private Attributes

std::atomic_bool reduceRelayReady_ {false}
hash_map< PublicKey, Slot< ClockType > > slots_
SquelchHandler const & handler_
Logslogs_
beast::Journal const journal_
bool const baseSquelchEnabled_
uint16_t const maxSelectedPeers_

Static Private Attributes

static messages peersWithMessage {beast::getAbstractClock<ClockType>()}

Detailed Description

template<typename ClockType>
class xrpl::reduce_relay::Slots< ClockType >

Slots is a container for validator's Slot and handles Slot update when a message is received from a validator.

It also handles Slot aging and checks for peers which are disconnected or stopped relaying the messages.

Definition at line 527 of file overlay/Slot.h.

Member Typedef Documentation

◆ time_point

template<typename ClockType>
using xrpl::reduce_relay::Slots< ClockType >::time_point = ClockType::time_point
private

Definition at line 529 of file overlay/Slot.h.

◆ id_t

template<typename ClockType>
using xrpl::reduce_relay::Slots< ClockType >::id_t = Peer::id_t
private

Definition at line 530 of file overlay/Slot.h.

◆ messages

template<typename ClockType>
using xrpl::reduce_relay::Slots< ClockType >::messages
private
Initial value:
ClockType,
Seed functor once per construction.
detail::AgedUnorderedContainer< false, true, Key, T, Clock, Hash, KeyEqual, Allocator > aged_unordered_map
BaseUInt< 256 > uint256
Definition base_uint.h:562

Definition at line 531 of file overlay/Slot.h.

Constructor & Destructor Documentation

◆ Slots()

template<typename ClockType>
xrpl::reduce_relay::Slots< ClockType >::Slots ( ServiceRegistry & registry,
SquelchHandler const & handler,
Config const & config )
Parameters
registryThe service registry.
handlerSquelch/unsquelch implementation
configreference to the global config

Definition at line 543 of file overlay/Slot.h.

◆ ~Slots()

template<typename ClockType>
xrpl::reduce_relay::Slots< ClockType >::~Slots ( )
default

Member Function Documentation

◆ baseSquelchReady()

template<typename ClockType>
bool xrpl::reduce_relay::Slots< ClockType >::baseSquelchReady ( )

Check if base squelching feature is enabled and ready.

Definition at line 555 of file overlay/Slot.h.

◆ reduceRelayReady()

template<typename ClockType>
bool xrpl::reduce_relay::Slots< ClockType >::reduceRelayReady ( )

Check if reduce_relay::kWaitOnBootup time passed since startup.

Definition at line 562 of file overlay/Slot.h.

◆ updateSlotAndSquelch() [1/2]

template<typename ClockType>
void xrpl::reduce_relay::Slots< ClockType >::updateSlotAndSquelch ( uint256 const & key,
PublicKey const & validator,
id_t id,
protocol::MessageType type )

Calls Slot::update of Slot associated with the validator, with a noop callback.

Parameters
keyMessage's hash
validatorValidator's public key
idPeer's id which received the message
typeReceived protocol message type

Definition at line 581 of file overlay/Slot.h.

◆ updateSlotAndSquelch() [2/2]

template<typename ClockType>
void xrpl::reduce_relay::Slots< ClockType >::updateSlotAndSquelch ( uint256 const & key,
PublicKey const & validator,
id_t id,
protocol::MessageType type,
Slot< ClockType >::ignored_squelch_callback callback )

Calls Slot::update of Slot associated with the validator.

Parameters
keyMessage's hash
validatorValidator's public key
idPeer's id which received the message
typeReceived protocol message type
callbackA callback to report ignored validations

Definition at line 739 of file overlay/Slot.h.

◆ deleteIdlePeers()

template<typename ClockType>
void xrpl::reduce_relay::Slots< ClockType >::deleteIdlePeers ( )

Check if peers stopped relaying messages and if slots stopped receiving messages from the validator.

Definition at line 777 of file overlay/Slot.h.

◆ inState() [1/2]

template<typename ClockType>
std::optional< std::uint16_t > xrpl::reduce_relay::Slots< ClockType >::inState ( PublicKey const & validator,
PeerState state ) const
nodiscard

Return number of peers in state.

Definition at line 613 of file overlay/Slot.h.

◆ notInState()

template<typename ClockType>
std::optional< std::uint16_t > xrpl::reduce_relay::Slots< ClockType >::notInState ( PublicKey const & validator,
PeerState state ) const
nodiscard

Return number of peers not in state.

Definition at line 623 of file overlay/Slot.h.

◆ inState() [2/2]

template<typename ClockType>
bool xrpl::reduce_relay::Slots< ClockType >::inState ( PublicKey const & validator,
SlotState state ) const
nodiscard

Return true if Slot is in state.

Definition at line 633 of file overlay/Slot.h.

◆ getSelected()

template<typename ClockType>
std::set< id_t > xrpl::reduce_relay::Slots< ClockType >::getSelected ( PublicKey const & validator)

Get selected peers.

Definition at line 643 of file overlay/Slot.h.

◆ getPeers()

template<typename ClockType>
std::unordered_map< Peer::id_t, std::tuple< PeerState, uint16_t, uint32_t, std::uint32_t > > xrpl::reduce_relay::Slots< ClockType >::getPeers ( PublicKey const & validator)

Get peers info.

Return map of peer's state, count, and squelch expiration milliseconds.

Definition at line 655 of file overlay/Slot.h.

◆ getState()

template<typename ClockType>
std::optional< SlotState > xrpl::reduce_relay::Slots< ClockType >::getState ( PublicKey const & validator)

Get Slot's state.

Definition at line 665 of file overlay/Slot.h.

◆ deletePeer()

template<typename ClockType>
void xrpl::reduce_relay::Slots< ClockType >::deletePeer ( id_t id,
bool erase )

Called when a peer is deleted.

If the peer was selected to be the source of messages from the validator then squelched peers have to be unsquelched.

Parameters
idPeer's id
eraseIf true then erase the peer

Definition at line 769 of file overlay/Slot.h.

◆ addPeerMessage()

template<typename ClockType>
bool xrpl::reduce_relay::Slots< ClockType >::addPeerMessage ( uint256 const & key,
id_t id )
private

Add message/peer if have not seen this message from the peer.

A message is aged after IDLED seconds. Return true if added

Definition at line 708 of file overlay/Slot.h.

Member Data Documentation

◆ reduceRelayReady_

template<typename ClockType>
std::atomic_bool xrpl::reduce_relay::Slots< ClockType >::reduceRelayReady_ {false}
private

Definition at line 689 of file overlay/Slot.h.

◆ slots_

template<typename ClockType>
hash_map<PublicKey, Slot<ClockType> > xrpl::reduce_relay::Slots< ClockType >::slots_
private

Definition at line 691 of file overlay/Slot.h.

◆ handler_

template<typename ClockType>
SquelchHandler const& xrpl::reduce_relay::Slots< ClockType >::handler_
private

Definition at line 692 of file overlay/Slot.h.

◆ logs_

template<typename ClockType>
Logs& xrpl::reduce_relay::Slots< ClockType >::logs_
private

Definition at line 693 of file overlay/Slot.h.

◆ journal_

template<typename ClockType>
beast::Journal const xrpl::reduce_relay::Slots< ClockType >::journal_
private

Definition at line 694 of file overlay/Slot.h.

◆ baseSquelchEnabled_

template<typename ClockType>
bool const xrpl::reduce_relay::Slots< ClockType >::baseSquelchEnabled_
private

Definition at line 696 of file overlay/Slot.h.

◆ maxSelectedPeers_

template<typename ClockType>
uint16_t const xrpl::reduce_relay::Slots< ClockType >::maxSelectedPeers_
private

Definition at line 697 of file overlay/Slot.h.

◆ peersWithMessage

template<typename ClockType>
messages xrpl::reduce_relay::Slots< ClockType >::peersWithMessage {beast::getAbstractClock<ClockType>()}
staticprivate

Definition at line 703 of file overlay/Slot.h.