diff --git a/FS.cpp b/FS.cpp index ac3d0935..9416d6b4 100644 --- a/FS.cpp +++ b/FS.cpp @@ -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 diff --git a/FS.h b/FS.h index a3f071e5..833258b9 100644 --- a/FS.h +++ b/FS.h @@ -136,9 +136,6 @@ namespace fs { return s.str(); } - - /* accessors */ - HashedStorage & GetPeerProfiles(); } // fs } // i2p diff --git a/NetDb.cpp b/NetDb.cpp index 1678850b..6401fcc8 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -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 diff --git a/Profiling.cpp b/Profiling.cpp index d868298f..be675502 100644 --- a/Profiling.cpp +++ b/Profiling.cpp @@ -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 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); diff --git a/Profiling.h b/Profiling.h index 3a65714d..26d5c2f7 100644 --- a/Profiling.h +++ b/Profiling.h @@ -60,6 +60,7 @@ namespace data }; std::shared_ptr GetRouterProfile (const IdentHash& identHash); + void InitProfilesStorage (); void DeleteObsoleteProfiles (); } }