mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
Create netDb directory structure
This commit is contained in:
parent
73ee4ff34c
commit
ee77bba5e0
69
NetDb.cpp
69
NetDb.cpp
@ -177,43 +177,75 @@ namespace data
|
|||||||
return it->second;
|
return it->second;
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
boost::filesystem::path p (directory);
|
||||||
|
LogPrint (directory, " doesn't exist, trying to create it.");
|
||||||
|
if (!boost::filesystem::create_directory (p))
|
||||||
|
{
|
||||||
|
LogPrint("Failed to create directory ", directory);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Random chars
|
||||||
|
std::string chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-~";
|
||||||
|
boost::filesystem::path suffix;
|
||||||
|
for (auto c : chars)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
suffix = "/r";
|
||||||
|
#else
|
||||||
|
suffix = "\\r";
|
||||||
|
#endif
|
||||||
|
suffix += c;
|
||||||
|
if (!boost::filesystem::create_directory( boost::filesystem::path (p / suffix) )) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void NetDb::Load (const char * directory)
|
void NetDb::Load (const char * directory)
|
||||||
{
|
{
|
||||||
boost::filesystem::path p (directory);
|
boost::filesystem::path p (directory);
|
||||||
if (boost::filesystem::exists (p))
|
if (!boost::filesystem::exists (p))
|
||||||
{
|
{
|
||||||
int numRouters = 0;
|
if (!CreateNetDb(directory)) return;
|
||||||
boost::filesystem::directory_iterator end;
|
}
|
||||||
for (boost::filesystem::directory_iterator it (p); it != end; ++it)
|
// TODO: Reseed if needed.
|
||||||
|
int numRouters = 0;
|
||||||
|
boost::filesystem::directory_iterator end;
|
||||||
|
for (boost::filesystem::directory_iterator it (p); it != end; ++it)
|
||||||
|
{
|
||||||
|
if (boost::filesystem::is_directory (it->status()))
|
||||||
{
|
{
|
||||||
if (boost::filesystem::is_directory (it->status()))
|
for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1)
|
||||||
{
|
{
|
||||||
for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1)
|
|
||||||
{
|
|
||||||
#if BOOST_VERSION > 10500
|
#if BOOST_VERSION > 10500
|
||||||
RouterInfo * r = new RouterInfo (it1->path().string().c_str ());
|
RouterInfo * r = new RouterInfo (it1->path().string().c_str ());
|
||||||
#else
|
#else
|
||||||
RouterInfo * r = new RouterInfo(it1->path().c_str());
|
RouterInfo * r = new RouterInfo(it1->path().c_str());
|
||||||
#endif
|
#endif
|
||||||
m_RouterInfos[r->GetIdentHash ()] = r;
|
m_RouterInfos[r->GetIdentHash ()] = r;
|
||||||
numRouters++;
|
numRouters++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogPrint (numRouters, " routers loaded");
|
|
||||||
}
|
}
|
||||||
else
|
LogPrint (numRouters, " routers loaded");
|
||||||
LogPrint (directory, " doesn't exist");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::SaveUpdated (const char * directory)
|
void NetDb::SaveUpdated (const char * directory)
|
||||||
{
|
{
|
||||||
auto GetFilePath = [](const char * directory, const RouterInfo * routerInfo)
|
auto GetFilePath = [](const char * directory, const RouterInfo * routerInfo)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
return std::string (directory) + "/r" +
|
return std::string (directory) + "/r" +
|
||||||
routerInfo->GetIdentHashBase64 ()[0] + "/routerInfo-" +
|
routerInfo->GetIdentHashBase64 ()[0] + "/routerInfo-" +
|
||||||
|
#else
|
||||||
|
return std::string (directory) + "\\r" +
|
||||||
|
routerInfo->GetIdentHashBase64 ()[0] + "\\routerInfo-" +
|
||||||
|
#endif
|
||||||
routerInfo->GetIdentHashBase64 () + ".dat";
|
routerInfo->GetIdentHashBase64 () + ".dat";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -570,6 +602,9 @@ namespace data
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Move to reseed.
|
||||||
|
//TODO: Implement v1 & v2 reseeding. Lightweight zip library is needed for v2.
|
||||||
|
//TODO: Implement SU3, utils.
|
||||||
void NetDb::DownloadRouterInfo (const std::string& address, const std::string& filename)
|
void NetDb::DownloadRouterInfo (const std::string& address, const std::string& filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
1
NetDb.h
1
NetDb.h
@ -76,6 +76,7 @@ namespace data
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool CreateNetDb(const char * directory);
|
||||||
void Load (const char * directory);
|
void Load (const char * directory);
|
||||||
void SaveUpdated (const char * directory);
|
void SaveUpdated (const char * directory);
|
||||||
void DownloadRouterInfo (const std::string& address, const std::string& filename); // for reseed
|
void DownloadRouterInfo (const std::string& address, const std::string& filename); // for reseed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user