Kagome
Polkadot Runtime Engine in C++17
reputation_repository_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_NETWORK_REPUTATIONREPOSITORYIMPL
7 #define KAGOME_NETWORK_REPUTATIONREPOSITORYIMPL
8 
10 
11 #include <memory>
12 #include <unordered_map>
13 
14 #include <libp2p/basic/scheduler.hpp>
15 
16 #include "log/logger.hpp"
17 
18 namespace kagome::network {
19 
21  : public ReputationRepository,
22  public std::enable_shared_from_this<ReputationRepositoryImpl> {
23  public:
25  std::shared_ptr<libp2p::basic::Scheduler> scheduler);
26 
27  Reputation reputation(const PeerId &peer_id) const override;
28 
29  Reputation change(const PeerId &peer_id, ReputationChange diff) override;
30 
31  Reputation changeForATime(const PeerId &peer_id,
32  ReputationChange diff,
33  std::chrono::seconds duration) override;
34 
35  private:
36  void tick();
37 
38  std::shared_ptr<libp2p::basic::Scheduler> scheduler_;
39  std::unordered_map<PeerId, Reputation> reputation_table_;
40 
41  libp2p::basic::Scheduler::Handle tick_handler_;
42 
44  };
45 
46 } // namespace kagome::network
47 
48 #endif // KAGOME_NETWORK_REPUTATIONREPOSITORYIMPL
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
Reputation reputation(const PeerId &peer_id) const override
Current peer reputation.
libp2p::peer::PeerId PeerId
Reputation changeForATime(const PeerId &peer_id, ReputationChange diff, std::chrono::seconds duration) override
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
std::int32_t Reputation
Reputation change(const PeerId &peer_id, ReputationChange diff) override
std::unordered_map< PeerId, Reputation > reputation_table_
ReputationRepositoryImpl(std::shared_ptr< libp2p::basic::Scheduler > scheduler)