mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
fixed race condition
This commit is contained in:
parent
9e759a59a9
commit
5abd4021c4
@ -290,6 +290,7 @@ namespace garlic
|
|||||||
SessionDecryption * decryption = new SessionDecryption;
|
SessionDecryption * decryption = new SessionDecryption;
|
||||||
decryption->SetKey (key);
|
decryption->SetKey (key);
|
||||||
decryption->SetTagCount (1);
|
decryption->SetTagCount (1);
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
|
||||||
m_SessionTags[SessionTag(tag)] = decryption;
|
m_SessionTags[SessionTag(tag)] = decryption;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,6 +344,7 @@ namespace garlic
|
|||||||
it->second->UseTag ();
|
it->second->UseTag ();
|
||||||
HandleAESBlock (buf + 32, length - 32, it->second, msg->from);
|
HandleAESBlock (buf + 32, length - 32, it->second, msg->from);
|
||||||
if (!it->second->GetTagCount ()) delete it->second; // all tags were used
|
if (!it->second->GetTagCount ()) delete it->second; // all tags were used
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
|
||||||
m_SessionTags.erase (it); // tag might be used only once
|
m_SessionTags.erase (it); // tag might be used only once
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -377,6 +379,7 @@ namespace garlic
|
|||||||
if (tagCount > 0)
|
if (tagCount > 0)
|
||||||
{
|
{
|
||||||
decryption->AddTagCount (tagCount);
|
decryption->AddTagCount (tagCount);
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
|
||||||
for (int i = 0; i < tagCount; i++)
|
for (int i = 0; i < tagCount; i++)
|
||||||
m_SessionTags[SessionTag(buf + i*32)] = decryption;
|
m_SessionTags[SessionTag(buf + i*32)] = decryption;
|
||||||
}
|
}
|
||||||
|
1
Garlic.h
1
Garlic.h
@ -129,6 +129,7 @@ namespace garlic
|
|||||||
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
|
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
|
||||||
// incoming session
|
// incoming session
|
||||||
// multiple tags refer to one decyption
|
// multiple tags refer to one decyption
|
||||||
|
std::mutex m_SessionsTagsMutex;
|
||||||
std::map<SessionTag, SessionDecryption *> m_SessionTags; // tag -> decryption
|
std::map<SessionTag, SessionDecryption *> m_SessionTags; // tag -> decryption
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user