xrpld
Loading...
Searching...
No Matches
xrpl::reduce_relay::Slot< ClockType > Class Template Referencefinal

Slot is associated with a specific validator via validator's public key. More...

#include <Slot.h>

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

Classes

struct  PeerInfo
 Data maintained for each peer. More...

Private Types

using id_t = Peer::id_t
using time_point = ClockType::time_point
using ignored_squelch_callback = std::function<void()>

Private Member Functions

 Slot (SquelchHandler const &handler, beast::Journal journal, uint16_t maxSelectedPeers)
 Constructor.
void update (PublicKey const &validator, id_t id, protocol::MessageType type, ignored_squelch_callback callback)
 Update peer info.
void deletePeer (PublicKey const &validator, id_t id, bool erase)
 Handle peer deletion when a peer disconnects.
time_point const & getLastSelected () const
 Get the time of the last peer selection round.
std::uint16_t inState (PeerState state) const
 Return number of peers in state.
std::uint16_t notInState (PeerState state) const
 Return number of peers not in state.
SlotState getState () const
 Return Slot's state.
std::set< id_tgetSelected () const
 Return selected peers.
std::unordered_map< id_t, std::tuple< PeerState, uint16_t, uint32_t, uint32_t > > getPeers () const
 Get peers info.
void deleteIdlePeer (PublicKey const &validator)
 Check if peers stopped relaying messages.
std::chrono::seconds getSquelchDuration (std::size_t npeers)
 Get random squelch duration between kMinUnsquelchExpire and min(max(kMaxUnsquelchExpireDefault, kSquelchPerPeer * npeers), kMaxUnsquelchExpirePeers).
void resetCounts ()
 Reset counts of peers in Selected or Counting state.
void initCounting ()
 Initialize slot to Counting state.

Private Attributes

std::unordered_map< id_t, PeerInfopeers_
std::unordered_set< id_tconsidered_
std::uint16_t reachedThreshold_ {0}
ClockType::time_point lastSelected_
SlotState state_ {SlotState::Counting}
SquelchHandler const & handler_
beast::Journal const journal_
uint16_t const maxSelectedPeers_

Friends

class Slots< ClockType >

Detailed Description

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

Slot is associated with a specific validator via validator's public key.

Slot counts messages from a validator, selects peers to be the source of the messages, and communicates the peers to be squelched. Slot can be in the following states: 1) Counting. This is the peer selection state when Slot counts the messages and selects the peers; 2) Selected. Slot doesn't count messages in Selected state. A message received from unsquelched, disconnected peer, or idling peer may transition Slot to Counting state.

Definition at line 102 of file src/xrpld/overlay/Slot.h.

Member Typedef Documentation

◆ id_t

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

Definition at line 106 of file src/xrpld/overlay/Slot.h.

◆ time_point

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

Definition at line 107 of file src/xrpld/overlay/Slot.h.

◆ ignored_squelch_callback

template<typename ClockType>
using xrpl::reduce_relay::Slot< ClockType >::ignored_squelch_callback = std::function<void()>
private

Definition at line 110 of file src/xrpld/overlay/Slot.h.

Constructor & Destructor Documentation

◆ Slot()

template<typename ClockType>
xrpl::reduce_relay::Slot< ClockType >::Slot ( SquelchHandler const & handler,
beast::Journal journal,
uint16_t maxSelectedPeers )
private

Constructor.

Parameters
handlerSquelch/Unsquelch implementation
journalJournal for logging
maxSelectedPeersthe maximum number of peers to be selected as validator message source

Definition at line 119 of file src/xrpld/overlay/Slot.h.

Member Function Documentation

◆ update()

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

Update peer info.

If the message is from a new peer or from a previously expired squelched peer then switch the peer's and slot's state to Counting. If time of last selection round is > 2 * kMaxUnsquelchExpireDefault then switch the slot's state to Counting. If the number of messages for the peer is > kMinMessageThreshold then add peer to considered peers pool. If the number of considered peers who reached kMaxMessageThreshold is maxSelectedPeers_ then randomly select maxSelectedPeers_ from considered peers, and call squelch handler for each peer, which is not selected and not already in Squelched state. Set the state for those peers to Squelched and reset the count of all peers. Set slot's state to Selected. Message count is not updated when the slot is in Selected state.

Parameters
validatorPublic key of the source validator
idPeer id which received the message
typeMessage type (Validation and Propose Set only, others are ignored, future use)
callbackA callback to report ignored squelches

Definition at line 299 of file src/xrpld/overlay/Slot.h.

◆ deletePeer()

template<typename ClockType>
void xrpl::reduce_relay::Slot< ClockType >::deletePeer ( PublicKey const & validator,
id_t id,
bool erase )
private

Handle peer deletion when a peer disconnects.

If the peer is in Selected state then call unsquelch handler for every peer in squelched state and reset every peer's state to Counting. Switch Slot's state to Counting.

