Browse Source

fixed race condition

pull/102/head
orignal 10 years ago
parent
commit
0f3a68cd8e
  1. 4
      NetDb.cpp
  2. 2
      NetDb.h
  3. 3
      SAM.cpp
  4. 2
      SAM.h

4
NetDb.cpp

@ -182,7 +182,10 @@ namespace data @@ -182,7 +182,10 @@ namespace data
RouterInfo * r = new RouterInfo (buf, len);
m_RouterInfos[r->GetIdentHash ()] = r;
if (r->IsFloodfill ())
{
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
m_Floodfills.push_back (r);
}
}
}
@ -852,6 +855,7 @@ namespace data @@ -852,6 +855,7 @@ namespace data
XORMetric minMetric;
RoutingKey destKey = CreateRoutingKey (destination);
minMetric.SetMax ();
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
for (auto it: m_Floodfills)
{
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))

2
NetDb.h

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include <vector>
#include <string>
#include <thread>
#include <mutex>
#include <boost/filesystem.hpp>
#include "Queue.h"
#include "I2NPProtocol.h"
@ -114,6 +115,7 @@ namespace data @@ -114,6 +115,7 @@ namespace data
std::map<IdentHash, LeaseSet *> m_LeaseSets;
std::map<IdentHash, RouterInfo *> m_RouterInfos;
mutable std::mutex m_FloodfillsMutex;
std::vector<RouterInfo *> m_Floodfills;
std::mutex m_RequestedDestinationsMutex;
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;

3
SAM.cpp

@ -582,6 +582,7 @@ namespace stream @@ -582,6 +582,7 @@ namespace stream
{
SAMSession session;
session.localDestination = localDestination;
std::unique_lock<std::mutex> l(m_SessionsMutex);
auto ret = m_Sessions.insert (std::pair<std::string, SAMSession>(id, session));
if (!ret.second)
LogPrint ("Session ", id, " already exists");
@ -592,6 +593,7 @@ namespace stream @@ -592,6 +593,7 @@ namespace stream
void SAMBridge::CloseSession (const std::string& id)
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
auto it = m_Sessions.find (id);
if (it != m_Sessions.end ())
{
@ -605,6 +607,7 @@ namespace stream @@ -605,6 +607,7 @@ namespace stream
SAMSession * SAMBridge::FindSession (const std::string& id)
{
std::unique_lock<std::mutex> l(m_SessionsMutex);
auto it = m_Sessions.find (id);
if (it != m_Sessions.end ())
return &it->second;

2
SAM.h

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
#include <map>
#include <list>
#include <thread>
#include <mutex>
#include <boost/asio.hpp>
#include "Identity.h"
#include "LeaseSet.h"
@ -144,6 +145,7 @@ namespace stream @@ -144,6 +145,7 @@ namespace stream
boost::asio::io_service m_Service;
boost::asio::ip::tcp::acceptor m_Acceptor;
SAMSocket * m_NewSocket;
std::mutex m_SessionsMutex;
std::map<std::string, SAMSession> m_Sessions;
};
}

Loading…
Cancel
Save