mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-30 04:37:50 +02:00
* store peer profiles in single file
This commit is contained in:
parent
f2269b75f5
commit
20e3d7c8fa
3 changed files with 194 additions and 205 deletions
|
@ -16,19 +16,26 @@ namespace i2p
|
|||
{
|
||||
namespace data
|
||||
{
|
||||
// sections
|
||||
const char PEER_PROFILE_SECTION_PARTICIPATION[] = "participation";
|
||||
const char PEER_PROFILE_SECTION_USAGE[] = "usage";
|
||||
const char PEER_PROFILES_DB_FILENAME[] = "peerProfiles.dat";
|
||||
/** example json peer profile (pretty-printed):
|
||||
{
|
||||
"peerid": "<base64-ident>",
|
||||
"lasttime": { "update": 123456789, "decline": 123456789, "unreachable": 123456789 },
|
||||
"tunnels": { "agreed": 17. "declined": 4, "noreply: 2 },
|
||||
"usage": { "taken": 10, "rejected": 3 }
|
||||
} */
|
||||
// params
|
||||
const char PEER_PROFILE_LAST_UPDATE_TIME[] = "lastupdatetime";
|
||||
const char PEER_PROFILE_LAST_UNREACHABLE_TIME[] = "lastunreachabletime";
|
||||
const char PEER_PROFILE_PARTICIPATION_AGREED[] = "agreed";
|
||||
const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "declined";
|
||||
const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "nonreplied";
|
||||
const char PEER_PROFILE_USAGE_TAKEN[] = "taken";
|
||||
const char PEER_PROFILE_USAGE_REJECTED[] = "rejected";
|
||||
const char PEER_PROFILE_USAGE_CONNECTED[] = "connected";
|
||||
|
||||
const char PEER_PROFILE_PEER_ID[] = "peerid";
|
||||
const char PEER_PROFILE_LAST_UPDATE_TIME[] = "lasttime.update";
|
||||
const char PEER_PROFILE_LAST_DECLINE_TIME[] = "lasttime.decline";
|
||||
const char PEER_PROFILE_LAST_UNREACHABLE_TIME[] = "lasttime.unreachable";
|
||||
const char PEER_PROFILE_PARTICIPATION_AGREED[] = "tunnels.agreed";
|
||||
const char PEER_PROFILE_PARTICIPATION_DECLINED[] = "tunnels.declined";
|
||||
const char PEER_PROFILE_PARTICIPATION_NON_REPLIED[] = "tunnels.noreply";
|
||||
const char PEER_PROFILE_USAGE_TAKEN[] = "usage.taken";
|
||||
const char PEER_PROFILE_USAGE_REJECTED[] = "usage.rejected";
|
||||
const char PEER_PROFILE_USAGE_CONNECTED[] = "usage.connected";
|
||||
|
||||
const int PEER_PROFILE_EXPIRATION_TIMEOUT = 36; // in hours (1.5 days)
|
||||
const int PEER_PROFILE_AUTOCLEAN_TIMEOUT = 6 * 3600; // in seconds (6 hours)
|
||||
const int PEER_PROFILE_AUTOCLEAN_VARIANCE = 3600; // in seconds (1 hour)
|
||||
|
@ -44,11 +51,12 @@ namespace data
|
|||
RouterProfile ();
|
||||
RouterProfile& operator= (const RouterProfile& ) = default;
|
||||
|
||||
void Save (const IdentHash& identHash);
|
||||
void Load (const IdentHash& identHash);
|
||||
std::string Dump (const std::string& peerid);
|
||||
std::string Load (const std::string& jsondata);
|
||||
|
||||
bool IsBad ();
|
||||
bool IsUnreachable ();
|
||||
bool IsUseful() const;
|
||||
bool IsReal () const { return m_HasConnected || m_NumTunnelsAgreed > 0 || m_NumTunnelsDeclined > 0; }
|
||||
|
||||
void TunnelBuildResponse (uint8_t ret);
|
||||
|
@ -57,15 +65,10 @@ namespace data
|
|||
void Unreachable ();
|
||||
void Connected ();
|
||||
|
||||
boost::posix_time::ptime GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||||
bool IsUpdated () const { return m_IsUpdated; };
|
||||
|
||||
bool IsUseful() const;
|
||||
uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||||
|
||||
private:
|
||||
|
||||
void UpdateTime ();
|
||||
|
||||
bool IsAlwaysDeclining () const { return !m_NumTunnelsAgreed && m_NumTunnelsDeclined >= 5; };
|
||||
bool IsLowPartcipationRate () const;
|
||||
bool IsLowReplyRate () const;
|
||||
|
@ -73,9 +76,10 @@ namespace data
|
|||
|
||||
private:
|
||||
|
||||
boost::posix_time::ptime m_LastUpdateTime; // TODO: use std::chrono
|
||||
bool m_IsUpdated;
|
||||
uint64_t m_LastDeclineTime, m_LastUnreachableTime; // in seconds
|
||||
// lasttime
|
||||
uint64_t m_LastUpdateTime;
|
||||
uint64_t m_LastDeclineTime;
|
||||
uint64_t m_LastUnreachableTime;
|
||||
// participation
|
||||
uint32_t m_NumTunnelsAgreed;
|
||||
uint32_t m_NumTunnelsDeclined;
|
||||
|
@ -87,10 +91,14 @@ namespace data
|
|||
};
|
||||
|
||||
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
|
||||
void InitProfilesStorage ();
|
||||
void DeleteObsoleteProfiles ();
|
||||
void SaveProfiles ();
|
||||
void PersistProfiles ();
|
||||
|
||||
/** database file operations */
|
||||
void LoadProfilesDB (); /*< read saved peer profiles from file to memory */
|
||||
void SaveProfilesDB (); /*< serialize and write to file known peer profiles */
|
||||
|
||||
/** memory database operations */
|
||||
void PruneExpiredProfiles (); /*< discard peer profiles inactive for long time */
|
||||
void ClearProfilesDB (); /*< discard ALL known peer profiles */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue