Browse Source

check lease expiration with threshold

pull/167/head
orignal 10 years ago
parent
commit
2a23537dbd
  1. 11
      LeaseSet.cpp
  2. 2
      LeaseSet.h
  3. 18
      Streaming.cpp

11
LeaseSet.cpp

@ -48,7 +48,7 @@ namespace data @@ -48,7 +48,7 @@ namespace data
m_BufferLen += 32; // gateway id
htobe32buf (m_Buffer + m_BufferLen, it->GetNextTunnelID ());
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 += rnd.GenerateWord32 (0, 5); // + random milliseconds
htobe64buf (m_Buffer + m_BufferLen, ts);
@ -107,13 +107,18 @@ namespace data @@ -107,13 +107,18 @@ namespace data
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 ();
std::vector<Lease> 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);
}
return leases;
}

2
LeaseSet.h

@ -49,7 +49,7 @@ namespace data @@ -49,7 +49,7 @@ namespace data
// implements RoutingDestination
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
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 HasNonExpiredLeases () const;
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };

18
Streaming.cpp

@ -585,7 +585,7 @@ namespace stream @@ -585,7 +585,7 @@ namespace stream
}
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
if (ts >= m_CurrentRemoteLease.endDate)
if (ts >= m_CurrentRemoteLease.endDate - i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000)
UpdateCurrentRemoteLease ();
if (ts < m_CurrentRemoteLease.endDate)
{
@ -604,11 +604,7 @@ namespace stream @@ -604,11 +604,7 @@ namespace stream
m_CurrentOutboundTunnel->SendTunnelDataMsg (msgs);
}
else
{
LogPrint (eLogInfo, "All leases are expired. Trying to request");
m_RemoteLeaseSet = nullptr;
m_LocalDestination.GetOwner ().RequestDestination (m_RemoteIdentity.GetIdentHash ());
}
LogPrint (eLogWarning, "All leases are expired");
}
@ -703,7 +699,12 @@ namespace stream @@ -703,7 +699,12 @@ namespace stream
{
if (!m_RoutingSession)
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 ())
{
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
@ -714,8 +715,9 @@ namespace stream @@ -714,8 +715,9 @@ namespace stream
}
else
{
m_RemoteLeaseSet = m_LocalDestination.GetOwner ().FindLeaseSet (m_RemoteIdentity.GetIdentHash ()); // re-request expired
m_RemoteLeaseSet = nullptr;
m_CurrentRemoteLease.endDate = 0;
// re-request expired
}
}
else

Loading…
Cancel
Save