mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
re-create local LeaseSet only if expired
This commit is contained in:
parent
2200133ce3
commit
2f5967537a
@ -56,7 +56,7 @@ namespace garlic
|
||||
}
|
||||
}
|
||||
|
||||
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet)
|
||||
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, I2NPMessage * leaseSet)
|
||||
{
|
||||
I2NPMessage * m = NewI2NPMessage ();
|
||||
size_t len = 0;
|
||||
@ -122,6 +122,8 @@ namespace garlic
|
||||
FillI2NPMessageHeader (m, eI2NPGarlic);
|
||||
if (msg)
|
||||
DeleteI2NPMessage (msg);
|
||||
if (leaseSet)
|
||||
DeleteI2NPMessage (leaseSet);
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -294,7 +296,7 @@ namespace garlic
|
||||
}
|
||||
|
||||
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination,
|
||||
I2NPMessage * msg, const I2NPMessage * leaseSet)
|
||||
I2NPMessage * msg, I2NPMessage * leaseSet)
|
||||
{
|
||||
auto it = m_Sessions.find (destination.GetIdentHash ());
|
||||
GarlicRoutingSession * session = nullptr;
|
||||
|
4
Garlic.h
4
Garlic.h
@ -45,7 +45,7 @@ namespace garlic
|
||||
GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags);
|
||||
GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption
|
||||
~GarlicRoutingSession ();
|
||||
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet);
|
||||
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, I2NPMessage * leaseSet);
|
||||
int GetNextTag () const { return m_NextTag; };
|
||||
uint32_t GetFirstMsgID () const { return m_FirstMsgID; };
|
||||
|
||||
@ -106,7 +106,7 @@ namespace garlic
|
||||
|
||||
I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg);
|
||||
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
|
||||
I2NPMessage * msg, const I2NPMessage * leaseSet = nullptr);
|
||||
I2NPMessage * msg, I2NPMessage * leaseSet = nullptr);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -209,15 +209,16 @@ namespace i2p
|
||||
return m;
|
||||
}
|
||||
|
||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet)
|
||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet)
|
||||
{
|
||||
if (!leaseSet) return nullptr;
|
||||
I2NPMessage * m = NewI2NPMessage ();
|
||||
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
|
||||
memcpy (msg->key, leaseSet.GetIdentHash (), 32);
|
||||
memcpy (msg->key, leaseSet->GetIdentHash (), 32);
|
||||
msg->type = 1; // LeaseSet
|
||||
msg->replyToken = 0;
|
||||
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet.GetBuffer (), leaseSet.GetBufferLen ());
|
||||
m->len += leaseSet.GetBufferLen () + sizeof (I2NPDatabaseStoreMsg);
|
||||
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
|
||||
m->len += leaseSet->GetBufferLen () + sizeof (I2NPDatabaseStoreMsg);
|
||||
FillI2NPMessageHeader (m, eI2NPDatabaseStore);
|
||||
return m;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ namespace tunnel
|
||||
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
|
||||
|
||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
|
||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet);
|
||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet);
|
||||
|
||||
I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
|
||||
const uint8_t * ourIdent, uint32_t receiveTunnelID,
|
||||
|
@ -156,7 +156,6 @@ namespace data
|
||||
virtual const Identity& GetIdentity () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
||||
virtual void UpdateLeaseSet () = 0; // LeaseSet must be updated
|
||||
virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0;
|
||||
};
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ namespace i2p
|
||||
void UpdateAddress (const char * host); // called from SSU
|
||||
|
||||
// implements LocalDestination
|
||||
void UpdateLeaseSet () {};
|
||||
const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
||||
const i2p::data::Identity& GetIdentity () const { return GetRouterIdentity (); };
|
||||
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };
|
||||
|
@ -281,11 +281,11 @@ namespace stream
|
||||
|
||||
bool Stream::SendPacket (const uint8_t * buf, size_t len)
|
||||
{
|
||||
const I2NPMessage * leaseSet = nullptr;
|
||||
I2NPMessage * leaseSet = nullptr;
|
||||
|
||||
if (m_LeaseSetUpdated)
|
||||
{
|
||||
leaseSet = m_LocalDestination->GetLeaseSet ();
|
||||
leaseSet = m_LocalDestination->GetLeaseSetMsg ();
|
||||
m_LeaseSetUpdated = false;
|
||||
}
|
||||
|
||||
@ -359,10 +359,9 @@ namespace stream
|
||||
|
||||
StreamingDestination::~StreamingDestination ()
|
||||
{
|
||||
if (m_LeaseSet)
|
||||
DeleteI2NPMessage (m_LeaseSet);
|
||||
if (m_Pool)
|
||||
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
|
||||
delete m_LeaseSet;
|
||||
}
|
||||
|
||||
void StreamingDestination::HandleNextPacket (Packet * packet)
|
||||
@ -402,34 +401,21 @@ namespace stream
|
||||
delete stream;
|
||||
}
|
||||
}
|
||||
|
||||
void StreamingDestination::UpdateLeaseSet ()
|
||||
{
|
||||
auto newLeaseSet = CreateLeaseSet ();
|
||||
// TODO: make it atomic
|
||||
auto oldLeaseSet = m_LeaseSet;
|
||||
m_LeaseSet = newLeaseSet;
|
||||
if (oldLeaseSet)
|
||||
DeleteI2NPMessage (oldLeaseSet);
|
||||
for (auto it: m_Streams)
|
||||
it.second->SetLeaseSetUpdated ();
|
||||
}
|
||||
|
||||
const I2NPMessage * StreamingDestination::GetLeaseSet ()
|
||||
I2NPMessage * StreamingDestination::GetLeaseSetMsg ()
|
||||
{
|
||||
if (!m_LeaseSet)
|
||||
m_LeaseSet = CreateLeaseSet ();
|
||||
else
|
||||
RenewI2NPMessageHeader (m_LeaseSet);
|
||||
return m_LeaseSet;
|
||||
}
|
||||
|
||||
I2NPMessage * StreamingDestination::CreateLeaseSet () const
|
||||
{
|
||||
// TODO: should store actual LeaseSet rather than msg
|
||||
if (!m_Pool) return nullptr;
|
||||
i2p::data::LeaseSet leaseSet(*m_Pool);
|
||||
return CreateDatabaseStoreMsg (leaseSet);
|
||||
if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ())
|
||||
{
|
||||
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
|
||||
// TODO: make it atomic
|
||||
auto oldLeaseSet = m_LeaseSet;
|
||||
m_LeaseSet = newLeaseSet;
|
||||
delete oldLeaseSet;
|
||||
for (auto it: m_Streams)
|
||||
it.second->SetLeaseSetUpdated ();
|
||||
}
|
||||
return CreateDatabaseStoreMsg (m_LeaseSet);
|
||||
}
|
||||
|
||||
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||
|
@ -124,7 +124,7 @@ namespace stream
|
||||
~StreamingDestination ();
|
||||
|
||||
const i2p::data::PrivateKeys& GetKeys () const { return m_Keys; };
|
||||
const I2NPMessage * GetLeaseSet ();
|
||||
I2NPMessage * GetLeaseSetMsg ();
|
||||
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
|
||||
|
||||
Stream * CreateNewStream (boost::asio::io_service& service, const i2p::data::LeaseSet& remote);
|
||||
@ -132,17 +132,12 @@ namespace stream
|
||||
void HandleNextPacket (Packet * packet);
|
||||
|
||||
// implements LocalDestination
|
||||
void UpdateLeaseSet ();
|
||||
const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; };
|
||||
const i2p::data::Identity& GetIdentity () const { return m_Keys.pub; };
|
||||
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
|
||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||
|
||||
private:
|
||||
|
||||
I2NPMessage * CreateLeaseSet () const;
|
||||
|
||||
private:
|
||||
|
||||
std::map<uint32_t, Stream *> m_Streams;
|
||||
@ -151,7 +146,7 @@ namespace stream
|
||||
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
|
||||
|
||||
i2p::tunnel::TunnelPool * m_Pool;
|
||||
I2NPMessage * m_LeaseSet;
|
||||
i2p::data::LeaseSet * m_LeaseSet;
|
||||
|
||||
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
|
||||
};
|
||||
|
@ -38,7 +38,6 @@ namespace tunnel
|
||||
if (it.second.second == expiredTunnel) it.second.second = nullptr;
|
||||
|
||||
}
|
||||
m_LocalDestination.UpdateLeaseSet ();
|
||||
}
|
||||
|
||||
void TunnelPool::TunnelCreated (OutboundTunnel * createdTunnel)
|
||||
|
Loading…
Reference in New Issue
Block a user