From 42c3c28ea7f65f178eae822b6a94524418066f4d Mon Sep 17 00:00:00 2001 From: r4sas Date: Mon, 4 Mar 2019 18:29:29 +0000 Subject: [PATCH] [addressbook] reset eTags if addressbook can't be loaded --- libi2pd_client/AddressBook.cpp | 16 ++++++++++++++++ libi2pd_client/AddressBook.h | 1 + 2 files changed, 17 insertions(+) diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index 3f3ef972..6dcf063e 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Base.h" #include "util.h" #include "Identity.h" @@ -45,6 +46,7 @@ namespace client void SaveEtag (const i2p::data::IdentHash& subsciption, const std::string& etag, const std::string& lastModified); bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified); + void ResetEtags (); private: @@ -218,6 +220,17 @@ namespace client return true; } + void AddressBookFilesystemStorage::ResetEtags () + { + LogPrint (eLogError, "Addressbook: resetting eTags"); + for (boost::filesystem::directory_iterator it (etagsPath); it != boost::filesystem::directory_iterator (); ++it) + { + if (!boost::filesystem::is_regular_file (it->status ())) + continue; + boost::filesystem::remove (it->path ()); + } + } + //--------------------------------------------------------------------- AddressBook::AddressBook (): m_Storage(nullptr), m_IsLoaded (false), m_IsDownloading (false), m_NumRetries (0), m_DefaultSubscription (nullptr), m_SubscriptionsUpdateTimer (nullptr) @@ -356,6 +369,9 @@ namespace client LoadHostsFromStream (f, false); m_IsLoaded = true; } + + // reset eTags, because we don’t know how old hosts.txt is or can't load addressbook + m_Storage->ResetEtags (); } bool AddressBook::LoadHostsFromStream (std::istream& f, bool is_update) diff --git a/libi2pd_client/AddressBook.h b/libi2pd_client/AddressBook.h index 19257eca..da640688 100644 --- a/libi2pd_client/AddressBook.h +++ b/libi2pd_client/AddressBook.h @@ -46,6 +46,7 @@ namespace client virtual void SaveEtag (const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified) = 0; virtual bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) = 0; + virtual void ResetEtags () = 0; }; class AddressBookSubscription;