Browse Source

request destination in netdb requests thread

pull/2072/head
orignal 6 months ago
parent
commit
b75e418879
  1. 10
      libi2pd/NetDb.cpp
  2. 23
      libi2pd/NetDbRequests.cpp
  3. 2
      libi2pd/NetDbRequests.h

10
libi2pd/NetDb.cpp

@ -807,14 +807,10 @@ namespace data @@ -807,14 +807,10 @@ namespace data
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete, bool direct)
{
if (direct && i2p::transport::transports.RoutesRestricted ()) direct = false; // always use tunnels for restricted routes
auto dest = m_Requests->CreateRequest (destination, false, direct, requestComplete); // non-exploratory
if (dest)
{
if (!m_Requests->SendNextRequest (dest))
m_Requests->RequestComplete (destination, nullptr);
}
if (m_Requests)
m_Requests->PostRequestDestination (destination, requestComplete, direct);
else
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already or cached");
LogPrint (eLogError, "NetDb: Requests is null");
}
void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete)

23
libi2pd/NetDbRequests.cpp

@ -405,7 +405,7 @@ namespace data @@ -405,7 +405,7 @@ namespace data
/* if(m_FloodfillBootstrap)
RequestDestinationFrom(router, m_FloodfillBootstrap->GetIdentHash(), true);
else */if (!IsRouterBanned (router))
netdb.RequestDestination (router);
RequestDestination (router, nullptr, true);
else
LogPrint (eLogDebug, "NetDbReq: Router ", peerHash, " is banned. Skipped");
}
@ -413,5 +413,26 @@ namespace data @@ -413,5 +413,26 @@ namespace data
LogPrint (eLogDebug, "NetDbReq: [:|||:]");
}
}
void NetDbRequests::PostRequestDestination (const IdentHash& destination,
const RequestedDestination::RequestComplete& requestComplete, bool direct)
{
GetIOService ().post ([this, destination, requestComplete, direct]()
{
RequestDestination (destination, requestComplete, direct);
});
}
void NetDbRequests::RequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct)
{
auto dest = CreateRequest (destination, false, direct, requestComplete); // non-exploratory
if (dest)
{
if (!SendNextRequest (dest))
RequestComplete (destination, nullptr);
}
else
LogPrint (eLogWarning, "NetDbReq: Destination ", destination.ToBase64(), " is requested already or cached");
}
}
}

2
libi2pd/NetDbRequests.h

@ -86,10 +86,12 @@ namespace data @@ -86,10 +86,12 @@ namespace data
bool SendNextRequest (std::shared_ptr<RequestedDestination> dest);
void PostDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
void PostRequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct);
private:
void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
void RequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct);
void ManageRequests ();
// timer
void ScheduleManageRequests ();

Loading…
Cancel
Save