| 457 | } |
| 458 | |
| 459 | void NetDbRequests::Explore (int numDestinations) |
| 460 | { |
| 461 | // new requests |
| 462 | auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); |
| 463 | auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; |
| 464 | auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; |
| 465 | bool throughTunnels = outbound && inbound; |
| 466 | |
| 467 | uint8_t randomHash[32]; |
| 468 | std::vector<i2p::tunnel::TunnelMessageBlock> msgs; |
| 469 | LogPrint (eLogInfo, "NetDbReq: Exploring new ", numDestinations, " routers ..."); |
| 470 | for (int i = 0; i < numDestinations; i++) |
| 471 | { |
| 472 | RAND_bytes (randomHash, 32); |
| 473 | auto dest = CreateRequest (randomHash, true, !throughTunnels); // exploratory |
| 474 | if (!dest) |
| 475 | { |
| 476 | LogPrint (eLogWarning, "NetDbReq: Exploratory destination is requested already"); |
| 477 | return; |
| 478 | } |
| 479 | auto floodfill = netdb.GetClosestFloodfill (randomHash, dest->GetExcludedPeers ()); |
| 480 | if (floodfill) |
| 481 | { |
| 482 | if (i2p::transport::transports.IsConnected (floodfill->GetIdentHash ())) |
| 483 | throughTunnels = false; |
| 484 | if (throughTunnels) |
| 485 | { |
| 486 | msgs.push_back (i2p::tunnel::TunnelMessageBlock |
| 487 | { |
| 488 | i2p::tunnel::eDeliveryTypeRouter, |
| 489 | floodfill->GetIdentHash (), 0, |
| 490 | CreateDatabaseStoreMsg () // tell floodfill about us |
| 491 | }); |
| 492 | msgs.push_back (i2p::tunnel::TunnelMessageBlock |
| 493 | { |
| 494 | i2p::tunnel::eDeliveryTypeRouter, |
| 495 | floodfill->GetIdentHash (), 0, |
| 496 | dest->CreateRequestMessage (floodfill, inbound) // explore |
| 497 | }); |
| 498 | } |
| 499 | else |
| 500 | i2p::transport::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ())); |
| 501 | } |
| 502 | else |
| 503 | RequestComplete (randomHash, nullptr); |
| 504 | } |
| 505 | if (throughTunnels && msgs.size () > 0) |
| 506 | outbound->SendTunnelDataMsgs (msgs); |
| 507 | } |
| 508 | |
| 509 | void NetDbRequests::ScheduleExploratory (uint64_t interval) |
| 510 | { |
nothing calls this directly
no test coverage detected