mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
Simplify and merge the identHash caching codepath on I2PClientTunnel
This commit is contained in:
parent
c05f411ba0
commit
6489230e68
@ -174,11 +174,7 @@ namespace client
|
|||||||
|
|
||||||
void I2PClientTunnel::Start ()
|
void I2PClientTunnel::Start ()
|
||||||
{
|
{
|
||||||
i2p::data::IdentHash identHash;
|
GetIdentHash();
|
||||||
if (i2p::client::context.GetAddressBook ().GetIdentHash (m_Destination, identHash))
|
|
||||||
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
|
|
||||||
if (!m_DestinationIdentHash)
|
|
||||||
LogPrint ("I2PTunnel unknown destination ", m_Destination);
|
|
||||||
m_Acceptor.listen ();
|
m_Acceptor.listen ();
|
||||||
Accept ();
|
Accept ();
|
||||||
}
|
}
|
||||||
@ -193,6 +189,21 @@ namespace client
|
|||||||
delete originalIdentHash;
|
delete originalIdentHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* HACK: maybe we should create a caching IdentHash provider in AddressBook */
|
||||||
|
const i2p::data::IdentHash * I2PClientTunnel::GetIdentHash ()
|
||||||
|
{
|
||||||
|
if (!m_DestinationIdentHash)
|
||||||
|
{
|
||||||
|
i2p::data::IdentHash identHash;
|
||||||
|
if (i2p::client::context.GetAddressBook ().GetIdentHash (m_Destination, identHash))
|
||||||
|
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
|
||||||
|
else
|
||||||
|
LogPrint ("Remote destination ", m_Destination, " not found");
|
||||||
|
}
|
||||||
|
return m_DestinationIdentHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void I2PClientTunnel::Accept ()
|
void I2PClientTunnel::Accept ()
|
||||||
{
|
{
|
||||||
auto newSocket = new boost::asio::ip::tcp::socket (GetService ());
|
auto newSocket = new boost::asio::ip::tcp::socket (GetService ());
|
||||||
@ -204,31 +215,22 @@ namespace client
|
|||||||
{
|
{
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
if (!m_DestinationIdentHash)
|
const i2p::data::IdentHash *identHash = GetIdentHash();
|
||||||
{
|
if (identHash)
|
||||||
i2p::data::IdentHash identHash;
|
|
||||||
if (i2p::client::context.GetAddressBook ().GetIdentHash (m_Destination, identHash))
|
|
||||||
m_DestinationIdentHash = new i2p::data::IdentHash (identHash);
|
|
||||||
}
|
|
||||||
if (m_DestinationIdentHash)
|
|
||||||
{
|
{
|
||||||
// try to get a LeaseSet
|
// try to get a LeaseSet
|
||||||
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*m_DestinationIdentHash);
|
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*identHash);
|
||||||
if (m_RemoteLeaseSet && m_RemoteLeaseSet->HasNonExpiredLeases ())
|
if (m_RemoteLeaseSet && m_RemoteLeaseSet->HasNonExpiredLeases ())
|
||||||
CreateConnection (socket);
|
CreateConnection (socket);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetLocalDestination ()->RequestDestination (*m_DestinationIdentHash,
|
GetLocalDestination ()->RequestDestination (*identHash,
|
||||||
std::bind (&I2PClientTunnel::HandleLeaseSetRequestComplete,
|
std::bind (&I2PClientTunnel::HandleLeaseSetRequestComplete,
|
||||||
this, std::placeholders::_1, socket));
|
this, std::placeholders::_1, socket));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
LogPrint ("Remote destination ", m_Destination, " not found");
|
|
||||||
delete socket;
|
delete socket;
|
||||||
}
|
|
||||||
|
|
||||||
Accept ();
|
Accept ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -239,9 +241,10 @@ namespace client
|
|||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
if (m_DestinationIdentHash)
|
const i2p::data::IdentHash *identHash = GetIdentHash();
|
||||||
|
if (identHash)
|
||||||
{
|
{
|
||||||
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*m_DestinationIdentHash);
|
m_RemoteLeaseSet = GetLocalDestination ()->FindLeaseSet (*identHash);
|
||||||
CreateConnection (socket);
|
CreateConnection (socket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ namespace client
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
const i2p::data::IdentHash * GetIdentHash ();
|
||||||
void Accept ();
|
void Accept ();
|
||||||
void HandleAccept (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket);
|
void HandleAccept (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket);
|
||||||
void HandleLeaseSetRequestComplete (bool success, boost::asio::ip::tcp::socket * socket);
|
void HandleLeaseSetRequestComplete (bool success, boost::asio::ip::tcp::socket * socket);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user