Browse Source

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

pull/388/head
hagen 9 years ago
parent
commit
0d15eceacb
  1. 5
      FS.cpp
  2. 3
      FS.h
  3. 1
      NetDb.cpp
  4. 14
      Profiling.cpp
  5. 1
      Profiling.h

5
FS.cpp

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

3
FS.h

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

1
NetDb.cpp

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

14
Profiling.cpp

@ -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);

1
Profiling.h

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

Loading…
Cancel
Save