diff --git a/Identity.h b/Identity.h index ee76892b..5c93e3d6 100644 --- a/Identity.h +++ b/Identity.h @@ -171,6 +171,7 @@ namespace data virtual const uint8_t * GetEncryptionPrivateKey () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0; virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0; + virtual void SetLeaseSetUpdated () = 0; }; } } diff --git a/RouterContext.h b/RouterContext.h index 5e7a8858..943a04e1 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -33,6 +33,7 @@ namespace i2p const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); }; const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; }; void Sign (const uint8_t * buf, int len, uint8_t * signature) const; + void SetLeaseSetUpdated () {}; private: diff --git a/Streaming.cpp b/Streaming.cpp index 82e34cd2..315f513f 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -575,21 +575,29 @@ namespace stream const i2p::data::LeaseSet * StreamingDestination::GetLeaseSet () { if (!m_Pool) return nullptr; - if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ()) + if (!m_LeaseSet) + UpdateLeaseSet (); + return m_LeaseSet; + } + + void StreamingDestination::UpdateLeaseSet () + { + auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool); + if (!m_LeaseSet) + m_LeaseSet = newLeaseSet; + else { - auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool); - if (!m_LeaseSet) - m_LeaseSet = newLeaseSet; - else - { - // TODO: implement it better - *m_LeaseSet = *newLeaseSet; - delete newLeaseSet; - } - for (auto it: m_Streams) - it.second->SetLeaseSetUpdated (); + // TODO: implement it better + *m_LeaseSet = *newLeaseSet; + delete newLeaseSet; } - return m_LeaseSet; + } + + void StreamingDestination::SetLeaseSetUpdated () + { + UpdateLeaseSet (); + for (auto it: m_Streams) + it.second->SetLeaseSetUpdated (); } void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const diff --git a/Streaming.h b/Streaming.h index f0573616..94f71e2e 100644 --- a/Streaming.h +++ b/Streaming.h @@ -157,10 +157,12 @@ namespace stream 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; + void SetLeaseSetUpdated (); private: Stream * CreateNewIncomingStream (); + void UpdateLeaseSet (); private: diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 80811f1a..46859c53 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -26,6 +26,7 @@ namespace tunnel void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) { m_InboundTunnels.insert (createdTunnel); + m_LocalDestination.SetLeaseSetUpdated (); } void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel) @@ -126,6 +127,7 @@ namespace tunnel { it.second.second->SetState (eTunnelStateFailed); m_InboundTunnels.erase (it.second.second); + m_LocalDestination.SetLeaseSetUpdated (); } else it.second.second->SetState (eTunnelStateTestFailed);