|
|
@ -315,63 +315,24 @@ namespace client |
|
|
|
m_Subscriptions.clear (); |
|
|
|
m_Subscriptions.clear (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AddressBook::GetIdentHash (const std::string& address, i2p::data::IdentHash& ident) |
|
|
|
std::shared_ptr<const Address> AddressBook::GetAddress (const std::string& address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto pos = address.find(".b32.i2p"); |
|
|
|
auto pos = address.find(".b32.i2p"); |
|
|
|
if (pos != std::string::npos) |
|
|
|
if (pos != std::string::npos) |
|
|
|
{ |
|
|
|
return std::make_shared<const Address>(address.substr (0, pos)); |
|
|
|
if (pos <= B33_ADDRESS_THRESHOLD) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Base32ToByteStream (address.c_str(), pos, ident, 32); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
pos = address.find (".i2p"); |
|
|
|
pos = address.find (".i2p"); |
|
|
|
if (pos != std::string::npos) |
|
|
|
if (pos != std::string::npos) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto addr = FindAddress (address); |
|
|
|
auto addr = FindAddress (address); |
|
|
|
if (addr) |
|
|
|
if (!addr) |
|
|
|
{ |
|
|
|
|
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ident = addr->identHash; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LookupAddress (address); // TODO:
|
|
|
|
LookupAddress (address); // TODO:
|
|
|
|
return false; |
|
|
|
return addr; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// if not .b32 we assume full base64 address
|
|
|
|
// if not .b32 we assume full base64 address
|
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
if (!dest.FromBase64 (address)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
ident = dest.GetIdentHash (); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<const Address> AddressBook::GetAddress (const std::string& address) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto pos = address.find(".b32.i2p"); |
|
|
|
|
|
|
|
if (pos != std::string::npos) |
|
|
|
|
|
|
|
return std::make_shared<const Address>(address.substr (0, pos)); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
pos = address.find (".i2p"); |
|
|
|
|
|
|
|
if (pos != std::string::npos) |
|
|
|
|
|
|
|
return FindAddress (address); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// if not .b32 we assume full base64 address
|
|
|
|
|
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
|
|
|
|
if (!dest.FromBase64 (address)) |
|
|
|
if (!dest.FromBase64 (address)) |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
return std::make_shared<const Address>(dest.GetIdentHash ()); |
|
|
|
return std::make_shared<const Address>(dest.GetIdentHash ()); |
|
|
@ -401,9 +362,9 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<const i2p::data::IdentityEx> AddressBook::GetFullAddress (const std::string& address) |
|
|
|
std::shared_ptr<const i2p::data::IdentityEx> AddressBook::GetFullAddress (const std::string& address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::data::IdentHash ident; |
|
|
|
auto addr = GetAddress (address); |
|
|
|
if (!GetIdentHash (address, ident)) return nullptr; |
|
|
|
if (!addr || !addr->IsIdentHash ()) return nullptr; |
|
|
|
return m_Storage->GetAddress (ident); |
|
|
|
return m_Storage->GetAddress (addr->identHash); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void AddressBook::LoadHosts () |
|
|
|
void AddressBook::LoadHosts () |
|
|
@ -761,14 +722,19 @@ namespace client |
|
|
|
i2p::http::URL url; |
|
|
|
i2p::http::URL url; |
|
|
|
// must be run in separate thread
|
|
|
|
// must be run in separate thread
|
|
|
|
LogPrint (eLogInfo, "Addressbook: Downloading hosts database from ", m_Link); |
|
|
|
LogPrint (eLogInfo, "Addressbook: Downloading hosts database from ", m_Link); |
|
|
|
if (!url.parse(m_Link)) { |
|
|
|
if (!url.parse(m_Link)) |
|
|
|
|
|
|
|
{ |
|
|
|
LogPrint(eLogError, "Addressbook: failed to parse url: ", m_Link); |
|
|
|
LogPrint(eLogError, "Addressbook: failed to parse url: ", m_Link); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!m_Book.GetIdentHash (url.host, m_Ident)) { |
|
|
|
auto addr = m_Book.GetAddress (url.host); |
|
|
|
|
|
|
|
if (!addr || !addr->IsIdentHash ()) |
|
|
|
|
|
|
|
{ |
|
|
|
LogPrint (eLogError, "Addressbook: Can't resolve ", url.host); |
|
|
|
LogPrint (eLogError, "Addressbook: Can't resolve ", url.host); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
m_Ident = addr->identHash; |
|
|
|
/* this code block still needs some love */ |
|
|
|
/* this code block still needs some love */ |
|
|
|
std::condition_variable newDataReceived; |
|
|
|
std::condition_variable newDataReceived; |
|
|
|
std::mutex newDataReceivedMutex; |
|
|
|
std::mutex newDataReceivedMutex; |
|
|
|