mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
common code for sending netdb lookup
This commit is contained in:
parent
4163542125
commit
f5b823a712
|
@ -820,57 +820,17 @@ namespace data
|
||||||
{
|
{
|
||||||
if (direct && i2p::transport::transports.RoutesRestricted ()) direct = false; // always use tunnels for restricted routes
|
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
|
auto dest = m_Requests->CreateRequest (destination, false, direct, requestComplete); // non-exploratory
|
||||||
if (!dest)
|
if (dest)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already or cached");
|
if (!m_Requests->SendNextRequest (dest))
|
||||||
return;
|
m_Requests->RequestComplete (destination, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
|
||||||
if (floodfill)
|
|
||||||
{
|
|
||||||
if (direct && !floodfill->IsReachableFrom (i2p::context.GetRouterInfo ()) &&
|
|
||||||
!i2p::transport::transports.IsConnected (floodfill->GetIdentHash ()))
|
|
||||||
direct = false; // floodfill can't be reached directly
|
|
||||||
if (direct)
|
|
||||||
{
|
|
||||||
if (CheckLogLevel (eLogDebug))
|
|
||||||
LogPrint (eLogDebug, "NetDb: Request ", dest->GetDestination ().ToBase64 (), " at ", floodfill->GetIdentHash ().ToBase64 (), " directly");
|
|
||||||
auto msg = dest->CreateRequestMessage (floodfill->GetIdentHash ());
|
|
||||||
msg->onDrop = [this, dest]() { if (dest->IsActive ()) this->m_Requests->SendNextRequest (dest); };
|
|
||||||
transports.SendMessage (floodfill->GetIdentHash (), msg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
|
||||||
auto outbound = pool ? pool->GetNextOutboundTunnel (nullptr, floodfill->GetCompatibleTransports (false)) : nullptr;
|
|
||||||
auto inbound = pool ? pool->GetNextInboundTunnel (nullptr, floodfill->GetCompatibleTransports (true)) : nullptr;
|
|
||||||
if (outbound && inbound)
|
|
||||||
{
|
|
||||||
if (CheckLogLevel (eLogDebug))
|
|
||||||
LogPrint (eLogDebug, "NetDb: Request ", dest->GetDestination ().ToBase64 (), " at ", floodfill->GetIdentHash ().ToBase64 (), " through tunnels");
|
|
||||||
auto msg = dest->CreateRequestMessage (floodfill, inbound);
|
|
||||||
msg->onDrop = [this, dest]() { if (dest->IsActive ()) this->m_Requests->SendNextRequest (dest); };
|
|
||||||
outbound->SendTunnelDataMsgTo (floodfill->GetIdentHash (), 0,
|
|
||||||
i2p::garlic::WrapECIESX25519MessageForRouter (msg, floodfill->GetIdentity ()->GetEncryptionPublicKey ()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrint (eLogError, "NetDb: ", destination.ToBase64(), " destination requested, but no tunnels found");
|
|
||||||
m_Requests->RequestComplete (destination, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already or cached");
|
||||||
LogPrint (eLogError, "NetDb: ", destination.ToBase64(), " destination requested, but no floodfills found");
|
|
||||||
m_Requests->RequestComplete (destination, nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete)
|
void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete)
|
||||||
{
|
{
|
||||||
|
|
||||||
auto dest = m_Requests->CreateRequest (destination, exploratory, true, requestComplete); // non-exploratory
|
auto dest = m_Requests->CreateRequest (destination, exploratory, true, requestComplete); // non-exploratory
|
||||||
if (!dest)
|
if (!dest)
|
||||||
{
|
{
|
||||||
|
@ -1045,8 +1005,11 @@ namespace data
|
||||||
if (dest && dest->IsActive ())
|
if (dest && dest->IsActive ())
|
||||||
{
|
{
|
||||||
if (!dest->IsExploratory () && (num > 0 || dest->GetNumExcludedPeers () < 3)) // before 3-rd attempt might be just bad luck
|
if (!dest->IsExploratory () && (num > 0 || dest->GetNumExcludedPeers () < 3)) // before 3-rd attempt might be just bad luck
|
||||||
|
{
|
||||||
// try to send next requests
|
// try to send next requests
|
||||||
m_Requests->SendNextRequest (dest);
|
if (!m_Requests->SendNextRequest (dest))
|
||||||
|
m_Requests->RequestComplete (ident, nullptr);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
// no more requests for destination possible. delete it
|
// no more requests for destination possible. delete it
|
||||||
m_Requests->RequestComplete (ident, nullptr);
|
m_Requests->RequestComplete (ident, nullptr);
|
||||||
|
|
|
@ -284,13 +284,13 @@ namespace data
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = false;
|
ret = false;
|
||||||
if (!nextFloodfill) LogPrint (eLogWarning, "NetDbReq: No more floodfills");
|
LogPrint (eLogWarning, "NetDbReq: No more floodfills for ", dest->GetDestination ().ToBase64 (), " after ", count, "attempts");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!dest->IsExploratory ())
|
if (!dest->IsExploratory ())
|
||||||
LogPrint (eLogWarning, "NetDbReq: ", dest->GetDestination ().ToBase64 (), " not found after 7 attempts");
|
LogPrint (eLogWarning, "NetDbReq: ", dest->GetDestination ().ToBase64 (), " not found after ", MAX_NUM_REQUEST_ATTEMPTS," attempts");
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue