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

This commit is contained in:
hagen 2016-02-20 01:00:00 +00:00
parent d3746e0119
commit b69fbdda9a
4 changed files with 8 additions and 12 deletions

4
FS.cpp
View File

@ -22,7 +22,6 @@ namespace fs {
#else
std::string dirSep = "/";
#endif
HashedStorage NetDB("netDb", "r", "routerInfo-", "dat");
HashedStorage Peers("peerProfiles", "p", "profile-", "txt");
const std::string & GetAppName () {
@ -72,8 +71,6 @@ namespace fs {
if (boost::filesystem::exists(destinations))
boost::filesystem::create_directory(destinations);
NetDB.SetPlace(dataDir);
NetDB.Init(i2p::data::GetBase64SubstitutionTable(), 64);
Peers.SetPlace(dataDir);
Peers.Init(i2p::data::GetBase64SubstitutionTable(), 64);
return true;
@ -157,7 +154,6 @@ namespace fs {
}
}
HashedStorage & GetNetDB() { return NetDB; }
HashedStorage & GetPeerProfiles() { return Peers; }
} // fs
} // i2p

1
FS.h
View File

@ -138,7 +138,6 @@ namespace fs {
}
/* accessors */
HashedStorage & GetNetDB();
HashedStorage & GetPeerProfiles();
} // fs
} // i2p

View File

@ -7,7 +7,6 @@
#include "I2PEndian.h"
#include "Base.h"
#include "Log.h"
#include "FS.h"
#include "Timestamp.h"
#include "I2NPProtocol.h"
#include "Tunnel.h"
@ -25,7 +24,7 @@ namespace data
{
NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr)
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat")
{
}
@ -37,6 +36,8 @@ namespace data
void NetDb::Start ()
{
m_Storage.SetPlace(i2p::fs::GetDataDir());
m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64);
m_Families.LoadCertificates ();
Load ();
if (m_RouterInfos.size () < 25) // reseed if # of router less than 50
@ -313,7 +314,7 @@ namespace data
m_LastLoad = i2p::util::GetSecondsSinceEpoch();
std::vector<std::string> files;
i2p::fs::GetNetDB().Traverse(files);
m_Storage.Traverse(files);
for (auto path : files)
LoadRouterInfo(path);
@ -329,7 +330,7 @@ namespace data
for (auto it: m_RouterInfos)
{
std::string ident = it.second->GetIdentHashBase64();
std::string path = i2p::fs::GetNetDB().Path(ident);
std::string path = m_Storage.Path(ident);
if (it.second->IsUpdated ()) {
it.second->SaveToFile (path);
it.second->SetUpdated (false);
@ -376,7 +377,7 @@ namespace data
if (it.second->IsUnreachable ()) {
total--;
// delete RI file
i2p::fs::GetNetDB().Remove(ident);
m_Storage.Remove(ident);
deletedCount++;
// delete from floodfills list
if (it.second->IsFloodfill ()) {

View File

@ -9,6 +9,7 @@
#include <thread>
#include <mutex>
#include "Base.h"
#include "FS.h"
#include "Queue.h"
#include "I2NPProtocol.h"
#include "RouterInfo.h"
@ -97,11 +98,10 @@ namespace data
GzipInflator m_Inflator;
Reseeder * m_Reseeder;
Families m_Families;
i2p::fs::HashedStorage m_Storage;
friend class NetDbRequests;
NetDbRequests m_Requests;
static const char m_NetDbPath[];
};
extern NetDb netdb;