Browse Source

handle LeaseSet expiration correctly

pull/380/head
orignal 9 years ago
parent
commit
ca56d3fc23
  1. 19
      LeaseSet.cpp
  2. 4
      Streaming.cpp
  3. 3
      TunnelPool.h

19
LeaseSet.cpp

@ -42,7 +42,9 @@ namespace data
auto signingKeyLen = localDestination->GetIdentity ()->GetSigningPublicKeyLen (); auto signingKeyLen = localDestination->GetIdentity ()->GetSigningPublicKeyLen ();
memset (m_Buffer + m_BufferLen, 0, signingKeyLen); memset (m_Buffer + m_BufferLen, 0, signingKeyLen);
m_BufferLen += signingKeyLen; m_BufferLen += signingKeyLen;
auto tunnels = pool->GetInboundTunnels (5); // 5 tunnels maximum int numTunnels = pool->GetNumInboundTunnels () + 2; // 2 backup tunnels
if (numTunnels > 16) numTunnels = 16; // 16 tunnels maximum
auto tunnels = pool->GetInboundTunnels (numTunnels);
m_Buffer[m_BufferLen] = tunnels.size (); // num leases m_Buffer[m_BufferLen] = tunnels.size (); // num leases
m_BufferLen++; m_BufferLen++;
// leases // leases
@ -151,12 +153,13 @@ namespace data
else else
LogPrint (eLogWarning, "LeaseSet: Lease is expired already "); LogPrint (eLogWarning, "LeaseSet: Lease is expired already ");
} }
if (!m_ExpirationTime && m_Leases.empty ()) if (!m_ExpirationTime)
{ {
LogPrint (eLogWarning, "LeaseSet: all leases are expired. Dropped"); LogPrint (eLogWarning, "LeaseSet: all leases are expired. Dropped");
m_IsValid = false; m_IsValid = false;
return; return;
} }
m_ExpirationTime += LEASE_ENDDATE_THRESHOLD;
// delete old leases // delete old leases
if (m_StoreLeases) if (m_StoreLeases)
{ {
@ -187,17 +190,13 @@ namespace data
for (auto it: m_Leases) for (auto it: m_Leases)
{ {
auto endDate = it->endDate; auto endDate = it->endDate;
if (!withThreshold) if (withThreshold)
endDate -= i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000; endDate += LEASE_ENDDATE_THRESHOLD;
else
endDate -= LEASE_ENDDATE_THRESHOLD;
if (ts < endDate) if (ts < endDate)
leases.push_back (it); leases.push_back (it);
} }
if (leases.empty () && withThreshold)
{
for (auto it: m_Leases)
if (ts < it->endDate + LEASE_ENDDATE_THRESHOLD)
leases.push_back (it);
}
return leases; return leases;
} }

4
Streaming.cpp

@ -731,8 +731,7 @@ namespace stream
{ {
if (!m_RemoteLeaseSet || m_RemoteLeaseSet->IsExpired ()) if (!m_RemoteLeaseSet || m_RemoteLeaseSet->IsExpired ())
{ {
auto remoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ()); m_RemoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
if (remoteLeaseSet) m_RemoteLeaseSet = remoteLeaseSet; // renew if possible
if (!m_RemoteLeaseSet) if (!m_RemoteLeaseSet)
LogPrint (eLogWarning, "Streaming: LeaseSet ", m_RemoteIdentity->GetIdentHash ().ToBase64 (), " not found"); LogPrint (eLogWarning, "Streaming: LeaseSet ", m_RemoteIdentity->GetIdentHash ().ToBase64 (), " not found");
} }
@ -774,6 +773,7 @@ namespace stream
m_RemoteLeaseSet = nullptr; m_RemoteLeaseSet = nullptr;
m_CurrentRemoteLease = nullptr; m_CurrentRemoteLease = nullptr;
// re-request expired // re-request expired
m_LocalDestination.GetOwner ()->RequestDestination (m_RemoteIdentity->GetIdentHash ());
} }
} }
else else

3
TunnelPool.h

@ -54,6 +54,9 @@ namespace tunnel
void SetActive (bool isActive) { m_IsActive = isActive; }; void SetActive (bool isActive) { m_IsActive = isActive; };
void DetachTunnels (); void DetachTunnels ();
int GetNumInboundTunnels () const { return m_NumInboundTunnels; };
int GetNumOutboundTunnels () const { return m_NumOutboundTunnels; };
private: private:
void CreateInboundTunnel (); void CreateInboundTunnel ();

Loading…
Cancel
Save