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 @@ -42,7 +42,9 @@ namespace data
auto signingKeyLen = localDestination->GetIdentity ()->GetSigningPublicKeyLen ();
memset (m_Buffer + m_BufferLen, 0, 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_BufferLen++;
// leases
@ -151,12 +153,13 @@ namespace data @@ -151,12 +153,13 @@ namespace data
else
LogPrint (eLogWarning, "LeaseSet: Lease is expired already ");
}
if (!m_ExpirationTime && m_Leases.empty ())
if (!m_ExpirationTime)
{
LogPrint (eLogWarning, "LeaseSet: all leases are expired. Dropped");
m_IsValid = false;
return;
}
m_ExpirationTime += LEASE_ENDDATE_THRESHOLD;
// delete old leases
if (m_StoreLeases)
{
@ -187,17 +190,13 @@ namespace data @@ -187,17 +190,13 @@ namespace data
for (auto it: m_Leases)
{
auto endDate = it->endDate;
if (!withThreshold)
endDate -= i2p::tunnel::TUNNEL_EXPIRATION_THRESHOLD*1000;
if (withThreshold)
endDate += LEASE_ENDDATE_THRESHOLD;
else
endDate -= LEASE_ENDDATE_THRESHOLD;
if (ts < endDate)
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;
}

4
Streaming.cpp

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

3
TunnelPool.h

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

Loading…
Cancel
Save