|
|
@ -10,6 +10,8 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace data |
|
|
|
namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
i2p::fs::HashedStorage m_ProfilesStorage("peerProfiles", "p", "profile-", "txt"); |
|
|
|
|
|
|
|
|
|
|
|
RouterProfile::RouterProfile (const IdentHash& identHash): |
|
|
|
RouterProfile::RouterProfile (const IdentHash& identHash): |
|
|
|
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()), |
|
|
|
m_IdentHash (identHash), m_LastUpdateTime (boost::posix_time::second_clock::local_time()), |
|
|
|
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0), |
|
|
|
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0), |
|
|
@ -45,7 +47,7 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
// save to file
|
|
|
|
// save to file
|
|
|
|
std::string ident = m_IdentHash.ToBase64 (); |
|
|
|
std::string ident = m_IdentHash.ToBase64 (); |
|
|
|
std::string path = i2p::fs::GetPeerProfiles().Path(ident); |
|
|
|
std::string path = m_ProfilesStorage.Path(ident); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
boost::property_tree::write_ini (path, pt); |
|
|
|
boost::property_tree::write_ini (path, pt); |
|
|
@ -58,7 +60,7 @@ namespace data |
|
|
|
void RouterProfile::Load () |
|
|
|
void RouterProfile::Load () |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string ident = m_IdentHash.ToBase64 (); |
|
|
|
std::string ident = m_IdentHash.ToBase64 (); |
|
|
|
std::string path = i2p::fs::GetPeerProfiles().Path(ident); |
|
|
|
std::string path = m_ProfilesStorage.Path(ident); |
|
|
|
boost::property_tree::ptree pt; |
|
|
|
boost::property_tree::ptree pt; |
|
|
|
|
|
|
|
|
|
|
|
if (!i2p::fs::Exists(path)) { |
|
|
|
if (!i2p::fs::Exists(path)) { |
|
|
@ -152,13 +154,19 @@ namespace data |
|
|
|
return profile; |
|
|
|
return profile; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitProfilesStorage () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_ProfilesStorage.SetPlace(i2p::fs::GetDataDir()); |
|
|
|
|
|
|
|
m_ProfilesStorage.Init(i2p::data::GetBase64SubstitutionTable(), 64); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DeleteObsoleteProfiles () |
|
|
|
void DeleteObsoleteProfiles () |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct stat st; |
|
|
|
struct stat st; |
|
|
|
std::time_t now = std::time(nullptr); |
|
|
|
std::time_t now = std::time(nullptr); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> files; |
|
|
|
std::vector<std::string> files; |
|
|
|
i2p::fs::GetPeerProfiles().Traverse(files); |
|
|
|
m_ProfilesStorage.Traverse(files); |
|
|
|
for (auto path: files) { |
|
|
|
for (auto path: files) { |
|
|
|
if (stat(path.c_str(), &st) != 0) { |
|
|
|
if (stat(path.c_str(), &st) != 0) { |
|
|
|
LogPrint(eLogWarning, "Profiling: Can't stat(): ", path); |
|
|
|
LogPrint(eLogWarning, "Profiling: Can't stat(): ", path); |
|
|
|