From 560ebcec8d51a193eedec8000a19c4aaf98e0ab0 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 1 Mar 2019 14:42:20 -0500 Subject: [PATCH] persist.addressbook parameter added --- libi2pd/Config.cpp | 1 + libi2pd_client/AddressBook.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index 89531f5a..22b08e10 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -256,6 +256,7 @@ namespace config { options_description persist("Network information persisting options"); persist.add_options() ("persist.profiles", value()->default_value(true), "Persist peer profiles (default: true)") + ("persist.addressbook", value()->default_value(true), "Persist full addreses (default: true)") ; m_OptionsDesc diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index 30ae7172..3f3ef972 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -30,7 +30,10 @@ namespace client std::string etagsPath, indexPath, localPath; public: - AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32") {}; + AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32") + { + i2p::config::GetOption("persist.addressbook", m_IsPersist); + } std::shared_ptr GetAddress (const i2p::data::IdentHash& ident) const; void AddAddress (std::shared_ptr address); void RemoveAddress (const i2p::data::IdentHash& ident); @@ -47,6 +50,9 @@ namespace client int LoadFromFile (const std::string& filename, std::map& addresses); // returns -1 if can't open file, otherwise number of records + private: + + bool m_IsPersist; }; bool AddressBookFilesystemStorage::Init() @@ -69,6 +75,11 @@ namespace client std::shared_ptr AddressBookFilesystemStorage::GetAddress (const i2p::data::IdentHash& ident) const { + if (!m_IsPersist) + { + LogPrint(eLogDebug, "Addressbook: Persistance is disabled"); + return nullptr; + } std::string filename = storage.Path(ident.ToBase32()); std::ifstream f(filename, std::ifstream::binary); if (!f.is_open ()) { @@ -92,6 +103,7 @@ namespace client void AddressBookFilesystemStorage::AddAddress (std::shared_ptr address) { + if (!m_IsPersist) return; std::string path = storage.Path( address->GetIdentHash().ToBase32() ); std::ofstream f (path, std::ofstream::binary | std::ofstream::out); if (!f.is_open ()) { @@ -107,6 +119,7 @@ namespace client void AddressBookFilesystemStorage::RemoveAddress (const i2p::data::IdentHash& ident) { + if (!m_IsPersist) return; storage.Remove( ident.ToBase32() ); }