MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / HandleDatabaseSearchReplyMsg

Method HandleDatabaseSearchReplyMsg

libi2pd/NetDbRequests.cpp:360–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358 }
359
360 void NetDbRequests::HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg)
361 {
362 const uint8_t * buf = msg->GetPayload ();
363 std::string key;
364 size_t num = buf[32]; // num
365 if (CheckLogLevel (eLogInfo))
366 key = i2p::data::ByteStreamToBase64 (buf, 32);
367 LogPrint (eLogDebug, "NetDbReq: DatabaseSearchReply for ", key, " num=", num);
368
369 IdentHash ident (buf);
370 bool isExploratory = false;
371 auto dest = FindRequest (ident);
372 if (dest && dest->IsActive ())
373 {
374 isExploratory = dest->IsExploratory ();
375 if (!isExploratory && (num > 0 || dest->GetNumAttempts () < 3)) // before 3-rd attempt might be just bad luck
376 {
377 // try to send next requests
378 if (!SendNextRequest (dest))
379 RequestComplete (ident, nullptr);
380 }
381 else
382 // no more requests for destination possible. delete it
383 RequestComplete (ident, nullptr);
384 }
385 else /*if (!m_FloodfillBootstrap)*/
386 {
387 LogPrint (eLogInfo, "NetDbReq: Unsolicited or late database search reply for ", key);
388 return;
389 }
390
391 // try responses
392 if (num > NETDB_MAX_NUM_SEARCH_REPLY_PEER_HASHES)
393 {
394 LogPrint (eLogWarning, "NetDbReq: Too many peer hashes ", num, " in database search reply, Reduced to ", NETDB_MAX_NUM_SEARCH_REPLY_PEER_HASHES);
395 num = NETDB_MAX_NUM_SEARCH_REPLY_PEER_HASHES;
396 }
397 if (isExploratory && !m_DiscoveredRouterHashes.empty ())
398 {
399 // request outstanding routers
400 for (auto it: m_DiscoveredRouterHashes)
401 RequestRouter (it);
402 m_DiscoveredRouterHashes.clear ();
403 m_DiscoveredRoutersTimer.cancel ();
404 }
405 for (size_t i = 0; i < num; i++)
406 {
407 IdentHash router (buf + 33 + i*32);
408 if (CheckLogLevel (eLogDebug))
409 LogPrint (eLogDebug, "NetDbReq: ", i, ": ", router.ToBase64 ());
410
411 if (isExploratory)
412 // postpone request
413 m_DiscoveredRouterHashes.push_back (router);
414 else
415 // send request right a way
416 RequestRouter (router);
417 }

Callers

nothing calls this directly

Calls 9

CheckLogLevelFunction · 0.85
ByteStreamToBase64Function · 0.85
LogPrintFunction · 0.85
GetNumAttemptsMethod · 0.80
ToBase64Method · 0.80
push_backMethod · 0.80
GetPayloadMethod · 0.45
IsActiveMethod · 0.45
IsExploratoryMethod · 0.45

Tested by

no test coverage detected