Browse Source

allow .b32.i2p in jump links

pull/1334/head
orignal 5 years ago
parent
commit
706da6e431
  1. 26
      libi2pd_client/AddressBook.cpp
  2. 2
      libi2pd_client/AddressBook.h
  3. 11
      libi2pd_client/HTTPProxy.cpp

26
libi2pd_client/AddressBook.cpp

@ -347,13 +347,27 @@ namespace client @@ -347,13 +347,27 @@ namespace client
return nullptr;
}
void AddressBook::InsertAddress (const std::string& address, const std::string& base64)
void AddressBook::InsertAddress (const std::string& address, const std::string& jump)
{
auto ident = std::make_shared<i2p::data::IdentityEx>();
ident->FromBase64 (base64);
m_Storage->AddAddress (ident);
m_Addresses[address] = std::make_shared<Address>(ident->GetIdentHash ());
LogPrint (eLogInfo, "Addressbook: added ", address," -> ", ToAddress(ident->GetIdentHash ()));
auto pos = jump.find(".b32.i2p");
if (pos != std::string::npos)
{
m_Addresses[address] = std::make_shared<Address>(jump.substr (0, pos));
LogPrint (eLogInfo, "Addressbook: added ", address," -> ", jump);
}
else
{
// assume base64
auto ident = std::make_shared<i2p::data::IdentityEx>();
if (ident->FromBase64 (jump))
{
m_Storage->AddAddress (ident);
m_Addresses[address] = std::make_shared<Address>(ident->GetIdentHash ());
LogPrint (eLogInfo, "Addressbook: added ", address," -> ", ToAddress(ident->GetIdentHash ()));
}
else
LogPrint (eLogError, "Addressbook: malformed address ", jump);
}
}
void AddressBook::InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address)

2
libi2pd_client/AddressBook.h

@ -78,7 +78,7 @@ namespace client @@ -78,7 +78,7 @@ namespace client
std::shared_ptr<const i2p::data::IdentityEx> GetFullAddress (const std::string& address);
std::shared_ptr<const Address> FindAddress (const std::string& address);
void LookupAddress (const std::string& address);
void InsertAddress (const std::string& address, const std::string& base64); // for jump service
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
bool LoadHostsFromStream (std::istream& f, bool is_update);

11
libi2pd_client/HTTPProxy.cpp

@ -234,8 +234,6 @@ namespace proxy { @@ -234,8 +234,6 @@ namespace proxy {
*/
bool HTTPReqHandler::HandleRequest()
{
std::string b64;
m_req_len = m_ClientRequest.parse(m_recv_buf);
if (m_req_len == 0)
@ -252,7 +250,8 @@ namespace proxy { @@ -252,7 +250,8 @@ namespace proxy {
m_RequestURL.parse(m_ClientRequest.uri);
bool m_Confirm;
if (ExtractAddressHelper(m_RequestURL, b64, m_Confirm))
std::string jump;
if (ExtractAddressHelper(m_RequestURL, jump, m_Confirm))
{
bool addresshelper; i2p::config::GetOption("httpproxy.addresshelper", addresshelper);
if (!addresshelper)
@ -263,8 +262,8 @@ namespace proxy { @@ -263,8 +262,8 @@ namespace proxy {
}
if (!i2p::client::context.GetAddressBook ().FindAddress (m_RequestURL.host) || m_Confirm)
{
i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, b64);
LogPrint (eLogInfo, "HTTPProxy: added b64 from addresshelper for ", m_RequestURL.host);
i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, jump);
LogPrint (eLogInfo, "HTTPProxy: added address from addresshelper for ", m_RequestURL.host);
std::string full_url = m_RequestURL.to_string();
std::stringstream ss;
ss << "Host " << m_RequestURL.host << " added to router's addressbook from helper. "
@ -276,7 +275,7 @@ namespace proxy { @@ -276,7 +275,7 @@ namespace proxy {
{
std::stringstream ss;
ss << "Host " << m_RequestURL.host << " <font color=red>already in router's addressbook</font>. "
<< "Click <a href=\"" << m_RequestURL.query << "?i2paddresshelper=" << b64 << "&update=true\">here</a> to update record.";
<< "Click <a href=\"" << m_RequestURL.query << "?i2paddresshelper=" << jump << "&update=true\">here</a> to update record.";
GenericProxyInfo("Addresshelper found", ss.str().c_str());
return true; /* request processed */
}

Loading…
Cancel
Save