mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-31 00:34:20 +00:00
select next lease with same gateway if possible
This commit is contained in:
parent
12465f840a
commit
873754c6ca
@ -606,7 +606,7 @@ namespace stream
|
|||||||
|
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
if (ts >= m_CurrentRemoteLease.endDate - i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000)
|
if (ts >= m_CurrentRemoteLease.endDate - i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000)
|
||||||
UpdateCurrentRemoteLease ();
|
UpdateCurrentRemoteLease (true);
|
||||||
if (ts < m_CurrentRemoteLease.endDate)
|
if (ts < m_CurrentRemoteLease.endDate)
|
||||||
{
|
{
|
||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
@ -709,7 +709,7 @@ namespace stream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::UpdateCurrentRemoteLease ()
|
void Stream::UpdateCurrentRemoteLease (bool expired)
|
||||||
{
|
{
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
@ -724,10 +724,24 @@ namespace stream
|
|||||||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (false); // try without threshold first
|
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (false); // try without threshold first
|
||||||
if (leases.empty ())
|
if (leases.empty ())
|
||||||
{
|
{
|
||||||
|
expired = false;
|
||||||
m_LocalDestination.GetOwner ().RequestDestination (m_RemoteIdentity.GetIdentHash ()); // time to re-request
|
m_LocalDestination.GetOwner ().RequestDestination (m_RemoteIdentity.GetIdentHash ()); // time to re-request
|
||||||
leases = m_RemoteLeaseSet->GetNonExpiredLeases (true); // then with threshold
|
leases = m_RemoteLeaseSet->GetNonExpiredLeases (true); // then with threshold
|
||||||
}
|
}
|
||||||
if (!leases.empty ())
|
if (!leases.empty ())
|
||||||
|
{
|
||||||
|
bool updated = false;
|
||||||
|
if (expired)
|
||||||
|
{
|
||||||
|
for (auto it: leases)
|
||||||
|
if ((it.tunnelGateway == m_CurrentRemoteLease.tunnelGateway) && (it.tunnelID != m_CurrentRemoteLease.tunnelID))
|
||||||
|
{
|
||||||
|
m_CurrentRemoteLease = it;
|
||||||
|
updated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!updated)
|
||||||
{
|
{
|
||||||
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
||||||
if (m_CurrentRemoteLease.endDate && leases[i].tunnelID == m_CurrentRemoteLease.tunnelID)
|
if (m_CurrentRemoteLease.endDate && leases[i].tunnelID == m_CurrentRemoteLease.tunnelID)
|
||||||
@ -735,6 +749,7 @@ namespace stream
|
|||||||
i = (i + 1) % leases.size (); // if so, pick next
|
i = (i + 1) % leases.size (); // if so, pick next
|
||||||
m_CurrentRemoteLease = leases[i];
|
m_CurrentRemoteLease = leases[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_RemoteLeaseSet = nullptr;
|
m_RemoteLeaseSet = nullptr;
|
||||||
|
@ -147,7 +147,7 @@ namespace stream
|
|||||||
void ProcessAck (Packet * packet);
|
void ProcessAck (Packet * packet);
|
||||||
size_t ConcatenatePackets (uint8_t * buf, size_t len);
|
size_t ConcatenatePackets (uint8_t * buf, size_t len);
|
||||||
|
|
||||||
void UpdateCurrentRemoteLease ();
|
void UpdateCurrentRemoteLease (bool expired = false);
|
||||||
|
|
||||||
template<typename Buffer, typename ReceiveHandler>
|
template<typename Buffer, typename ReceiveHandler>
|
||||||
void HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler);
|
void HandleReceiveTimer (const boost::system::error_code& ecode, const Buffer& buffer, ReceiveHandler handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user