mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-13 11:17:53 +00:00
handle LeaseSet expiration correctly
This commit is contained in:
parent
49b1e76585
commit
ca56d3fc23
19
LeaseSet.cpp
19
LeaseSet.cpp
@ -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
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
m_RemoteLeaseSet = nullptr;
|
||||
m_CurrentRemoteLease = nullptr;
|
||||
// re-request expired
|
||||
m_LocalDestination.GetOwner ()->RequestDestination (m_RemoteIdentity->GetIdentHash ());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -53,6 +53,9 @@ namespace tunnel
|
||||
bool IsActive () const { return m_IsActive; };
|
||||
void SetActive (bool isActive) { m_IsActive = isActive; };
|
||||
void DetachTunnels ();
|
||||
|
||||
int GetNumInboundTunnels () const { return m_NumInboundTunnels; };
|
||||
int GetNumOutboundTunnels () const { return m_NumOutboundTunnels; };
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user