* Profiling : move storage from FS.cpp to Profiling.cpp

This commit is contained in:
hagen 2016-02-20 01:00:00 +00:00
parent b69fbdda9a
commit 0d15eceacb
5 changed files with 13 additions and 11 deletions

5
FS.cpp
View File

@ -22,7 +22,6 @@ namespace fs {
#else
std::string dirSep = "/";
#endif
HashedStorage Peers("peerProfiles", "p", "profile-", "txt");
const std::string & GetAppName () {
return appName;
@ -71,8 +70,6 @@ namespace fs {
if (boost::filesystem::exists(destinations))
boost::filesystem::create_directory(destinations);
Peers.SetPlace(dataDir);
Peers.Init(i2p::data::GetBase64SubstitutionTable(), 64);
return true;
}
@ -153,7 +150,5 @@ namespace fs {
files.push_back(t);
}
}
HashedStorage & GetPeerProfiles() { return Peers; }
} // fs
} // i2p

3
FS.h
View File

@ -136,9 +136,6 @@ namespace fs {
return s.str();
}
/* accessors */
HashedStorage & GetPeerProfiles();
} // fs
} // i2p

View File

@ -38,6 +38,7 @@ namespace data
{
m_Storage.SetPlace(i2p::fs::GetDataDir());
m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64);
InitProfilesStorage ();
m_Families.LoadCertificates ();
Load ();
if (m_RouterInfos.size () < 25) // reseed if # of router less than 50

View File

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

View File

@ -60,6 +60,7 @@ namespace data
};
std::shared_ptr<RouterProfile> GetRouterProfile (const IdentHash& identHash);
void InitProfilesStorage ();
void DeleteObsoleteProfiles ();
}
}