Browse Source

Merge pull request #15 from meeh420/master

NetDb update
pull/16/head
orignal 11 years ago
parent
commit
f69fbee6a5
  1. 7
      .gitignore
  2. 43
      NetDb.cpp
  3. 1
      NetDb.h

7
.gitignore vendored

@ -1,3 +1,10 @@ @@ -1,3 +1,10 @@
# i2pd
*.o
router.info
router.keys
i2p
netDb
#################
## Eclipse
#################

43
NetDb.cpp

@ -179,11 +179,41 @@ namespace data @@ -179,11 +179,41 @@ namespace data
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)
{
boost::filesystem::path p (directory);
if (boost::filesystem::exists (p))
if (!boost::filesystem::exists (p))
{
if (!CreateNetDb(directory)) return;
}
// TODO: Reseed if needed.
int numRouters = 0;
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator it (p); it != end; ++it)
@ -204,16 +234,18 @@ namespace data @@ -204,16 +234,18 @@ namespace data
}
LogPrint (numRouters, " routers loaded");
}
else
LogPrint (directory, " doesn't exist");
}
void NetDb::SaveUpdated (const char * directory)
{
auto GetFilePath = [](const char * directory, const RouterInfo * routerInfo)
{
#ifndef _WIN32
return std::string (directory) + "/r" +
routerInfo->GetIdentHashBase64 ()[0] + "/routerInfo-" +
#else
return std::string (directory) + "\\r" +
routerInfo->GetIdentHashBase64 ()[0] + "\\routerInfo-" +
#endif
routerInfo->GetIdentHashBase64 () + ".dat";
};
@ -570,6 +602,9 @@ namespace data @@ -570,6 +602,9 @@ namespace data
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)
{
try

1
NetDb.h

@ -76,6 +76,7 @@ namespace data @@ -76,6 +76,7 @@ namespace data
private:
bool CreateNetDb(const char * directory);
void Load (const char * directory);
void SaveUpdated (const char * directory);
void DownloadRouterInfo (const std::string& address, const std::string& filename); // for reseed

Loading…
Cancel
Save