mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
check expiration of lease
This commit is contained in:
parent
68a0643310
commit
659177e2fd
@ -149,14 +149,14 @@ namespace util
|
|||||||
uint8_t destination[32];
|
uint8_t destination[32];
|
||||||
i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32);
|
i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32);
|
||||||
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
||||||
if (!leaseSet)
|
if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
|
||||||
{
|
{
|
||||||
i2p::data::netdb.RequestDestination (i2p::data::IdentHash (destination), true);
|
i2p::data::netdb.RequestDestination (i2p::data::IdentHash (destination), true);
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(10)); // wait for 10 seconds
|
std::this_thread::sleep_for (std::chrono::seconds(10)); // wait for 10 seconds
|
||||||
leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
||||||
if (!leaseSet) // still no LeaseSet
|
if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) // still no LeaseSet
|
||||||
{
|
{
|
||||||
m_Reply.content = "<html>LeaseSet not found</html>";
|
m_Reply.content = leaseSet ? "<html>Leases expired</html>" : "<html>LeaseSet not found</html>";
|
||||||
m_Reply.headers.resize(2);
|
m_Reply.headers.resize(2);
|
||||||
m_Reply.headers[0].name = "Content-Length";
|
m_Reply.headers[0].name = "Content-Length";
|
||||||
m_Reply.headers[0].value = boost::lexical_cast<std::string>(m_Reply.content.size());
|
m_Reply.headers[0].value = boost::lexical_cast<std::string>(m_Reply.content.size());
|
||||||
@ -166,6 +166,12 @@ namespace util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we found LeaseSet
|
// we found LeaseSet
|
||||||
|
if (leaseSet->HasExpiredLeases ())
|
||||||
|
{
|
||||||
|
// we should re-request LeaseSet
|
||||||
|
LogPrint ("LeaseSet re-requested");
|
||||||
|
i2p::data::netdb.RequestDestination (i2p::data::IdentHash (destination), true);
|
||||||
|
}
|
||||||
auto s = i2p::stream::CreateStream (leaseSet);
|
auto s = i2p::stream::CreateStream (leaseSet);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
|
29
LeaseSet.cpp
29
LeaseSet.cpp
@ -1,8 +1,9 @@
|
|||||||
|
#include "I2PEndian.h"
|
||||||
#include <cryptopp/dsa.h>
|
#include <cryptopp/dsa.h>
|
||||||
#include "CryptoConst.h"
|
#include "CryptoConst.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Timestamp.h"
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
#include "I2PEndian.h"
|
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
@ -44,5 +45,31 @@ namespace data
|
|||||||
if (!verifier.VerifyMessage (buf, leases - buf, leases, 40))
|
if (!verifier.VerifyMessage (buf, leases - buf, leases, 40))
|
||||||
LogPrint ("LeaseSet verification failed");
|
LogPrint ("LeaseSet verification failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Lease> LeaseSet::GetNonExpiredLeases () const
|
||||||
|
{
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
std::vector<Lease> leases;
|
||||||
|
for (auto& it: m_Leases)
|
||||||
|
if (ts < it.endDate)
|
||||||
|
leases.push_back (it);
|
||||||
|
return leases;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LeaseSet::HasExpiredLeases () const
|
||||||
|
{
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
for (auto& it: m_Leases)
|
||||||
|
if (ts >= it.endDate) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LeaseSet::HasNonExpiredLeases () const
|
||||||
|
{
|
||||||
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
|
for (auto& it: m_Leases)
|
||||||
|
if (ts < it.endDate) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,9 @@ namespace data
|
|||||||
const Identity& GetIdentity () const { return m_Identity; };
|
const Identity& GetIdentity () const { return m_Identity; };
|
||||||
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
const IdentHash& GetIdentHash () const { return m_IdentHash; };
|
||||||
const std::vector<Lease>& GetLeases () const { return m_Leases; };
|
const std::vector<Lease>& GetLeases () const { return m_Leases; };
|
||||||
|
std::vector<Lease> GetNonExpiredLeases () const;
|
||||||
|
bool HasExpiredLeases () const;
|
||||||
|
bool HasNonExpiredLeases () const;
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };
|
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };
|
||||||
bool IsDestination () const { return true; };
|
bool IsDestination () const { return true; };
|
||||||
|
|
||||||
|
@ -170,9 +170,18 @@ namespace stream
|
|||||||
CreateDataMessage (this, packet, size));
|
CreateDataMessage (this, packet, size));
|
||||||
if (m_OutboundTunnel)
|
if (m_OutboundTunnel)
|
||||||
{
|
{
|
||||||
auto& lease = m_RemoteLeaseSet->GetLeases ()[0]; // TODO:
|
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
||||||
m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg);
|
if (!leases.empty ())
|
||||||
LogPrint ("Quick Ack sent");
|
{
|
||||||
|
auto& lease = leases[0]; // TODO:
|
||||||
|
m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg);
|
||||||
|
LogPrint ("Quick Ack sent");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint ("All leases are expired");
|
||||||
|
DeleteI2NPMessage (msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DeleteI2NPMessage (msg);
|
DeleteI2NPMessage (msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user