check if addressbook is enabled

This commit is contained in:
orignal 2024-09-11 12:06:55 -04:00
parent 78ec5b2c6e
commit 3d0a1afd64
3 changed files with 15 additions and 10 deletions

View File

@ -441,7 +441,7 @@ namespace client
auto ident = std::make_shared<i2p::data::IdentityEx>(); auto ident = std::make_shared<i2p::data::IdentityEx>();
if (ident->FromBase64 (jump)) if (ident->FromBase64 (jump))
{ {
m_Storage->AddAddress (ident); if (m_Storage) m_Storage->AddAddress (ident);
m_Addresses[address] = std::make_shared<Address>(ident->GetIdentHash ()); m_Addresses[address] = std::make_shared<Address>(ident->GetIdentHash ());
LogPrint (eLogInfo, "Addressbook: Added ", address," -> ", ToAddress(ident->GetIdentHash ())); LogPrint (eLogInfo, "Addressbook: Added ", address," -> ", ToAddress(ident->GetIdentHash ()));
} }
@ -452,18 +452,19 @@ namespace client
void AddressBook::InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address) void AddressBook::InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address)
{ {
m_Storage->AddAddress (address); if (m_Storage) m_Storage->AddAddress (address);
} }
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)
{ {
auto addr = GetAddress (address); auto addr = GetAddress (address);
if (!addr || !addr->IsIdentHash ()) return nullptr; if (!addr || !addr->IsIdentHash ()) return nullptr;
return m_Storage->GetAddress (addr->identHash); return m_Storage ? m_Storage->GetAddress (addr->identHash) : nullptr;
} }
void AddressBook::LoadHosts () void AddressBook::LoadHosts ()
{ {
if (!m_Storage) return;
if (m_Storage->Load (m_Addresses) > 0) if (m_Storage->Load (m_Addresses) > 0)
{ {
m_IsLoaded = true; m_IsLoaded = true;
@ -534,15 +535,18 @@ namespace client
ident->GetSigningKeyType () != i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) // don't replace by DSA ident->GetSigningKeyType () != i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) // don't replace by DSA
{ {
it->second->identHash = ident->GetIdentHash (); it->second->identHash = ident->GetIdentHash ();
m_Storage->AddAddress (ident); if (m_Storage)
m_Storage->RemoveAddress (it->second->identHash); {
m_Storage->AddAddress (ident);
m_Storage->RemoveAddress (it->second->identHash);
}
LogPrint (eLogInfo, "Addressbook: Updated host: ", name); LogPrint (eLogInfo, "Addressbook: Updated host: ", name);
} }
} }
else else
{ {
m_Addresses.emplace (name, std::make_shared<Address>(ident->GetIdentHash ())); m_Addresses.emplace (name, std::make_shared<Address>(ident->GetIdentHash ()));
m_Storage->AddAddress (ident); if (m_Storage) m_Storage->AddAddress (ident);
if (is_update) if (is_update)
LogPrint (eLogInfo, "Addressbook: Added new host: ", name); LogPrint (eLogInfo, "Addressbook: Added new host: ", name);
} }
@ -554,7 +558,7 @@ namespace client
if (numAddresses > 0) if (numAddresses > 0)
{ {
if (!incomplete) m_IsLoaded = true; if (!incomplete) m_IsLoaded = true;
m_Storage->Save (m_Addresses); if (m_Storage) m_Storage->Save (m_Addresses);
} }
return !incomplete; return !incomplete;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2022, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -99,7 +99,8 @@ namespace client
std::string ToAddress(std::shared_ptr<const i2p::data::IdentityEx> ident) { return ToAddress(ident->GetIdentHash ()); } std::string ToAddress(std::shared_ptr<const i2p::data::IdentityEx> ident) { return ToAddress(ident->GetIdentHash ()); }
bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified); bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified);
bool IsEnabled () const { return m_IsEnabled; }
private: private:
void StartSubscriptions (); void StartSubscriptions ();

View File

@ -376,7 +376,7 @@ namespace proxy {
std::string jump; std::string jump;
if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm)) if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm))
{ {
if (!m_Addresshelper) if (!m_Addresshelper || !i2p::client::context.GetAddressBook ().IsEnabled ())
{ {
LogPrint(eLogWarning, "HTTPProxy: Addresshelper request rejected"); LogPrint(eLogWarning, "HTTPProxy: Addresshelper request rejected");
GenericProxyError(tr("Invalid request"), tr("Addresshelper is not supported")); GenericProxyError(tr("Invalid request"), tr("Addresshelper is not supported"));