From ca47d1552be8d8d03aeec530bdc197378a409819 Mon Sep 17 00:00:00 2001 From: Meeh Date: Tue, 28 Jan 2014 02:54:50 +0100 Subject: [PATCH 1/3] Updating gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index b9d6bd92..3c69f891 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# i2pd +*.o +router.info +router.keys + ################# ## Eclipse ################# From 73ee4ff34cd2057c804a98c6f809a18d725a99a3 Mon Sep 17 00:00:00 2001 From: Meeh Date: Wed, 29 Jan 2014 19:31:19 +0100 Subject: [PATCH 2/3] gitignore update --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3c69f891..2cb9ea10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ *.o router.info router.keys +i2p +netDb ################# ## Eclipse From ee77bba5e0631c187a958e17c4de288df4c4bbe7 Mon Sep 17 00:00:00 2001 From: Meeh Date: Wed, 29 Jan 2014 19:36:20 +0100 Subject: [PATCH 3/3] Create netDb directory structure --- NetDb.cpp | 69 +++++++++++++++++++++++++++++++++++++++++-------------- NetDb.h | 1 + 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 38814549..ee9a0a52 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -177,43 +177,75 @@ namespace data return it->second; else 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) { - 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 - RouterInfo * r = new RouterInfo (it1->path().string().c_str ()); + RouterInfo * r = new RouterInfo (it1->path().string().c_str ()); #else - RouterInfo * r = new RouterInfo(it1->path().c_str()); + RouterInfo * r = new RouterInfo(it1->path().c_str()); #endif - m_RouterInfos[r->GetIdentHash ()] = r; - numRouters++; - } + m_RouterInfos[r->GetIdentHash ()] = r; + numRouters++; } } - LogPrint (numRouters, " routers loaded"); } - else - LogPrint (directory, " doesn't exist"); + LogPrint (numRouters, " routers loaded"); } 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-" + + routerInfo->GetIdentHashBase64 ()[0] + "/routerInfo-" + +#else + return std::string (directory) + "\\r" + + routerInfo->GetIdentHashBase64 ()[0] + "\\routerInfo-" + +#endif routerInfo->GetIdentHashBase64 () + ".dat"; }; @@ -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 diff --git a/NetDb.h b/NetDb.h index 7baebc5d..1397e9e4 100644 --- a/NetDb.h +++ b/NetDb.h @@ -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