Parameters
validatorPublic key of the source validator
idDeleted peer id
eraseIf true then erase the peer. The peer is not erased when the peer when is idled. The peer is deleted when it disconnects

Definition at line 447 of file src/xrpld/overlay/Slot.h.

◆ getLastSelected()

template<typename ClockType>
time_point const & xrpl::reduce_relay::Slot< ClockType >::getLastSelected ( ) const
nodiscardprivate

Get the time of the last peer selection round.

Definition at line 172 of file src/xrpld/overlay/Slot.h.

◆ inState()

template<typename ClockType>
std::uint16_t xrpl::reduce_relay::Slot< ClockType >::inState ( PeerState state) const
nodiscardprivate

Return number of peers in state.

Definition at line 515 of file src/xrpld/overlay/Slot.h.

◆ notInState()

template<typename ClockType>
std::uint16_t xrpl::reduce_relay::Slot< ClockType >::notInState ( PeerState state) const
nodiscardprivate

Return number of peers not in state.

Definition at line 523 of file src/xrpld/overlay/Slot.h.

◆ getState()

template<typename ClockType>
SlotState xrpl::reduce_relay::Slot< ClockType >::getState ( ) const
nodiscardprivate

Return Slot's state.

Definition at line 193 of file src/xrpld/overlay/Slot.h.

◆ getSelected()

template<typename ClockType>
std::set< Peer::id_t > xrpl::reduce_relay::Slot< ClockType >::getSelected ( ) const
nodiscardprivate

Return selected peers.

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

◆ getPeers()

template<typename ClockType>
std::unordered_map< Peer::id_t, std::tuple< PeerState, uint16_t, uint32_t, uint32_t > > xrpl::reduce_relay::Slot< ClockType >::getPeers ( ) const
nodiscardprivate

Get peers info.

Return map of peer's state, count, squelch expiration milsec, and last message time milsec.

Definition at line 544 of file src/xrpld/overlay/Slot.h.

◆ deleteIdlePeer()

template<typename ClockType>
void xrpl::reduce_relay::Slot< ClockType >::deleteIdlePeer ( PublicKey const & validator)
private

Check if peers stopped relaying messages.

If a peer is selected peer then call unsquelch handler for all currently squelched peers and switch the slot to Counting state.

Parameters
validatorPublic key of the source validator

Definition at line 277 of file src/xrpld/overlay/Slot.h.

◆ getSquelchDuration()

template<typename ClockType>
std::chrono::seconds xrpl::reduce_relay::Slot< ClockType >::getSquelchDuration ( std::size_t npeers)
private

Get random squelch duration between kMinUnsquelchExpire and min(max(kMaxUnsquelchExpireDefault, kSquelchPerPeer * npeers), kMaxUnsquelchExpirePeers).

Parameters
npeersnumber of peers that can be squelched in the Slot

Definition at line 433 of file src/xrpld/overlay/Slot.h.

◆ resetCounts()

template<typename ClockType>
void xrpl::reduce_relay::Slot< ClockType >::resetCounts ( )
private

Reset counts of peers in Selected or Counting state.

Definition at line 494 of file src/xrpld/overlay/Slot.h.

◆ initCounting()

template<typename ClockType>
void xrpl::reduce_relay::Slot< ClockType >::initCounting ( )
private

Initialize slot to Counting state.

Definition at line 505 of file src/xrpld/overlay/Slot.h.

◆ Slots< ClockType >

template<typename ClockType>
friend class Slots< ClockType >
friend

Definition at line 88 of file src/xrpld/overlay/Slot.h.

Member Data Documentation

◆ peers_

template<typename ClockType>
std::unordered_map<id_t, PeerInfo> xrpl::reduce_relay::Slot< ClockType >::peers_
private

Definition at line 254 of file src/xrpld/overlay/Slot.h.

◆ considered_

template<typename ClockType>
std::unordered_set<id_t> xrpl::reduce_relay::Slot< ClockType >::considered_
private

Definition at line 258 of file src/xrpld/overlay/Slot.h.

◆ reachedThreshold_

template<typename ClockType>
std::uint16_t xrpl::reduce_relay::Slot< ClockType >::reachedThreshold_ {0}
private

Definition at line 261 of file src/xrpld/overlay/Slot.h.

◆ lastSelected_

template<typename ClockType>
ClockType::time_point xrpl::reduce_relay::Slot< ClockType >::lastSelected_
private

Definition at line 264 of file src/xrpld/overlay/Slot.h.

◆ state_

template<typename ClockType>
SlotState xrpl::reduce_relay::Slot< ClockType >::state_ {SlotState::Counting}
private

Definition at line 266 of file src/xrpld/overlay/Slot.h.

◆ handler_

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

Definition at line 267 of file src/xrpld/overlay/Slot.h.

◆ journal_

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

Definition at line 268 of file src/xrpld/overlay/Slot.h.

◆ maxSelectedPeers_

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

Definition at line 272 of file src/xrpld/overlay/Slot.h.