|
|
@ -252,11 +252,11 @@ namespace client |
|
|
|
f_save.close(); |
|
|
|
f_save.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint("Can't write hosts.txt"); |
|
|
|
LogPrint (eLogError, "Can't write hosts.txt"); |
|
|
|
m_IsLoaded = false; |
|
|
|
m_IsLoaded = false; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint ("Failed to download hosts.txt"); |
|
|
|
LogPrint (eLogError, "Failed to download hosts.txt"); |
|
|
|
m_IsDowloading = false; |
|
|
|
m_IsDowloading = false; |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
@ -266,8 +266,7 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_Storage) |
|
|
|
if (!m_Storage) |
|
|
|
m_Storage = CreateStorage (); |
|
|
|
m_Storage = CreateStorage (); |
|
|
|
int numAddresses = m_Storage->Load (m_Addresses); |
|
|
|
if (m_Storage->Load (m_Addresses) > 0) |
|
|
|
if (numAddresses > 0) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsLoaded = true; |
|
|
|
m_IsLoaded = true; |
|
|
|
return; |
|
|
|
return; |
|
|
@ -277,7 +276,7 @@ namespace client |
|
|
|
std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode
|
|
|
|
std::ifstream f (i2p::util::filesystem::GetFullPath ("hosts.txt").c_str (), std::ofstream::in); // in text mode
|
|
|
|
if (!f.is_open ()) |
|
|
|
if (!f.is_open ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("hosts.txt not found. Try to load..."); |
|
|
|
LogPrint (eLogInfo, "hosts.txt not found. Try to load..."); |
|
|
|
if (!m_IsDowloading) |
|
|
|
if (!m_IsDowloading) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsDowloading = true; |
|
|
|
m_IsDowloading = true; |
|
|
@ -287,6 +286,14 @@ namespace client |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoadHostsFromStream (f); |
|
|
|
|
|
|
|
m_Storage->Save (m_Addresses); |
|
|
|
|
|
|
|
m_IsLoaded = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AddressBook::LoadHostsFromStream (std::istream& f) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int numAddresses = 0; |
|
|
|
std::string s; |
|
|
|
std::string s; |
|
|
|
while (!f.eof ()) |
|
|
|
while (!f.eof ()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -309,9 +316,7 @@ namespace client |
|
|
|
numAddresses++; |
|
|
|
numAddresses++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
LogPrint (numAddresses, " addresses loaded"); |
|
|
|
LogPrint (eLogInfo, numAddresses, " addresses loaded"); |
|
|
|
m_Storage->Save (m_Addresses); |
|
|
|
|
|
|
|
m_IsLoaded = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AddressBookSubscription::AddressBookSubscription (AddressBook& book, const std::string& link): |
|
|
|
AddressBookSubscription::AddressBookSubscription (AddressBook& book, const std::string& link): |
|
|
@ -369,6 +374,23 @@ namespace client |
|
|
|
if (!end) |
|
|
|
if (!end) |
|
|
|
end = !stream->IsOpen (); |
|
|
|
end = !stream->IsOpen (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// parse response
|
|
|
|
|
|
|
|
std::string version; |
|
|
|
|
|
|
|
response >> version; // HTTP version
|
|
|
|
|
|
|
|
int status = 0; |
|
|
|
|
|
|
|
response >> status; // status
|
|
|
|
|
|
|
|
if (status == 200) // OK
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::string header, statusMessage; |
|
|
|
|
|
|
|
std::getline (response, statusMessage); |
|
|
|
|
|
|
|
// read until new line meaning end of header
|
|
|
|
|
|
|
|
while (!response.eof () && header != "\r") |
|
|
|
|
|
|
|
std::getline (response, header); |
|
|
|
|
|
|
|
if (!response.eof ()) |
|
|
|
|
|
|
|
m_Book.LoadHostsFromStream (response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "Adressbook HTTP response ", status); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "Address ", u.host_, " not found"); |
|
|
|
LogPrint (eLogError, "Address ", u.host_, " not found"); |
|
|
|