From b69fbdda9a6f8dc0891a6505789279342f917359 Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 20 Feb 2016 01:00:00 +0000 Subject: [PATCH] * NetDb : move storage from FS.cpp to NetDb.cpp --- FS.cpp | 4 ---- FS.h | 1 - NetDb.cpp | 11 ++++++----- NetDb.h | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/FS.cpp b/FS.cpp index f6125954..ac3d0935 100644 --- a/FS.cpp +++ b/FS.cpp @@ -22,7 +22,6 @@ namespace fs { #else std::string dirSep = "/"; #endif - HashedStorage NetDB("netDb", "r", "routerInfo-", "dat"); HashedStorage Peers("peerProfiles", "p", "profile-", "txt"); const std::string & GetAppName () { @@ -72,8 +71,6 @@ namespace fs { if (boost::filesystem::exists(destinations)) boost::filesystem::create_directory(destinations); - NetDB.SetPlace(dataDir); - NetDB.Init(i2p::data::GetBase64SubstitutionTable(), 64); Peers.SetPlace(dataDir); Peers.Init(i2p::data::GetBase64SubstitutionTable(), 64); return true; @@ -157,7 +154,6 @@ namespace fs { } } - HashedStorage & GetNetDB() { return NetDB; } HashedStorage & GetPeerProfiles() { return Peers; } } // fs } // i2p diff --git a/FS.h b/FS.h index f80840bc..a3f071e5 100644 --- a/FS.h +++ b/FS.h @@ -138,7 +138,6 @@ namespace fs { } /* accessors */ - HashedStorage & GetNetDB(); HashedStorage & GetPeerProfiles(); } // fs } // i2p diff --git a/NetDb.cpp b/NetDb.cpp index 428f1c36..1678850b 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -7,7 +7,6 @@ #include "I2PEndian.h" #include "Base.h" #include "Log.h" -#include "FS.h" #include "Timestamp.h" #include "I2NPProtocol.h" #include "Tunnel.h" @@ -25,7 +24,7 @@ namespace data { 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 () { + m_Storage.SetPlace(i2p::fs::GetDataDir()); + m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64); m_Families.LoadCertificates (); Load (); if (m_RouterInfos.size () < 25) // reseed if # of router less than 50 @@ -313,7 +314,7 @@ namespace data m_LastLoad = i2p::util::GetSecondsSinceEpoch(); std::vector files; - i2p::fs::GetNetDB().Traverse(files); + m_Storage.Traverse(files); for (auto path : files) LoadRouterInfo(path); @@ -329,7 +330,7 @@ namespace data for (auto it: m_RouterInfos) { 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 ()) { it.second->SaveToFile (path); it.second->SetUpdated (false); @@ -376,7 +377,7 @@ namespace data if (it.second->IsUnreachable ()) { total--; // delete RI file - i2p::fs::GetNetDB().Remove(ident); + m_Storage.Remove(ident); deletedCount++; // delete from floodfills list if (it.second->IsFloodfill ()) { diff --git a/NetDb.h b/NetDb.h index 0c59ff0f..7efbfcf2 100644 --- a/NetDb.h +++ b/NetDb.h @@ -9,6 +9,7 @@ #include #include #include "Base.h" +#include "FS.h" #include "Queue.h" #include "I2NPProtocol.h" #include "RouterInfo.h" @@ -97,11 +98,10 @@ namespace data GzipInflator m_Inflator; Reseeder * m_Reseeder; Families m_Families; + i2p::fs::HashedStorage m_Storage; friend class NetDbRequests; NetDbRequests m_Requests; - - static const char m_NetDbPath[]; }; extern NetDb netdb;