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

Method HandleDatabaseStoreMessage

libi2pd/Destination.cpp:380–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378 }
379
380 void LeaseSetDestination::HandleDatabaseStoreMessage (const uint8_t * buf, size_t len,
381 i2p::garlic::ECIESX25519AEADRatchetSession * from)
382 {
383 if (len < DATABASE_STORE_HEADER_SIZE)
384 {
385 LogPrint (eLogError, "Destination: Database store msg is too short ", len);
386 return;
387 }
388 uint32_t replyToken = bufbe32toh (buf + DATABASE_STORE_REPLY_TOKEN_OFFSET);
389 size_t offset = DATABASE_STORE_HEADER_SIZE;
390 if (replyToken)
391 {
392 LogPrint (eLogInfo, "Destination: Reply token is ignored for DatabaseStore");
393 offset += 36;
394 }
395 if (offset > len || len > i2p::data::MAX_LS_BUFFER_SIZE + offset)
396 {
397 LogPrint (eLogError, "Destination: Database store message is too long ", len);
398 return;
399 }
400 i2p::data::IdentHash key (buf + DATABASE_STORE_KEY_OFFSET);
401 std::shared_ptr<i2p::data::LeaseSet> leaseSet;
402 std::shared_ptr<LeaseSetRequest> request;
403 switch (buf[DATABASE_STORE_TYPE_OFFSET])
404 {
405 case i2p::data::NETDB_STORE_TYPE_LEASESET: // 1
406 case i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2: // 3
407 {
408 LogPrint (eLogDebug, "Destination: Remote LeaseSet");
409 std::lock_guard<std::mutex> lock(m_RemoteLeaseSetsMutex);
410 auto it = m_RemoteLeaseSets.find (key);
411 if (it != m_RemoteLeaseSets.end () &&
412 it->second->GetStoreType () == buf[DATABASE_STORE_TYPE_OFFSET]) // update only if same type
413 {
414 leaseSet = it->second;
415 if (leaseSet->IsNewer (buf + offset, len - offset))
416 {
417 leaseSet->Update (buf + offset, len - offset, shared_from_this(), true);
418 if (leaseSet->IsValid () && leaseSet->GetIdentHash () == key && !leaseSet->IsExpired ())
419 LogPrint (eLogDebug, "Destination: Remote LeaseSet updated");
420 else
421 {
422 LogPrint (eLogDebug, "Destination: Remote LeaseSet update failed");
423 m_RemoteLeaseSets.erase (it);
424 leaseSet = nullptr;
425 }
426 }
427 else
428 LogPrint (eLogDebug, "Destination: Remote LeaseSet is older. Not updated");
429 }
430 else
431 {
432 // add or replace
433 if (buf[DATABASE_STORE_TYPE_OFFSET] == i2p::data::NETDB_STORE_TYPE_LEASESET)
434 leaseSet = std::make_shared<i2p::data::LeaseSet> (buf + offset, len - offset); // LeaseSet
435 else
436 {
437 leaseSet = std::make_shared<i2p::data::LeaseSet2> (buf[DATABASE_STORE_TYPE_OFFSET],

Callers

nothing calls this directly

Calls 15

LogPrintFunction · 0.85
bufbe32tohFunction · 0.85
GetRemoteStaticKeyMethod · 0.80
SetDestinationMethod · 0.80
GetStoreHashMethod · 0.80
CompleteMethod · 0.80
GetStoreTypeMethod · 0.45
IsNewerMethod · 0.45
UpdateMethod · 0.45
IsValidMethod · 0.45
IsExpiredMethod · 0.45

Tested by

no test coverage detected