Adding an option to choose storage engine

This commit is contained in:
hakunamtu 2018-03-05 16:04:02 +03:00
parent ef4e11f00a
commit 8a8ea9d5d4
3 changed files with 20 additions and 2 deletions

View file

@ -231,6 +231,11 @@ namespace config {
("exploratory.outbound.quantity", value<int>()->default_value(3), "Exploratory outbound tunnels quantity") ("exploratory.outbound.quantity", value<int>()->default_value(3), "Exploratory outbound tunnels quantity")
; ;
options_description storage("Persistent storage options for NetDb, profiles, etc.");
storage.add_options()
("storage.engine", value<std::string>()->default_value("fs"), "Storage engine")
;
m_OptionsDesc m_OptionsDesc
.add(general) .add(general)
.add(limits) .add(limits)
@ -248,6 +253,7 @@ namespace config {
.add(trust) .add(trust)
.add(websocket) .add(websocket)
.add(exploratory) .add(exploratory)
.add(storage)
; ;
} }

View file

@ -37,7 +37,13 @@ namespace data
void NetDb::Start () void NetDb::Start ()
{ {
m_Storage.reset(new FsIdentStorage("netDb", "r", "routerInfo-", "dat")); std::string engine;
i2p::config::GetOption("storage.engine", engine);
if (engine == "lmdb")
m_Storage.reset(new MdbIdentStorage("netDb.lmdb"));
else
m_Storage.reset(new FsIdentStorage("netDb", "r", "routerInfo-", "dat"));
m_Storage->Init(); m_Storage->Init();
InitProfilesStorage (); InitProfilesStorage ();
m_Families.LoadCertificates (); m_Families.LoadCertificates ();

View file

@ -2,6 +2,7 @@
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ini_parser.hpp>
#include "Base.h" #include "Base.h"
#include "Config.h"
#include "FS.h" #include "FS.h"
#include "Log.h" #include "Log.h"
#include "Profiling.h" #include "Profiling.h"
@ -173,7 +174,12 @@ namespace data
void InitProfilesStorage () void InitProfilesStorage ()
{ {
m_ProfilesStorage.reset(new FsIdentStorage("peerProfiles", "p", "profile-", "txt")); std::string engine;
i2p::config::GetOption("storage.engine", engine);
if (engine == "lmdb")
m_ProfilesStorage.reset(new MdbIdentStorage("peerProfiles.lmdb"));
else
m_ProfilesStorage.reset(new FsIdentStorage("peerProfiles", "p", "profile-", "txt"));
m_ProfilesStorage->Init(); m_ProfilesStorage->Init();
} }