1 /* 2 * Copyright (c) 2013-2020, The PurpleI2P Project 3 * 4 * This file is part of Purple i2pd project and licensed under BSD3 5 * 6 * See full license text in LICENSE file at top of project tree 7 */ 8 9 #ifndef PROFILING_H__ 10 #define PROFILING_H__ 11 12 #include <memory> 13 #include <boost/date_time/posix_time/posix_time.hpp> 14 #include "Identity.h" 15 16 namespace i2p 17 { 18 namespace data 19 { 20 // sections 21 const char PEER_PROFILE_SECTION_PARTICIPATION[] = "participation"; 22 const char PEER_PROFILE_SECTION_USAGE[] = "usage"; 23 // params 24 const char PEER_PROFILE_LAST_UPDATE_TIME[] = "lastupdatetime"; 25 const char PEER_PROFILE_PARTICIPATION_AGREED[] = "agreed"; 26 const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined"; 27 const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied"; 28 const char PEER_PROFILE_USAGE_TAKEN[] = "taken"; 29 const char PEER_PROFILE_USAGE_REJECTED[] = "rejected"; 30 31 const int PEER_PROFILE_EXPIRATION_TIMEOUT = 72; // in hours (3 days) 32 33 class RouterProfile 34 { 35 public: 36 37 RouterProfile (); 38 RouterProfile& operator= (const RouterProfile& ) = default; 39 40 void Save (const IdentHash& identHash); 41 void Load (const IdentHash& identHash); 42 43 bool IsBad (); 44 45 void TunnelBuildResponse (uint8_t ret); 46 void TunnelNonReplied (); 47 48 private: 49 50 boost::posix_time::ptime GetTime () const; 51 void UpdateTime (); 52 IsAlwaysDeclining()53 bool IsAlwaysDeclining () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; }; 54 bool IsLowPartcipationRate () const; 55 bool IsLowReplyRate () const; 56 57 private: 58 59 boost::posix_time::ptime m_LastUpdateTime; 60 // participation 61 uint32_t m_NumTunnelsAgreed; 62 uint32_t m_NumTunnelsDeclined; 63 uint32_t m_NumTunnelsNonReplied; 64 // usage 65 uint32_t m_NumTimesTaken; 66 uint32_t m_NumTimesRejected; 67 }; 68 69 std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash); 70 void InitProfilesStorage (); 71 void DeleteObsoleteProfiles (); 72 } 73 } 74 75 #endif 76