Browse Source

persist.addressbook parameter added

pull/1313/head
orignal 5 years ago
parent
commit
560ebcec8d
  1. 1
      libi2pd/Config.cpp
  2. 15
      libi2pd_client/AddressBook.cpp

1
libi2pd/Config.cpp

@ -256,6 +256,7 @@ namespace config {
options_description persist("Network information persisting options"); options_description persist("Network information persisting options");
persist.add_options() persist.add_options()
("persist.profiles", value<bool>()->default_value(true), "Persist peer profiles (default: true)") ("persist.profiles", value<bool>()->default_value(true), "Persist peer profiles (default: true)")
("persist.addressbook", value<bool>()->default_value(true), "Persist full addreses (default: true)")
; ;
m_OptionsDesc m_OptionsDesc

15
libi2pd_client/AddressBook.cpp

@ -30,7 +30,10 @@ namespace client
std::string etagsPath, indexPath, localPath; std::string etagsPath, indexPath, localPath;
public: public:
AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32") {}; AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32")
{
i2p::config::GetOption("persist.addressbook", m_IsPersist);
}
std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const; std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const;
void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address); void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
void RemoveAddress (const i2p::data::IdentHash& ident); void RemoveAddress (const i2p::data::IdentHash& ident);
@ -47,6 +50,9 @@ namespace client
int LoadFromFile (const std::string& filename, std::map<std::string, i2p::data::IdentHash>& addresses); // returns -1 if can't open file, otherwise number of records int LoadFromFile (const std::string& filename, std::map<std::string, i2p::data::IdentHash>& addresses); // returns -1 if can't open file, otherwise number of records
private:
bool m_IsPersist;
}; };
bool AddressBookFilesystemStorage::Init() bool AddressBookFilesystemStorage::Init()
@ -69,6 +75,11 @@ namespace client
std::shared_ptr<const i2p::data::IdentityEx> AddressBookFilesystemStorage::GetAddress (const i2p::data::IdentHash& ident) const std::shared_ptr<const i2p::data::IdentityEx> 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::string filename = storage.Path(ident.ToBase32());
std::ifstream f(filename, std::ifstream::binary); std::ifstream f(filename, std::ifstream::binary);
if (!f.is_open ()) { if (!f.is_open ()) {
@ -92,6 +103,7 @@ namespace client
void AddressBookFilesystemStorage::AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) void AddressBookFilesystemStorage::AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address)
{ {
if (!m_IsPersist) return;
std::string path = storage.Path( address->GetIdentHash().ToBase32() ); std::string path = storage.Path( address->GetIdentHash().ToBase32() );
std::ofstream f (path, std::ofstream::binary | std::ofstream::out); std::ofstream f (path, std::ofstream::binary | std::ofstream::out);
if (!f.is_open ()) { if (!f.is_open ()) {
@ -107,6 +119,7 @@ namespace client
void AddressBookFilesystemStorage::RemoveAddress (const i2p::data::IdentHash& ident) void AddressBookFilesystemStorage::RemoveAddress (const i2p::data::IdentHash& ident)
{ {
if (!m_IsPersist) return;
storage.Remove( ident.ToBase32() ); storage.Remove( ident.ToBase32() );
} }

Loading…
Cancel
Save