mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
don't detach ECIESx25519 session from destination
This commit is contained in:
parent
bc4a97774f
commit
b1262d54de
@ -295,7 +295,7 @@ namespace datagram
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_RoutingSession || !m_RoutingSession->GetOwner () || !m_RoutingSession->IsReadyToSend ())
|
if (!m_RoutingSession || m_RoutingSession->IsTerminated () || !m_RoutingSession->IsReadyToSend ())
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (auto& it: m_PendingRoutingSessions)
|
for (auto& it: m_PendingRoutingSessions)
|
||||||
|
@ -94,15 +94,20 @@ namespace garlic
|
|||||||
m_ItermediateSymmKeys.erase (index);
|
m_ItermediateSymmKeys.erase (index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RatchetTagSet::Expire ()
|
void ReceiveRatchetTagSet::Expire ()
|
||||||
{
|
{
|
||||||
if (!m_ExpirationTimestamp)
|
if (!m_ExpirationTimestamp)
|
||||||
m_ExpirationTimestamp = i2p::util::GetSecondsSinceEpoch () + ECIESX25519_PREVIOUS_TAGSET_EXPIRATION_TIMEOUT;
|
m_ExpirationTimestamp = i2p::util::GetSecondsSinceEpoch () + ECIESX25519_PREVIOUS_TAGSET_EXPIRATION_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ReceiveRatchetTagSet::IsExpired (uint64_t ts) const
|
||||||
|
{
|
||||||
|
return m_ExpirationTimestamp && ts > m_ExpirationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
bool ReceiveRatchetTagSet::IsIndexExpired (int index) const
|
bool ReceiveRatchetTagSet::IsIndexExpired (int index) const
|
||||||
{
|
{
|
||||||
return index < m_TrimBehindIndex || !m_Session || !m_Session->GetOwner ();
|
return index < m_TrimBehindIndex || !m_Session || m_Session->IsTerminated ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReceiveRatchetTagSet::HandleNextMessage (uint8_t * buf, size_t len, int index)
|
bool ReceiveRatchetTagSet::HandleNextMessage (uint8_t * buf, size_t len, int index)
|
||||||
|
@ -57,9 +57,6 @@ namespace garlic
|
|||||||
int GetTagSetID () const { return m_TagSetID; };
|
int GetTagSetID () const { return m_TagSetID; };
|
||||||
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
|
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
|
||||||
|
|
||||||
void Expire ();
|
|
||||||
bool IsExpired (uint64_t ts) const { return m_ExpirationTimestamp && ts > m_ExpirationTimestamp; };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
union
|
union
|
||||||
@ -77,7 +74,6 @@ namespace garlic
|
|||||||
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
|
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
|
||||||
|
|
||||||
int m_TagSetID = 0;
|
int m_TagSetID = 0;
|
||||||
uint64_t m_ExpirationTimestamp = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ECIESX25519AEADRatchetSession;
|
class ECIESX25519AEADRatchetSession;
|
||||||
@ -93,6 +89,9 @@ namespace garlic
|
|||||||
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session; };
|
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session; };
|
||||||
void SetTrimBehind (int index) { if (index > m_TrimBehindIndex) m_TrimBehindIndex = index; };
|
void SetTrimBehind (int index) { if (index > m_TrimBehindIndex) m_TrimBehindIndex = index; };
|
||||||
|
|
||||||
|
void Expire ();
|
||||||
|
bool IsExpired (uint64_t ts) const;
|
||||||
|
|
||||||
virtual bool IsIndexExpired (int index) const;
|
virtual bool IsIndexExpired (int index) const;
|
||||||
virtual bool HandleNextMessage (uint8_t * buf, size_t len, int index);
|
virtual bool HandleNextMessage (uint8_t * buf, size_t len, int index);
|
||||||
|
|
||||||
@ -101,6 +100,7 @@ namespace garlic
|
|||||||
int m_TrimBehindIndex = 0;
|
int m_TrimBehindIndex = 0;
|
||||||
std::shared_ptr<ECIESX25519AEADRatchetSession> m_Session;
|
std::shared_ptr<ECIESX25519AEADRatchetSession> m_Session;
|
||||||
bool m_IsNS;
|
bool m_IsNS;
|
||||||
|
uint64_t m_ExpirationTimestamp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DatabaseLookupTagSet: public ReceiveRatchetTagSet
|
class DatabaseLookupTagSet: public ReceiveRatchetTagSet
|
||||||
@ -171,6 +171,7 @@ namespace garlic
|
|||||||
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
||||||
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
|
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
|
||||||
|
|
||||||
|
void Terminate () { m_IsTerminated = true; }
|
||||||
void SetDestination (const i2p::data::IdentHash& dest) // TODO:
|
void SetDestination (const i2p::data::IdentHash& dest) // TODO:
|
||||||
{
|
{
|
||||||
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
|
||||||
@ -182,6 +183,7 @@ namespace garlic
|
|||||||
|
|
||||||
bool IsRatchets () const { return true; };
|
bool IsRatchets () const { return true; };
|
||||||
bool IsReadyToSend () const { return m_State != eSessionStateNewSessionSent; };
|
bool IsReadyToSend () const { return m_State != eSessionStateNewSessionSent; };
|
||||||
|
bool IsTerminated () const { return m_IsTerminated; }
|
||||||
uint64_t GetLastActivityTimestamp () const { return m_LastActivityTimestamp; };
|
uint64_t GetLastActivityTimestamp () const { return m_LastActivityTimestamp; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -221,7 +223,7 @@ namespace garlic
|
|||||||
std::shared_ptr<RatchetTagSet> m_SendTagset, m_NSRSendTagset;
|
std::shared_ptr<RatchetTagSet> m_SendTagset, m_NSRSendTagset;
|
||||||
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
|
||||||
std::list<std::pair<uint16_t, int> > m_AckRequests; // (tagsetid, index)
|
std::list<std::pair<uint16_t, int> > m_AckRequests; // (tagsetid, index)
|
||||||
bool m_SendReverseKey = false, m_SendForwardKey = false;
|
bool m_SendReverseKey = false, m_SendForwardKey = false, m_IsTerminated = false;
|
||||||
std::unique_ptr<DHRatchet> m_NextReceiveRatchet, m_NextSendRatchet;
|
std::unique_ptr<DHRatchet> m_NextReceiveRatchet, m_NextSendRatchet;
|
||||||
uint8_t m_PaddingSizes[32], m_NextPaddingSize;
|
uint8_t m_PaddingSizes[32], m_NextPaddingSize;
|
||||||
|
|
||||||
|
@ -445,9 +445,16 @@ namespace garlic
|
|||||||
|
|
||||||
void GarlicDestination::CleanUp ()
|
void GarlicDestination::CleanUp ()
|
||||||
{
|
{
|
||||||
|
for (auto it: m_Sessions)
|
||||||
|
it.second->SetOwner (nullptr);
|
||||||
m_Sessions.clear ();
|
m_Sessions.clear ();
|
||||||
m_DeliveryStatusSessions.clear ();
|
m_DeliveryStatusSessions.clear ();
|
||||||
m_Tags.clear ();
|
m_Tags.clear ();
|
||||||
|
for (auto it: m_ECIESx25519Sessions)
|
||||||
|
{
|
||||||
|
it.second->Terminate ();
|
||||||
|
it.second->SetOwner (nullptr);
|
||||||
|
}
|
||||||
m_ECIESx25519Sessions.clear ();
|
m_ECIESx25519Sessions.clear ();
|
||||||
m_ECIESx25519Tags.clear ();
|
m_ECIESx25519Tags.clear ();
|
||||||
}
|
}
|
||||||
@ -852,7 +859,7 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
if (it->second->CheckExpired (ts))
|
if (it->second->CheckExpired (ts))
|
||||||
{
|
{
|
||||||
it->second->SetOwner (nullptr);
|
it->second->Terminate ();
|
||||||
it = m_ECIESx25519Sessions.erase (it);
|
it = m_ECIESx25519Sessions.erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1077,7 +1084,7 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
if (it->second->CanBeRestarted (i2p::util::GetSecondsSinceEpoch ()))
|
if (it->second->CanBeRestarted (i2p::util::GetSecondsSinceEpoch ()))
|
||||||
{
|
{
|
||||||
it->second->SetOwner (nullptr); // detach
|
it->second->Terminate (); // detach
|
||||||
m_ECIESx25519Sessions.erase (it);
|
m_ECIESx25519Sessions.erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -115,6 +115,7 @@ namespace garlic
|
|||||||
virtual bool MessageConfirmed (uint32_t msgID);
|
virtual bool MessageConfirmed (uint32_t msgID);
|
||||||
virtual bool IsRatchets () const { return false; };
|
virtual bool IsRatchets () const { return false; };
|
||||||
virtual bool IsReadyToSend () const { return true; };
|
virtual bool IsReadyToSend () const { return true; };
|
||||||
|
virtual bool IsTerminated () const { return !GetOwner (); };
|
||||||
virtual uint64_t GetLastActivityTimestamp () const { return 0; }; // non-zero for rathets only
|
virtual uint64_t GetLastActivityTimestamp () const { return 0; }; // non-zero for rathets only
|
||||||
|
|
||||||
void SetLeaseSetUpdated ()
|
void SetLeaseSetUpdated ()
|
||||||
|
@ -764,7 +764,7 @@ namespace stream
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_RoutingSession || !m_RoutingSession->GetOwner () || !m_RoutingSession->IsReadyToSend ()) // expired and detached or new session sent
|
if (!m_RoutingSession || m_RoutingSession->IsTerminated () || !m_RoutingSession->IsReadyToSend ()) // expired and detached or new session sent
|
||||||
m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, true);
|
m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, true);
|
||||||
if (!m_CurrentOutboundTunnel && m_RoutingSession) // first message to send
|
if (!m_CurrentOutboundTunnel && m_RoutingSession) // first message to send
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user