rippled
Classes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
ripple::reduce_relay::Slot< clock_type > Class Template Referencefinal

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

Collaboration diagram for ripple::reduce_relay::Slot< clock_type >:
Collaboration graph
[legend]

Classes

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

Private Types

using id_t = Peer::id_t
 
using time_point = typename clock_type::time_point
 

Private Member Functions

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

Private Attributes

std::unordered_map< id_t, PeerInfopeers_
 
std::unordered_set< id_tconsidered_
 
std::uint16_t reachedThreshold_
 
clock_type::time_point lastSelected_
 
SlotState state_
 
SquelchHandler const & handler_
 
const beast::Journal journal_
 

Friends

class Slots< clock_type >
 

Detailed Description

template<typename clock_type>
class ripple::reduce_relay::Slot< clock_type >

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 104 of file overlay/Slot.h.

Member Typedef Documentation

◆ id_t

template<typename clock_type >
using ripple::reduce_relay::Slot< clock_type >::id_t = Peer::id_t
private

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

◆ time_point

template<typename clock_type >
using ripple::reduce_relay::Slot< clock_type >::time_point = typename clock_type::time_point
private

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

Constructor & Destructor Documentation

◆ Slot()

template<typename clock_type >
ripple::reduce_relay::Slot< clock_type >::Slot ( SquelchHandler const &  handler,
beast::Journal  journal 
)
private

Constructor.

Parameters
journalJournal for logging
handlerSquelch/Unsquelch implementation

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

Member Function Documentation

◆ update()

template<typename clock_type >
void ripple::reduce_relay::Slot< clock_type >::update ( PublicKey const &  validator,
id_t  id,
protocol::MessageType  type 
)
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 * MAX_UNSQUELCH_EXPIRE_DEFAULT then switch the slot's state to Counting. If the number of messages for the peer is > MIN_MESSAGE_THRESHOLD then add peer to considered peers pool. If the number of considered peers who reached MAX_MESSAGE_THRESHOLD is MAX_SELECTED_PEERS then randomly select MAX_SELECTED_PEERS 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)

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

◆ deletePeer()

template<typename clock_type >
void ripple::reduce_relay::Slot< clock_type >::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 413 of file overlay/Slot.h.

◆ getLastSelected()

template<typename clock_type >
const time_point& ripple::reduce_relay::Slot< clock_type >::getLastSelected ( ) const
private

Get the time of the last peer selection round.

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

◆ inState()

template<typename clock_type >
std::uint16_t ripple::reduce_relay::Slot< clock_type >::inState ( PeerState  state) const
private

Return number of peers in state.

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

◆ notInState()

template<typename clock_type >
std::uint16_t ripple::reduce_relay::Slot< clock_type >::notInState ( PeerState  state) const
private

Return number of peers not in state.

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

◆ getState()

template<typename clock_type >
SlotState ripple::reduce_relay::Slot< clock_type >::getState ( ) const
private

Return Slot's state.

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

◆ getSelected()

template<typename clock_type >
std::set< typename Peer::id_t > ripple::reduce_relay::Slot< clock_type >::getSelected
private

Return selected peers.

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

◆ getPeers()

template<typename clock_type >
std::unordered_map< typename Peer::id_t, std::tuple< PeerState, uint16_t, uint32_t, uint32_t > > ripple::reduce_relay::Slot< clock_type >::getPeers
private

Get peers info.

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

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

◆ deleteIdlePeer()

template<typename clock_type >
void ripple::reduce_relay::Slot< clock_type >::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 240 of file overlay/Slot.h.

◆ getSquelchDuration()

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

Get random squelch duration between MIN_UNSQUELCH_EXPIRE and min(max(MAX_UNSQUELCH_EXPIRE_DEFAULT, SQUELCH_PER_PEER * npeers), MAX_UNSQUELCH_EXPIRE_PEERS)

Parameters
npeersnumber of peers that can be squelched in the Slot

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

◆ resetCounts()

template<typename clock_type >
void ripple::reduce_relay::Slot< clock_type >::resetCounts
private

Reset counts of peers in Selected or Counting state.

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

◆ initCounting()

template<typename clock_type >
void ripple::reduce_relay::Slot< clock_type >::initCounting
private

Initialize slot to Counting state.

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

Friends And Related Function Documentation

◆ Slots< clock_type >

template<typename clock_type >
friend class Slots< clock_type >
friend

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

Member Data Documentation

◆ peers_

template<typename clock_type >
std::unordered_map<id_t, PeerInfo> ripple::reduce_relay::Slot< clock_type >::peers_
private

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

◆ considered_

template<typename clock_type >
std::unordered_set<id_t> ripple::reduce_relay::Slot< clock_type >::considered_
private

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

◆ reachedThreshold_

template<typename clock_type >
std::uint16_t ripple::reduce_relay::Slot< clock_type >::reachedThreshold_
private

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

◆ lastSelected_

template<typename clock_type >
clock_type::time_point ripple::reduce_relay::Slot< clock_type >::lastSelected_
private

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

◆ state_

template<typename clock_type >
SlotState ripple::reduce_relay::Slot< clock_type >::state_
private

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

◆ handler_

template<typename clock_type >
SquelchHandler const& ripple::reduce_relay::Slot< clock_type >::handler_
private

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

◆ journal_

template<typename clock_type >
const beast::Journal ripple::reduce_relay::Slot< clock_type >::journal_
private

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