diff --git a/NetDb.cpp b/NetDb.cpp index 411b381e..4aa48be4 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -182,7 +182,10 @@ namespace data RouterInfo * r = new RouterInfo (buf, len); m_RouterInfos[r->GetIdentHash ()] = r; if (r->IsFloodfill ()) + { + std::unique_lock l(m_FloodfillsMutex); m_Floodfills.push_back (r); + } } } @@ -852,6 +855,7 @@ namespace data XORMetric minMetric; RoutingKey destKey = CreateRoutingKey (destination); minMetric.SetMax (); + std::unique_lock l(m_FloodfillsMutex); for (auto it: m_Floodfills) { if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ())) diff --git a/NetDb.h b/NetDb.h index 31bd05fa..523f5c81 100644 --- a/NetDb.h +++ b/NetDb.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "Queue.h" #include "I2NPProtocol.h" @@ -114,6 +115,7 @@ namespace data std::map m_LeaseSets; std::map m_RouterInfos; + mutable std::mutex m_FloodfillsMutex; std::vector m_Floodfills; std::mutex m_RequestedDestinationsMutex; std::map m_RequestedDestinations; diff --git a/SAM.cpp b/SAM.cpp index c647e246..15733c45 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -582,6 +582,7 @@ namespace stream { SAMSession session; session.localDestination = localDestination; + std::unique_lock l(m_SessionsMutex); auto ret = m_Sessions.insert (std::pair(id, session)); if (!ret.second) LogPrint ("Session ", id, " already exists"); @@ -592,6 +593,7 @@ namespace stream void SAMBridge::CloseSession (const std::string& id) { + std::unique_lock l(m_SessionsMutex); auto it = m_Sessions.find (id); if (it != m_Sessions.end ()) { @@ -605,6 +607,7 @@ namespace stream SAMSession * SAMBridge::FindSession (const std::string& id) { + std::unique_lock l(m_SessionsMutex); auto it = m_Sessions.find (id); if (it != m_Sessions.end ()) return &it->second; diff --git a/SAM.h b/SAM.h index 883c817c..7a42ac8f 100644 --- a/SAM.h +++ b/SAM.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "Identity.h" #include "LeaseSet.h" @@ -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 m_Sessions; }; }