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];
|
||||
i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32);
|
||||
auto leaseSet = i2p::data::netdb.FindLeaseSet (destination);
|
||||
if (!leaseSet)
|
||||
if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
|
||||
{
|
||||
i2p::data::netdb.RequestDestination (i2p::data::IdentHash (destination), true);
|
||||
std::this_thread::sleep_for (std::chrono::seconds(10)); // wait for 10 seconds
|
||||
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[0].name = "Content-Length";
|
||||
m_Reply.headers[0].value = boost::lexical_cast<std::string>(m_Reply.content.size());
|
||||
@ -166,6 +166,12 @@ namespace util
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
if (s)
|
||||
{
|
||||
|
29
LeaseSet.cpp
29
LeaseSet.cpp
@ -1,8 +1,9 @@
|
||||
#include "I2PEndian.h"
|
||||
#include <cryptopp/dsa.h>
|
||||
#include "CryptoConst.h"
|
||||
#include "Log.h"
|
||||
#include "Timestamp.h"
|
||||
#include "LeaseSet.h"
|
||||
#include "I2PEndian.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
@ -44,5 +45,31 @@ namespace data
|
||||
if (!verifier.VerifyMessage (buf, leases - buf, leases, 40))
|
||||
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 IdentHash& GetIdentHash () const { return m_IdentHash; };
|
||||
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; };
|
||||
bool IsDestination () const { return true; };
|
||||
|
||||
|
@ -170,10 +170,19 @@ namespace stream
|
||||
CreateDataMessage (this, packet, size));
|
||||
if (m_OutboundTunnel)
|
||||
{
|
||||
auto& lease = m_RemoteLeaseSet->GetLeases ()[0]; // TODO:
|
||||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
|
||||
if (!leases.empty ())
|
||||
{
|
||||
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
|
||||
DeleteI2NPMessage (msg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user