mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
* NetDb : move storage from FS.cpp to NetDb.cpp
This commit is contained in:
parent
d3746e0119
commit
b69fbdda9a
4
FS.cpp
4
FS.cpp
|
@ -22,7 +22,6 @@ namespace fs {
|
||||||
#else
|
#else
|
||||||
std::string dirSep = "/";
|
std::string dirSep = "/";
|
||||||
#endif
|
#endif
|
||||||
HashedStorage NetDB("netDb", "r", "routerInfo-", "dat");
|
|
||||||
HashedStorage Peers("peerProfiles", "p", "profile-", "txt");
|
HashedStorage Peers("peerProfiles", "p", "profile-", "txt");
|
||||||
|
|
||||||
const std::string & GetAppName () {
|
const std::string & GetAppName () {
|
||||||
|
@ -72,8 +71,6 @@ namespace fs {
|
||||||
if (boost::filesystem::exists(destinations))
|
if (boost::filesystem::exists(destinations))
|
||||||
boost::filesystem::create_directory(destinations);
|
boost::filesystem::create_directory(destinations);
|
||||||
|
|
||||||
NetDB.SetPlace(dataDir);
|
|
||||||
NetDB.Init(i2p::data::GetBase64SubstitutionTable(), 64);
|
|
||||||
Peers.SetPlace(dataDir);
|
Peers.SetPlace(dataDir);
|
||||||
Peers.Init(i2p::data::GetBase64SubstitutionTable(), 64);
|
Peers.Init(i2p::data::GetBase64SubstitutionTable(), 64);
|
||||||
return true;
|
return true;
|
||||||
|
@ -157,7 +154,6 @@ namespace fs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HashedStorage & GetNetDB() { return NetDB; }
|
|
||||||
HashedStorage & GetPeerProfiles() { return Peers; }
|
HashedStorage & GetPeerProfiles() { return Peers; }
|
||||||
} // fs
|
} // fs
|
||||||
} // i2p
|
} // i2p
|
||||||
|
|
1
FS.h
1
FS.h
|
@ -138,7 +138,6 @@ namespace fs {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* accessors */
|
/* accessors */
|
||||||
HashedStorage & GetNetDB();
|
|
||||||
HashedStorage & GetPeerProfiles();
|
HashedStorage & GetPeerProfiles();
|
||||||
} // fs
|
} // fs
|
||||||
} // i2p
|
} // i2p
|
||||||
|
|
11
NetDb.cpp
11
NetDb.cpp
|
@ -7,7 +7,6 @@
|
||||||
#include "I2PEndian.h"
|
#include "I2PEndian.h"
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "FS.h"
|
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
|
@ -25,7 +24,7 @@ namespace data
|
||||||
{
|
{
|
||||||
NetDb netdb;
|
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 ()
|
void NetDb::Start ()
|
||||||
{
|
{
|
||||||
|
m_Storage.SetPlace(i2p::fs::GetDataDir());
|
||||||
|
m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64);
|
||||||
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
|
||||||
|
@ -313,7 +314,7 @@ namespace data
|
||||||
|
|
||||||
m_LastLoad = i2p::util::GetSecondsSinceEpoch();
|
m_LastLoad = i2p::util::GetSecondsSinceEpoch();
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
i2p::fs::GetNetDB().Traverse(files);
|
m_Storage.Traverse(files);
|
||||||
for (auto path : files)
|
for (auto path : files)
|
||||||
LoadRouterInfo(path);
|
LoadRouterInfo(path);
|
||||||
|
|
||||||
|
@ -329,7 +330,7 @@ namespace data
|
||||||
for (auto it: m_RouterInfos)
|
for (auto it: m_RouterInfos)
|
||||||
{
|
{
|
||||||
std::string ident = it.second->GetIdentHashBase64();
|
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 ()) {
|
if (it.second->IsUpdated ()) {
|
||||||
it.second->SaveToFile (path);
|
it.second->SaveToFile (path);
|
||||||
it.second->SetUpdated (false);
|
it.second->SetUpdated (false);
|
||||||
|
@ -376,7 +377,7 @@ namespace data
|
||||||
if (it.second->IsUnreachable ()) {
|
if (it.second->IsUnreachable ()) {
|
||||||
total--;
|
total--;
|
||||||
// delete RI file
|
// delete RI file
|
||||||
i2p::fs::GetNetDB().Remove(ident);
|
m_Storage.Remove(ident);
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
// delete from floodfills list
|
// delete from floodfills list
|
||||||
if (it.second->IsFloodfill ()) {
|
if (it.second->IsFloodfill ()) {
|
||||||
|
|
4
NetDb.h
4
NetDb.h
|
@ -9,6 +9,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
#include "FS.h"
|
||||||
#include "Queue.h"
|
#include "Queue.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
@ -97,11 +98,10 @@ namespace data
|
||||||
GzipInflator m_Inflator;
|
GzipInflator m_Inflator;
|
||||||
Reseeder * m_Reseeder;
|
Reseeder * m_Reseeder;
|
||||||
Families m_Families;
|
Families m_Families;
|
||||||
|
i2p::fs::HashedStorage m_Storage;
|
||||||
|
|
||||||
friend class NetDbRequests;
|
friend class NetDbRequests;
|
||||||
NetDbRequests m_Requests;
|
NetDbRequests m_Requests;
|
||||||
|
|
||||||
static const char m_NetDbPath[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NetDb netdb;
|
extern NetDb netdb;
|
||||||
|
|
Loading…
Reference in a new issue