Kagome
Polkadot Runtime Engine in C++17
kagome::network::detail::BlocksResponseCache Class Reference

#include <sync_protocol_impl.hpp>

Collaboration diagram for kagome::network::detail::BlocksResponseCache:

Classes

struct  CacheRecord
 

Public Member Functions

 BlocksResponseCache (std::size_t capacity, std::chrono::seconds expiration_time)
 
bool isDuplicate (const PeerId &peer_id, BlocksRequest::Fingerprint request_fingerprint)
 

Private Types

using ExpirationTimepoint = std::chrono::time_point< std::chrono::system_clock >
 
using CacheRecordIndex = std::size_t
 

Private Member Functions

void cache (const PeerId &peer_id, BlocksRequest::Fingerprint request_fingerprint, std::optional< CacheRecordIndex > target_slot=std::nullopt)
 
void purge ()
 removes all stale records More...
 

Private Attributes

const std::size_t capacity_
 
const std::chrono::seconds expiration_time_
 
std::unordered_map< PeerId, CacheRecordIndexlookup_table_
 
std::vector< std::optional< CacheRecord > > storage_
 
std::unordered_set< CacheRecordIndexfree_slots_
 

Detailed Description

Container to store the most recent block requests by peers we replied to with non empty responses.

Definition at line 40 of file sync_protocol_impl.hpp.


Class Documentation

struct kagome::network::detail::BlocksResponseCache::CacheRecord

Definition at line 85 of file sync_protocol_impl.hpp.

Collaboration diagram for kagome::network::detail::BlocksResponseCache::CacheRecord:
Class Members
circular_buffer< Fingerprint > fingerprints
PeerId peer_id
ExpirationTimepoint valid_till

Member Typedef Documentation

Definition at line 69 of file sync_protocol_impl.hpp.

using kagome::network::detail::BlocksResponseCache::ExpirationTimepoint = std::chrono::time_point<std::chrono::system_clock>
private

Definition at line 68 of file sync_protocol_impl.hpp.

Constructor & Destructor Documentation

kagome::network::detail::BlocksResponseCache::BlocksResponseCache ( std::size_t  capacity,
std::chrono::seconds  expiration_time 
)

Initialize the cache

Parameters
capacity- max amount of cache entries
expiration_time- cache entry expiry time in seconds

Definition at line 22 of file sync_protocol_impl.cpp.

Member Function Documentation

void kagome::network::detail::BlocksResponseCache::cache ( const PeerId peer_id,
BlocksRequest::Fingerprint  request_fingerprint,
std::optional< CacheRecordIndex target_slot = std::nullopt 
)
private

Save a record about peer's request to cache

Parameters
peer_id- peer identifier
request_fingerprint- request identifier
target_slot- (optional) a slot of internal storage to put a record into

Definition at line 67 of file sync_protocol_impl.cpp.

bool kagome::network::detail::BlocksResponseCache::isDuplicate ( const PeerId peer_id,
BlocksRequest::Fingerprint  request_fingerprint 
)

Checks whether specified request came from the peer more than once.

Some repeating request done past "expiration_time" seconds since last request from the peer would not be considered as duplicating request.

Parameters
peer_id- peer identifier
request_fingerprint- request identifier
Returns
true when the request is found in a list of last peers' requests of size kMaxCacheEntriesPerPeer and the last request took a place not later than "expiration_time" seconds. Otherwise - false.

Definition at line 35 of file sync_protocol_impl.cpp.

void kagome::network::detail::BlocksResponseCache::purge ( )
private

removes all stale records

Definition at line 103 of file sync_protocol_impl.cpp.

Member Data Documentation

const std::size_t kagome::network::detail::BlocksResponseCache::capacity_
private

Definition at line 92 of file sync_protocol_impl.hpp.

const std::chrono::seconds kagome::network::detail::BlocksResponseCache::expiration_time_
private

Definition at line 93 of file sync_protocol_impl.hpp.

std::unordered_set<CacheRecordIndex> kagome::network::detail::BlocksResponseCache::free_slots_
private

Definition at line 96 of file sync_protocol_impl.hpp.

std::unordered_map<PeerId, CacheRecordIndex> kagome::network::detail::BlocksResponseCache::lookup_table_
private

Definition at line 94 of file sync_protocol_impl.hpp.

std::vector<std::optional<CacheRecord> > kagome::network::detail::BlocksResponseCache::storage_
private

Definition at line 95 of file sync_protocol_impl.hpp.


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