Skip to content

Commit

Permalink
fixed race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Aug 25, 2014
1 parent 481b54a commit 711b4ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,16 @@ namespace garlic
if (!session)
{
session = new GarlicRoutingSession (&destination, 32);
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions[destination.GetIdentHash ()] = session;
}

I2NPMessage * ret = session->WrapSingleMessage (msg, leaseSet);
if (!session->GetNextTag ()) // tags have beed recreated
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_CreatedSessions[session->GetFirstMsgID ()] = session;
}
return ret;
}

Expand Down
2 changes: 2 additions & 0 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <list>
#include <string>
#include <thread>
#include <mutex>
#include <cryptopp/osrng.h>
#include "aes.h"
#include "I2NPProtocol.h"
Expand Down Expand Up @@ -121,6 +122,7 @@ namespace garlic
std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue;
// outgoing sessions
std::mutex m_SessionsMutex;
std::map<i2p::data::IdentHash, GarlicRoutingSession *> m_Sessions;
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
// incoming session
Expand Down

0 comments on commit 711b4ab

Please sign in to comment.