mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
fixed race condition
This commit is contained in:
parent
78fc3876e6
commit
0f3a68cd8e
@ -182,9 +182,12 @@ namespace data
|
|||||||
RouterInfo * r = new RouterInfo (buf, len);
|
RouterInfo * r = new RouterInfo (buf, len);
|
||||||
m_RouterInfos[r->GetIdentHash ()] = r;
|
m_RouterInfos[r->GetIdentHash ()] = r;
|
||||||
if (r->IsFloodfill ())
|
if (r->IsFloodfill ())
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
||||||
m_Floodfills.push_back (r);
|
m_Floodfills.push_back (r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len)
|
void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len)
|
||||||
{
|
{
|
||||||
@ -852,6 +855,7 @@ namespace data
|
|||||||
XORMetric minMetric;
|
XORMetric minMetric;
|
||||||
RoutingKey destKey = CreateRoutingKey (destination);
|
RoutingKey destKey = CreateRoutingKey (destination);
|
||||||
minMetric.SetMax ();
|
minMetric.SetMax ();
|
||||||
|
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
||||||
for (auto it: m_Floodfills)
|
for (auto it: m_Floodfills)
|
||||||
{
|
{
|
||||||
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))
|
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))
|
||||||
|
2
NetDb.h
2
NetDb.h
@ -7,6 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include "Queue.h"
|
#include "Queue.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
@ -114,6 +115,7 @@ namespace data
|
|||||||
|
|
||||||
std::map<IdentHash, LeaseSet *> m_LeaseSets;
|
std::map<IdentHash, LeaseSet *> m_LeaseSets;
|
||||||
std::map<IdentHash, RouterInfo *> m_RouterInfos;
|
std::map<IdentHash, RouterInfo *> m_RouterInfos;
|
||||||
|
mutable std::mutex m_FloodfillsMutex;
|
||||||
std::vector<RouterInfo *> m_Floodfills;
|
std::vector<RouterInfo *> m_Floodfills;
|
||||||
std::mutex m_RequestedDestinationsMutex;
|
std::mutex m_RequestedDestinationsMutex;
|
||||||
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
|
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
|
||||||
|
3
SAM.cpp
3
SAM.cpp
@ -582,6 +582,7 @@ namespace stream
|
|||||||
{
|
{
|
||||||
SAMSession session;
|
SAMSession session;
|
||||||
session.localDestination = localDestination;
|
session.localDestination = localDestination;
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
auto ret = m_Sessions.insert (std::pair<std::string, SAMSession>(id, session));
|
auto ret = m_Sessions.insert (std::pair<std::string, SAMSession>(id, session));
|
||||||
if (!ret.second)
|
if (!ret.second)
|
||||||
LogPrint ("Session ", id, " already exists");
|
LogPrint ("Session ", id, " already exists");
|
||||||
@ -592,6 +593,7 @@ namespace stream
|
|||||||
|
|
||||||
void SAMBridge::CloseSession (const std::string& id)
|
void SAMBridge::CloseSession (const std::string& id)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
auto it = m_Sessions.find (id);
|
auto it = m_Sessions.find (id);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
{
|
{
|
||||||
@ -605,6 +607,7 @@ namespace stream
|
|||||||
|
|
||||||
SAMSession * SAMBridge::FindSession (const std::string& id)
|
SAMSession * SAMBridge::FindSession (const std::string& id)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
auto it = m_Sessions.find (id);
|
auto it = m_Sessions.find (id);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
return &it->second;
|
return &it->second;
|
||||||
|
2
SAM.h
2
SAM.h
@ -6,6 +6,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "LeaseSet.h"
|
#include "LeaseSet.h"
|
||||||
@ -144,6 +145,7 @@ namespace stream
|
|||||||
boost::asio::io_service m_Service;
|
boost::asio::io_service m_Service;
|
||||||
boost::asio::ip::tcp::acceptor m_Acceptor;
|
boost::asio::ip::tcp::acceptor m_Acceptor;
|
||||||
SAMSocket * m_NewSocket;
|
SAMSocket * m_NewSocket;
|
||||||
|
std::mutex m_SessionsMutex;
|
||||||
std::map<std::string, SAMSession> m_Sessions;
|
std::map<std::string, SAMSession> m_Sessions;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user