mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-10 20:47:53 +00:00
drop expired leasesand renew leaseset
This commit is contained in:
parent
c754b5ae18
commit
e056c9c135
@ -303,7 +303,7 @@ namespace client
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "New remote LeaseSet verification failed");
|
LogPrint (eLogError, "New remote LeaseSet failed");
|
||||||
leaseSet = nullptr;
|
leaseSet = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -678,7 +678,7 @@ namespace client
|
|||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
for (auto it = m_RemoteLeaseSets.begin (); it != m_RemoteLeaseSets.end ();)
|
for (auto it = m_RemoteLeaseSets.begin (); it != m_RemoteLeaseSets.end ();)
|
||||||
{
|
{
|
||||||
if (ts > it->second->GetExpirationTime ()) // leaseset expired
|
if (it->second->IsEmpty () || ts > it->second->GetExpirationTime ()) // leaseset expired
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "Destination: Remote LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
|
LogPrint (eLogWarning, "Destination: Remote LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
|
||||||
it = m_RemoteLeaseSets.erase (it);
|
it = m_RemoteLeaseSets.erase (it);
|
||||||
|
41
LeaseSet.cpp
41
LeaseSet.cpp
@ -119,6 +119,7 @@ namespace data
|
|||||||
|
|
||||||
// process leases
|
// process leases
|
||||||
m_ExpirationTime = 0;
|
m_ExpirationTime = 0;
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
const uint8_t * leases = m_Buffer + size;
|
const uint8_t * leases = m_Buffer + size;
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
@ -129,21 +130,32 @@ namespace data
|
|||||||
leases += 4; // tunnel ID
|
leases += 4; // tunnel ID
|
||||||
lease.endDate = bufbe64toh (leases);
|
lease.endDate = bufbe64toh (leases);
|
||||||
leases += 8; // end date
|
leases += 8; // end date
|
||||||
if (lease.endDate > m_ExpirationTime)
|
if (ts < lease.endDate)
|
||||||
m_ExpirationTime = lease.endDate;
|
|
||||||
if (m_StoreLeases)
|
|
||||||
{
|
{
|
||||||
auto ret = m_Leases.insert (std::make_shared<Lease>(lease));
|
if (lease.endDate > m_ExpirationTime)
|
||||||
if (!ret.second) *(*ret.first) = lease; // update existing
|
m_ExpirationTime = lease.endDate;
|
||||||
(*ret.first)->isUpdated = true;
|
if (m_StoreLeases)
|
||||||
// check if lease's gateway is in our netDb
|
{
|
||||||
if (!netdb.FindRouter (lease.tunnelGateway))
|
auto ret = m_Leases.insert (std::make_shared<Lease>(lease));
|
||||||
{
|
if (!ret.second) *(*ret.first) = lease; // update existing
|
||||||
// if not found request it
|
(*ret.first)->isUpdated = true;
|
||||||
LogPrint (eLogInfo, "LeaseSet: Lease's tunnel gateway not found, requesting");
|
// check if lease's gateway is in our netDb
|
||||||
netdb.RequestDestination (lease.tunnelGateway);
|
if (!netdb.FindRouter (lease.tunnelGateway))
|
||||||
}
|
{
|
||||||
}
|
// if not found request it
|
||||||
|
LogPrint (eLogInfo, "LeaseSet: Lease's tunnel gateway not found, requesting");
|
||||||
|
netdb.RequestDestination (lease.tunnelGateway);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogWarning, "LeaseSet: Lease is expired already ");
|
||||||
|
}
|
||||||
|
if (!m_ExpirationTime)
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "LeaseSet: all leases are expired. Dropped");
|
||||||
|
m_IsValid = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// delete old leases
|
// delete old leases
|
||||||
if (m_StoreLeases)
|
if (m_StoreLeases)
|
||||||
@ -193,6 +205,7 @@ namespace data
|
|||||||
|
|
||||||
bool LeaseSet::IsExpired () const
|
bool LeaseSet::IsExpired () const
|
||||||
{
|
{
|
||||||
|
if (IsEmpty ()) return true;
|
||||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
return ts > m_ExpirationTime;
|
return ts > m_ExpirationTime;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ namespace data
|
|||||||
const std::vector<std::shared_ptr<Lease> > GetNonExpiredLeases (bool withThreshold = true) const;
|
const std::vector<std::shared_ptr<Lease> > GetNonExpiredLeases (bool withThreshold = true) const;
|
||||||
bool HasExpiredLeases () const;
|
bool HasExpiredLeases () const;
|
||||||
bool IsExpired () const;
|
bool IsExpired () const;
|
||||||
|
bool IsEmpty () const { return m_Leases.empty (); };
|
||||||
uint64_t GetExpirationTime () const { return m_ExpirationTime; };
|
uint64_t GetExpirationTime () const { return m_ExpirationTime; };
|
||||||
|
|
||||||
// implements RoutingDestination
|
// implements RoutingDestination
|
||||||
|
@ -704,11 +704,11 @@ namespace stream
|
|||||||
|
|
||||||
void Stream::UpdateCurrentRemoteLease (bool expired)
|
void Stream::UpdateCurrentRemoteLease (bool expired)
|
||||||
{
|
{
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet || m_RemoteLeaseSet->IsExpired ())
|
||||||
{
|
{
|
||||||
m_RemoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
|
m_RemoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
LogPrint (eLogError, "Streaming: LeaseSet ", m_RemoteIdentity->GetIdentHash ().ToBase64 (), " not found");
|
LogPrint (eLogWarning, "Streaming: LeaseSet ", m_RemoteIdentity->GetIdentHash ().ToBase64 (), " not found");
|
||||||
}
|
}
|
||||||
if (m_RemoteLeaseSet)
|
if (m_RemoteLeaseSet)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user