From 5c877de2c2f954c27471092fff73443a1c9af9d4 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 1 Apr 2016 12:51:34 -0400 Subject: [PATCH] check if hosts is incomplete --- AddressBook.cpp | 18 ++++++++++++------ AddressBook.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index ad2d0c32..766d8c95 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -343,10 +343,11 @@ namespace client } } - void AddressBook::LoadHostsFromStream (std::istream& f) + bool AddressBook::LoadHostsFromStream (std::istream& f) { std::unique_lock l(m_AddressBookMutex); int numAddresses = 0; + bool incomplete = false; std::string s; while (!f.eof ()) { @@ -370,15 +371,21 @@ namespace client numAddresses++; } else + { LogPrint (eLogError, "Addressbook: malformed address ", addr, " for ", name); - } + incomplete = f.eof (); + } + } + else + incomplete = f.eof (); } LogPrint (eLogInfo, "Addressbook: ", numAddresses, " addresses processed"); if (numAddresses > 0) { - m_IsLoaded = true; + if (!incomplete) m_IsLoaded = true; m_Storage->Save (m_Addresses); } + return !incomplete; } void AddressBook::LoadSubscriptions () @@ -776,13 +783,12 @@ namespace client i2p::data::GzipInflator inflator; inflator.Inflate (s, uncompressed); if (!uncompressed.fail ()) - m_Book.LoadHostsFromStream (uncompressed); + return m_Book.LoadHostsFromStream (uncompressed); else return false; } else - m_Book.LoadHostsFromStream (s); - return true; + return m_Book.LoadHostsFromStream (s); } AddressResolver::AddressResolver (std::shared_ptr destination): diff --git a/AddressBook.h b/AddressBook.h index 56f8145c..61b82f4b 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -66,7 +66,7 @@ namespace client void InsertAddress (const std::string& address, const std::string& base64); // for jump service void InsertAddress (std::shared_ptr address); - void LoadHostsFromStream (std::istream& f); + bool LoadHostsFromStream (std::istream& f); void DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified); //This method returns the ".b32.i2p" address std::string ToAddress(const i2p::data::IdentHash& ident) { return GetB32Address(ident); }