mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-24 01:46:36 +02:00
fxied race condition
This commit is contained in:
parent
923b64eb48
commit
8492e87d29
2 changed files with 25 additions and 35 deletions
57
NetDb.cpp
57
NetDb.cpp
|
@ -453,18 +453,18 @@ namespace data
|
||||||
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete)
|
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete)
|
||||||
{
|
{
|
||||||
// request RouterInfo directly
|
// request RouterInfo directly
|
||||||
auto& dest = CreateRequestedDestination (destination, false);
|
auto dest = new RequestedDestination (destination, false); // non-exploratory
|
||||||
if (requestComplete)
|
dest->SetRequestComplete (requestComplete);
|
||||||
{
|
{
|
||||||
if (dest->IsRequestComplete ()) // if set already
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
{
|
if (!m_RequestedDestinations.insert (std::make_pair (destination,
|
||||||
|
std::unique_ptr<RequestedDestination> (dest))).second) // not inserted
|
||||||
|
{
|
||||||
LogPrint (eLogWarning, "Destination ", destination.ToBase64(), " is requested already");
|
LogPrint (eLogWarning, "Destination ", destination.ToBase64(), " is requested already");
|
||||||
requestComplete (nullptr); // TODO: implement it better
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
dest->SetRequestComplete (requestComplete);
|
|
||||||
}
|
|
||||||
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
||||||
if (floodfill)
|
if (floodfill)
|
||||||
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
||||||
|
@ -472,7 +472,8 @@ namespace data
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "No floodfills found");
|
LogPrint (eLogError, "No floodfills found");
|
||||||
dest->Fail ();
|
dest->Fail ();
|
||||||
DeleteRequestedDestination (destination);
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
|
m_RequestedDestinations.erase (destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,7 +783,16 @@ namespace data
|
||||||
for (int i = 0; i < numDestinations; i++)
|
for (int i = 0; i < numDestinations; i++)
|
||||||
{
|
{
|
||||||
rnd.GenerateBlock (randomHash, 32);
|
rnd.GenerateBlock (randomHash, 32);
|
||||||
auto& dest = CreateRequestedDestination (IdentHash (randomHash), true);
|
auto dest = new RequestedDestination (randomHash, true); // exploratory
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
|
if (!m_RequestedDestinations.insert (std::make_pair (randomHash,
|
||||||
|
std::unique_ptr<RequestedDestination> (dest))).second) // not inserted
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "Exploratory destination is requested already");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
|
auto floodfill = GetClosestFloodfill (randomHash, dest->GetExcludedPeers ());
|
||||||
if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once
|
if (floodfill && !floodfills.count (floodfill.get ())) // request floodfill only once
|
||||||
{
|
{
|
||||||
|
@ -806,7 +816,10 @@ namespace data
|
||||||
i2p::transport::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
i2p::transport::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DeleteRequestedDestination (dest->GetDestination ());
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
||||||
|
m_RequestedDestinations.erase (dest->GetDestination ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (throughTunnels && msgs.size () > 0)
|
if (throughTunnels && msgs.size () > 0)
|
||||||
outbound->SendTunnelDataMsg (msgs);
|
outbound->SendTunnelDataMsg (msgs);
|
||||||
|
@ -826,27 +839,7 @@ namespace data
|
||||||
excluded.insert (floodfill->GetIdentHash ());
|
excluded.insert (floodfill->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<RequestedDestination>& NetDb::CreateRequestedDestination (const IdentHash& dest, bool isExploratory)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
|
||||||
auto it = m_RequestedDestinations.find (dest);
|
|
||||||
if (it == m_RequestedDestinations.end ()) // not exist yet
|
|
||||||
{
|
|
||||||
auto d = new RequestedDestination (dest, isExploratory);
|
|
||||||
return m_RequestedDestinations.insert (std::make_pair (dest,
|
|
||||||
std::unique_ptr<RequestedDestination> (d))).first->second;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetDb::DeleteRequestedDestination (IdentHash ident)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
|
|
||||||
m_RequestedDestinations.erase (ident);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter () const
|
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouter () const
|
||||||
{
|
{
|
||||||
|
|
3
NetDb.h
3
NetDb.h
|
@ -104,9 +104,6 @@ namespace data
|
||||||
void ManageLeaseSets ();
|
void ManageLeaseSets ();
|
||||||
void ManageRequests ();
|
void ManageRequests ();
|
||||||
|
|
||||||
std::unique_ptr<RequestedDestination>& CreateRequestedDestination (const IdentHash& dest, bool isExploratory = false);
|
|
||||||
void DeleteRequestedDestination (IdentHash ident);
|
|
||||||
|
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue