mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
check lease expiration with threshold
This commit is contained in:
parent
ca3b9f253d
commit
2a23537dbd
11
LeaseSet.cpp
11
LeaseSet.cpp
@ -48,7 +48,7 @@ namespace data
|
|||||||
m_BufferLen += 32; // gateway id
|
m_BufferLen += 32; // gateway id
|
||||||
htobe32buf (m_Buffer + m_BufferLen, it->GetNextTunnelID ());
|
htobe32buf (m_Buffer + m_BufferLen, it->GetNextTunnelID ());
|
||||||
m_BufferLen += 4; // tunnel id
|
m_BufferLen += 4; // tunnel id
|
||||||
uint64_t ts = it->GetCreationTime () + i2p::tunnel::TUNNEL_EXPIRATION_TIMEOUT - 60; // 1 minute before expiration
|
uint64_t ts = it->GetCreationTime () + i2p::tunnel::TUNNEL_EXPIRATION_TIMEOUT - i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD; // 1 minute before expiration
|
||||||
ts *= 1000; // in milliseconds
|
ts *= 1000; // in milliseconds
|
||||||
ts += rnd.GenerateWord32 (0, 5); // + random milliseconds
|
ts += rnd.GenerateWord32 (0, 5); // + random milliseconds
|
||||||
htobe64buf (m_Buffer + m_BufferLen, ts);
|
htobe64buf (m_Buffer + m_BufferLen, ts);
|
||||||
@ -107,13 +107,18 @@ namespace data
|
|||||||
LogPrint ("LeaseSet verification failed");
|
LogPrint ("LeaseSet verification failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Lease> LeaseSet::GetNonExpiredLeases () const
|
const std::vector<Lease> LeaseSet::GetNonExpiredLeases (bool withThreshold) const
|
||||||
{
|
{
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
std::vector<Lease> leases;
|
std::vector<Lease> leases;
|
||||||
for (auto& it: m_Leases)
|
for (auto& it: m_Leases)
|
||||||
if (ts < it.endDate)
|
{
|
||||||
|
auto endDate = it.endDate;
|
||||||
|
if (!withThreshold)
|
||||||
|
endDate -= i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000;
|
||||||
|
if (ts < endDate)
|
||||||
leases.push_back (it);
|
leases.push_back (it);
|
||||||
|
}
|
||||||
return leases;
|
return leases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ namespace data
|
|||||||
// implements RoutingDestination
|
// implements RoutingDestination
|
||||||
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
|
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
|
||||||
const std::vector<Lease>& GetLeases () const { return m_Leases; };
|
const std::vector<Lease>& GetLeases () const { return m_Leases; };
|
||||||
const std::vector<Lease> GetNonExpiredLeases () const;
|
const std::vector<Lease> GetNonExpiredLeases (bool withThreshold = true) const;
|
||||||
bool HasExpiredLeases () const;
|
bool HasExpiredLeases () const;
|
||||||
bool HasNonExpiredLeases () const;
|
bool HasNonExpiredLeases () const;
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };
|
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };
|
||||||
|
@ -585,7 +585,7 @@ namespace stream
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
if (ts >= m_CurrentRemoteLease.endDate)
|
if (ts >= m_CurrentRemoteLease.endDate - i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000)
|
||||||
UpdateCurrentRemoteLease ();
|
UpdateCurrentRemoteLease ();
|
||||||
if (ts < m_CurrentRemoteLease.endDate)
|
if (ts < m_CurrentRemoteLease.endDate)
|
||||||
{
|
{
|
||||||
@ -604,11 +604,7 @@ namespace stream
|
|||||||
m_CurrentOutboundTunnel->SendTunnelDataMsg (msgs);
|
m_CurrentOutboundTunnel->SendTunnelDataMsg (msgs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
LogPrint (eLogWarning, "All leases are expired");
|
||||||
LogPrint (eLogInfo, "All leases are expired. Trying to request");
|
|
||||||
m_RemoteLeaseSet = nullptr;
|
|
||||||
m_LocalDestination.GetOwner ().RequestDestination (m_RemoteIdentity.GetIdentHash ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -703,7 +699,12 @@ namespace stream
|
|||||||
{
|
{
|
||||||
if (!m_RoutingSession)
|
if (!m_RoutingSession)
|
||||||
m_RoutingSession = m_LocalDestination.GetOwner ().GetRoutingSession (m_RemoteLeaseSet, 32);
|
m_RoutingSession = m_LocalDestination.GetOwner ().GetRoutingSession (m_RemoteLeaseSet, 32);
|
||||||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (false); // try without threshold first
|
||||||
|
if (leases.empty ())
|
||||||
|
{
|
||||||
|
m_LocalDestination.GetOwner ().RequestDestination (m_RemoteIdentity.GetIdentHash ()); // time to re-request
|
||||||
|
leases = m_RemoteLeaseSet->GetNonExpiredLeases (true); // then with threshold
|
||||||
|
}
|
||||||
if (!leases.empty ())
|
if (!leases.empty ())
|
||||||
{
|
{
|
||||||
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
||||||
@ -714,8 +715,9 @@ namespace stream
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_RemoteLeaseSet = m_LocalDestination.GetOwner ().FindLeaseSet (m_RemoteIdentity.GetIdentHash ()); // re-request expired
|
m_RemoteLeaseSet = nullptr;
|
||||||
m_CurrentRemoteLease.endDate = 0;
|
m_CurrentRemoteLease.endDate = 0;
|
||||||
|
// re-request expired
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user