Profiling.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef PROFILING_H__
  2. #define PROFILING_H__
  3. #include <memory>
  4. #include <boost/date_time/posix_time/posix_time.hpp>
  5. #include "Identity.h"
  6. namespace i2p
  7. {
  8. namespace data
  9. {
  10. // sections
  11. const char PEER_PROFILE_SECTION_PARTICIPATION[] = "participation";
  12. const char PEER_PROFILE_SECTION_USAGE[] = "usage";
  13. // params
  14. const char PEER_PROFILE_LAST_UPDATE_TIME[] = "lastupdatetime";
  15. const char PEER_PROFILE_PARTICIPATION_AGREED[] = "agreed";
  16. const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined";
  17. const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied";
  18. const char PEER_PROFILE_USAGE_TAKEN[] = "taken";
  19. const char PEER_PROFILE_USAGE_REJECTED[] = "rejected";
  20. const int PEER_PROFILE_EXPIRATION_TIMEOUT = 72; // in hours (3 days)
  21. class RouterProfile
  22. {
  23. public:
  24. RouterProfile ();
  25. RouterProfile& operator= (const RouterProfile& ) = default;
  26. void Save (const IdentHash& identHash);
  27. void Load (const IdentHash& identHash);
  28. bool IsBad ();
  29. void TunnelBuildResponse (uint8_t ret);
  30. void TunnelNonReplied ();
  31. private:
  32. boost::posix_time::ptime GetTime () const;
  33. void UpdateTime ();
  34. bool IsAlwaysDeclining () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; };
  35. bool IsLowPartcipationRate () const;
  36. bool IsLowReplyRate () const;
  37. private:
  38. boost::posix_time::ptime m_LastUpdateTime;
  39. // participation
  40. uint32_t m_NumTunnelsAgreed;
  41. uint32_t m_NumTunnelsDeclined;
  42. uint32_t m_NumTunnelsNonReplied;
  43. // usage
  44. uint32_t m_NumTimesTaken;
  45. uint32_t m_NumTimesRejected;
  46. };
  47. std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
  48. void InitProfilesStorage ();
  49. void DeleteObsoleteProfiles ();
  50. }
  51. }
  52. #endif