mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
validate leaseset for zero leases
This commit is contained in:
parent
9ce9d9b7fc
commit
d5e1d5db9c
4 changed files with 46 additions and 10 deletions
|
@ -223,14 +223,29 @@ namespace client
|
||||||
{
|
{
|
||||||
leaseSet = it->second;
|
leaseSet = it->second;
|
||||||
leaseSet->Update (buf + offset, len - offset);
|
leaseSet->Update (buf + offset, len - offset);
|
||||||
|
if (leaseSet->IsValid ())
|
||||||
LogPrint (eLogDebug, "Remote LeaseSet updated");
|
LogPrint (eLogDebug, "Remote LeaseSet updated");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Remote LeaseSet update failed");
|
||||||
|
m_RemoteLeaseSets.erase (it);
|
||||||
|
leaseSet = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "New remote LeaseSet added");
|
|
||||||
leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset);
|
leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset);
|
||||||
|
if (leaseSet->IsValid ())
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "New remote LeaseSet added");
|
||||||
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = leaseSet;
|
m_RemoteLeaseSets[buf + DATABASE_STORE_KEY_OFFSET] = leaseSet;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "New remote LeaseSet verification failed");
|
||||||
|
leaseSet = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint (eLogError, "Unexpected client's DatabaseStore type ", buf[DATABASE_STORE_TYPE_OFFSET], ". Dropped");
|
LogPrint (eLogError, "Unexpected client's DatabaseStore type ", buf[DATABASE_STORE_TYPE_OFFSET], ". Dropped");
|
||||||
|
|
15
LeaseSet.cpp
15
LeaseSet.cpp
|
@ -14,7 +14,8 @@ namespace i2p
|
||||||
namespace data
|
namespace data
|
||||||
{
|
{
|
||||||
|
|
||||||
LeaseSet::LeaseSet (const uint8_t * buf, size_t len)
|
LeaseSet::LeaseSet (const uint8_t * buf, size_t len):
|
||||||
|
m_IsValid (true)
|
||||||
{
|
{
|
||||||
m_Buffer = new uint8_t[len];
|
m_Buffer = new uint8_t[len];
|
||||||
memcpy (m_Buffer, buf, len);
|
memcpy (m_Buffer, buf, len);
|
||||||
|
@ -22,7 +23,8 @@ namespace data
|
||||||
ReadFromBuffer ();
|
ReadFromBuffer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool)
|
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool):
|
||||||
|
m_IsValid (true)
|
||||||
{
|
{
|
||||||
// header
|
// header
|
||||||
const i2p::data::LocalDestination * localDestination = pool.GetLocalDestination ();
|
const i2p::data::LocalDestination * localDestination = pool.GetLocalDestination ();
|
||||||
|
@ -30,6 +32,7 @@ namespace data
|
||||||
{
|
{
|
||||||
m_Buffer = nullptr;
|
m_Buffer = nullptr;
|
||||||
m_BufferLen = 0;
|
m_BufferLen = 0;
|
||||||
|
m_IsValid = false;
|
||||||
LogPrint (eLogError, "Destination for local LeaseSet doesn't exist");
|
LogPrint (eLogError, "Destination for local LeaseSet doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +91,7 @@ namespace data
|
||||||
uint8_t num = m_Buffer[size];
|
uint8_t num = m_Buffer[size];
|
||||||
size++; // num
|
size++; // num
|
||||||
LogPrint ("LeaseSet num=", (int)num);
|
LogPrint ("LeaseSet num=", (int)num);
|
||||||
|
if (!num) m_IsValid = false;
|
||||||
|
|
||||||
// process leases
|
// process leases
|
||||||
const uint8_t * leases = m_Buffer + size;
|
const uint8_t * leases = m_Buffer + size;
|
||||||
|
@ -106,14 +110,17 @@ namespace data
|
||||||
if (!netdb.FindRouter (lease.tunnelGateway))
|
if (!netdb.FindRouter (lease.tunnelGateway))
|
||||||
{
|
{
|
||||||
// if not found request it
|
// if not found request it
|
||||||
LogPrint ("Lease's tunnel gateway not found. Requested");
|
LogPrint (eLogInfo, "Lease's tunnel gateway not found. Requested");
|
||||||
netdb.RequestDestination (lease.tunnelGateway);
|
netdb.RequestDestination (lease.tunnelGateway);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
if (!m_Identity.Verify (m_Buffer, leases - m_Buffer, leases))
|
if (!m_Identity.Verify (m_Buffer, leases - m_Buffer, leases))
|
||||||
LogPrint ("LeaseSet verification failed");
|
{
|
||||||
|
LogPrint (eLogWarning, "LeaseSet verification failed");
|
||||||
|
m_IsValid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Lease> LeaseSet::GetNonExpiredLeases (bool withThreshold) const
|
const std::vector<Lease> LeaseSet::GetNonExpiredLeases (bool withThreshold) const
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace data
|
||||||
|
|
||||||
const uint8_t * GetBuffer () const { return m_Buffer; };
|
const uint8_t * GetBuffer () const { return m_Buffer; };
|
||||||
size_t GetBufferLen () const { return m_BufferLen; };
|
size_t GetBufferLen () const { return m_BufferLen; };
|
||||||
|
bool IsValid () const { return m_IsValid; };
|
||||||
|
|
||||||
// implements RoutingDestination
|
// implements RoutingDestination
|
||||||
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
|
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
|
||||||
|
@ -60,6 +61,7 @@ namespace data
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool m_IsValid;
|
||||||
std::vector<Lease> m_Leases;
|
std::vector<Lease> m_Leases;
|
||||||
IdentityEx m_Identity;
|
IdentityEx m_Identity;
|
||||||
uint8_t m_EncryptionKey[256];
|
uint8_t m_EncryptionKey[256];
|
||||||
|
|
18
NetDb.cpp
18
NetDb.cpp
|
@ -252,12 +252,24 @@ namespace data
|
||||||
if (it != m_LeaseSets.end ())
|
if (it != m_LeaseSets.end ())
|
||||||
{
|
{
|
||||||
it->second->Update (buf, len);
|
it->second->Update (buf, len);
|
||||||
LogPrint ("LeaseSet updated");
|
if (it->second->IsValid ())
|
||||||
|
LogPrint (eLogInfo, "LeaseSet updated");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogInfo, "LeaseSet update failed");
|
||||||
|
m_LeaseSets.erase (it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint ("New LeaseSet added");
|
auto leaseSet = std::make_shared<LeaseSet> (buf, len);
|
||||||
m_LeaseSets[ident] = std::make_shared<LeaseSet> (buf, len);
|
if (leaseSet->IsValid ())
|
||||||
|
{
|
||||||
|
LogPrint (eLogInfo, "New LeaseSet added");
|
||||||
|
m_LeaseSets[ident] = leaseSet;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "New LeaseSet validation failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue