mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-13 01:20:22 +03:00
Load netDb from data directory
This commit is contained in:
parent
ca1e1c4896
commit
d87a79b226
29
NetDb.cpp
29
NetDb.cpp
@ -14,6 +14,7 @@
|
|||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Reseed.h"
|
#include "Reseed.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
@ -62,13 +63,21 @@ namespace data
|
|||||||
|
|
||||||
void NetDb::Start ()
|
void NetDb::Start ()
|
||||||
{
|
{
|
||||||
Load ("netDb");
|
#ifndef _WIN32
|
||||||
|
Load ("/netDb");
|
||||||
|
#else
|
||||||
|
Load ("\\netDb");
|
||||||
|
#endif
|
||||||
while (m_RouterInfos.size () < 100 && m_ReseedRetries < 10)
|
while (m_RouterInfos.size () < 100 && m_ReseedRetries < 10)
|
||||||
{
|
{
|
||||||
Reseeder reseeder;
|
Reseeder reseeder;
|
||||||
reseeder.reseedNow();
|
reseeder.reseedNow();
|
||||||
m_ReseedRetries++;
|
m_ReseedRetries++;
|
||||||
Load ("netDb");
|
#ifndef _WIN32
|
||||||
|
Load ("/netDb");
|
||||||
|
#else
|
||||||
|
Load ("\\netDb");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
m_Thread = new std::thread (std::bind (&NetDb::Run, this));
|
m_Thread = new std::thread (std::bind (&NetDb::Run, this));
|
||||||
}
|
}
|
||||||
@ -188,13 +197,12 @@ namespace data
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move to reseed and/or scheduled tasks. (In java version, scheduler fix this as well as sort RIs.)
|
// TODO: Move to reseed and/or scheduled tasks. (In java version, scheduler fix this as well as sort RIs.)
|
||||||
bool NetDb::CreateNetDb(const char * directory)
|
bool NetDb::CreateNetDb(boost::filesystem::path directory)
|
||||||
{
|
{
|
||||||
boost::filesystem::path p (directory);
|
LogPrint (directory.string(), " doesn't exist, trying to create it.");
|
||||||
LogPrint (directory, " doesn't exist, trying to create it.");
|
if (!boost::filesystem::create_directory (directory))
|
||||||
if (!boost::filesystem::create_directory (p))
|
|
||||||
{
|
{
|
||||||
LogPrint("Failed to create directory ", directory);
|
LogPrint("Failed to create directory ", directory.string());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,18 +216,19 @@ namespace data
|
|||||||
#else
|
#else
|
||||||
suffix = std::string ("\\r") + chars[i];
|
suffix = std::string ("\\r") + chars[i];
|
||||||
#endif
|
#endif
|
||||||
if (!boost::filesystem::create_directory( boost::filesystem::path (p / suffix) )) return false;
|
if (!boost::filesystem::create_directory( boost::filesystem::path (directory / suffix) )) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::Load (const char * directory)
|
void NetDb::Load (const char * directory)
|
||||||
{
|
{
|
||||||
boost::filesystem::path p (directory);
|
boost::filesystem::path p (i2p::util::filesystem::GetDataDir());
|
||||||
|
p /= (directory);
|
||||||
if (!boost::filesystem::exists (p))
|
if (!boost::filesystem::exists (p))
|
||||||
{
|
{
|
||||||
// seems netDb doesn't exist yet
|
// seems netDb doesn't exist yet
|
||||||
if (!CreateNetDb(directory)) return;
|
if (!CreateNetDb(p)) return;
|
||||||
}
|
}
|
||||||
// make sure we cleanup netDb from previous attempts
|
// make sure we cleanup netDb from previous attempts
|
||||||
for (auto r: m_RouterInfos)
|
for (auto r: m_RouterInfos)
|
||||||
|
2
NetDb.h
2
NetDb.h
@ -76,7 +76,7 @@ namespace data
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool CreateNetDb(const char * directory);
|
bool CreateNetDb(boost::filesystem::path directory);
|
||||||
void Load (const char * directory);
|
void Load (const char * directory);
|
||||||
void SaveUpdated (const char * directory);
|
void SaveUpdated (const char * directory);
|
||||||
void Run (); // exploratory thread
|
void Run (); // exploratory thread
|
||||||
|
Loading…
Reference in New Issue
Block a user