don't detach ECIESx25519 session from destination

This commit is contained in:
orignal 2021-01-05 15:56:48 -05:00
parent bc4a97774f
commit b1262d54de
6 changed files with 29 additions and 14 deletions

View File

@ -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;
for (auto& it: m_PendingRoutingSessions)

View File

@ -94,15 +94,20 @@ namespace garlic
m_ItermediateSymmKeys.erase (index);
}
void RatchetTagSet::Expire ()
void ReceiveRatchetTagSet::Expire ()
{
if (!m_ExpirationTimestamp)
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
{
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)

View File

@ -57,9 +57,6 @@ namespace garlic
int GetTagSetID () const { return m_TagSetID; };
void SetTagSetID (int tagsetID) { m_TagSetID = tagsetID; };
void Expire ();
bool IsExpired (uint64_t ts) const { return m_ExpirationTimestamp && ts > m_ExpirationTimestamp; };
private:
union
@ -77,7 +74,6 @@ namespace garlic
std::unordered_map<int, i2p::data::Tag<32> > m_ItermediateSymmKeys;
int m_TagSetID = 0;
uint64_t m_ExpirationTimestamp = 0;
};
class ECIESX25519AEADRatchetSession;
@ -93,6 +89,9 @@ namespace garlic
std::shared_ptr<ECIESX25519AEADRatchetSession> GetSession () { return m_Session; };
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 HandleNextMessage (uint8_t * buf, size_t len, int index);
@ -101,6 +100,7 @@ namespace garlic
int m_TrimBehindIndex = 0;
std::shared_ptr<ECIESX25519AEADRatchetSession> m_Session;
bool m_IsNS;
uint64_t m_ExpirationTimestamp = 0;
};
class DatabaseLookupTagSet: public ReceiveRatchetTagSet
@ -171,6 +171,7 @@ namespace garlic
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
void SetRemoteStaticKey (const uint8_t * key) { memcpy (m_RemoteStaticKey, key, 32); }
void Terminate () { m_IsTerminated = true; }
void SetDestination (const i2p::data::IdentHash& dest) // TODO:
{
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
@ -182,6 +183,7 @@ namespace garlic
bool IsRatchets () const { return true; };
bool IsReadyToSend () const { return m_State != eSessionStateNewSessionSent; };
bool IsTerminated () const { return m_IsTerminated; }
uint64_t GetLastActivityTimestamp () const { return m_LastActivityTimestamp; };
private:
@ -221,7 +223,7 @@ namespace garlic
std::shared_ptr<RatchetTagSet> m_SendTagset, m_NSRSendTagset;
std::unique_ptr<i2p::data::IdentHash> m_Destination;// TODO: might not need it
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;
uint8_t m_PaddingSizes[32], m_NextPaddingSize;

View File

@ -445,9 +445,16 @@ namespace garlic
void GarlicDestination::CleanUp ()
{
for (auto it: m_Sessions)
it.second->SetOwner (nullptr);
m_Sessions.clear ();
m_DeliveryStatusSessions.clear ();
m_Tags.clear ();
for (auto it: m_ECIESx25519Sessions)
{
it.second->Terminate ();
it.second->SetOwner (nullptr);
}
m_ECIESx25519Sessions.clear ();
m_ECIESx25519Tags.clear ();
}
@ -852,7 +859,7 @@ namespace garlic
{
if (it->second->CheckExpired (ts))
{
it->second->SetOwner (nullptr);
it->second->Terminate ();
it = m_ECIESx25519Sessions.erase (it);
}
else
@ -1077,7 +1084,7 @@ namespace garlic
{
if (it->second->CanBeRestarted (i2p::util::GetSecondsSinceEpoch ()))
{
it->second->SetOwner (nullptr); // detach
it->second->Terminate (); // detach
m_ECIESx25519Sessions.erase (it);
}
else

View File

@ -115,6 +115,7 @@ namespace garlic
virtual bool MessageConfirmed (uint32_t msgID);
virtual bool IsRatchets () const { return false; };
virtual bool IsReadyToSend () const { return true; };
virtual bool IsTerminated () const { return !GetOwner (); };
virtual uint64_t GetLastActivityTimestamp () const { return 0; }; // non-zero for rathets only
void SetLeaseSetUpdated ()

View File

@ -764,7 +764,7 @@ namespace stream
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);
if (!m_CurrentOutboundTunnel && m_RoutingSession) // first message to send
{