mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-25 23:44:18 +00:00
* Addressbook.{cpp,h} : show new hosts
This commit is contained in:
parent
cbfb1edb79
commit
9f3ce09e88
@ -340,12 +340,12 @@ namespace client
|
|||||||
std::ifstream f (i2p::fs::DataDirPath("hosts.txt"), std::ifstream::in); // in text mode
|
std::ifstream f (i2p::fs::DataDirPath("hosts.txt"), std::ifstream::in); // in text mode
|
||||||
if (f.is_open ())
|
if (f.is_open ())
|
||||||
{
|
{
|
||||||
LoadHostsFromStream (f);
|
LoadHostsFromStream (f, false);
|
||||||
m_IsLoaded = true;
|
m_IsLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddressBook::LoadHostsFromStream (std::istream& f)
|
bool AddressBook::LoadHostsFromStream (std::istream& f, bool is_update)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_AddressBookMutex);
|
std::unique_lock<std::mutex> l(m_AddressBookMutex);
|
||||||
int numAddresses = 0;
|
int numAddresses = 0;
|
||||||
@ -366,17 +366,18 @@ namespace client
|
|||||||
std::string addr = s.substr(pos);
|
std::string addr = s.substr(pos);
|
||||||
|
|
||||||
auto ident = std::make_shared<i2p::data::IdentityEx> ();
|
auto ident = std::make_shared<i2p::data::IdentityEx> ();
|
||||||
if (ident->FromBase64(addr))
|
if (!ident->FromBase64(addr)) {
|
||||||
{
|
|
||||||
m_Addresses[name] = ident->GetIdentHash ();
|
|
||||||
m_Storage->AddAddress (ident);
|
|
||||||
numAddresses++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrint (eLogError, "Addressbook: malformed address ", addr, " for ", name);
|
LogPrint (eLogError, "Addressbook: malformed address ", addr, " for ", name);
|
||||||
incomplete = f.eof ();
|
incomplete = f.eof ();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
numAddresses++;
|
||||||
|
if (m_Addresses.count(name) > 0)
|
||||||
|
continue; /* already exists */
|
||||||
|
m_Addresses[name] = ident->GetIdentHash ();
|
||||||
|
m_Storage->AddAddress (ident);
|
||||||
|
if (is_update)
|
||||||
|
LogPrint(eLogInfo, "Addressbook: added new host: ", name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
incomplete = f.eof ();
|
incomplete = f.eof ();
|
||||||
@ -776,7 +777,7 @@ namespace client
|
|||||||
}
|
}
|
||||||
std::stringstream ss(response);
|
std::stringstream ss(response);
|
||||||
LogPrint (eLogInfo, "Addressbook: got update from ", dest_host);
|
LogPrint (eLogInfo, "Addressbook: got update from ", dest_host);
|
||||||
m_Book.LoadHostsFromStream (ss);
|
m_Book.LoadHostsFromStream (ss, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ namespace client
|
|||||||
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
|
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
|
||||||
void InsertAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
void InsertAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
||||||
|
|
||||||
bool LoadHostsFromStream (std::istream& f);
|
bool LoadHostsFromStream (std::istream& f, bool is_update);
|
||||||
void DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified);
|
void DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified);
|
||||||
//This method returns the ".b32.i2p" address
|
//This method returns the ".b32.i2p" address
|
||||||
std::string ToAddress(const i2p::data::IdentHash& ident) { return GetB32Address(ident); }
|
std::string ToAddress(const i2p::data::IdentHash& ident) { return GetB32Address(ident); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user