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

Method ReadStandardLS2TypeSpecificPart

libi2pd/LeaseSet.cpp:399–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397 }
398
399 size_t LeaseSet2::ReadStandardLS2TypeSpecificPart (const uint8_t * buf, size_t len,
400 std::shared_ptr<LocalDestination> dest)
401 {
402 size_t offset = 0;
403 // properties
404 if (offset + 2 > len) return 0;
405 m_Properties.CleanUp ();
406 uint16_t propertiesLen = bufbe16toh (buf + offset);
407 if (propertiesLen)
408 m_Properties.FromBuffer (buf + offset, len - offset);
409 offset += propertiesLen + 2;
410 // key sections
411 CryptoKeyType preferredKeyType = m_EncryptionType;
412 m_EncryptionType = 0;
413 bool preferredKeyFound = false;
414 if (offset + 1 > len) return 0;
415 int numKeySections = buf[offset]; offset++;
416 for (int i = 0; i < numKeySections; i++)
417 {
418 if (offset + 4 > len) return 0;
419 uint16_t keyType = bufbe16toh (buf + offset); offset += 2; // encryption key type
420 uint16_t encryptionKeyLen = bufbe16toh (buf + offset); offset += 2;
421 if (offset + encryptionKeyLen > len) return 0;
422 if (IsStoreLeases () && !preferredKeyFound) // create encryptor with leases only
423 {
424 // we pick max key type if preferred not found
425#if !OPENSSL_PQ
426 if (keyType <= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD) // skip PQ keys if not supported
427#endif
428 {
429 if ((keyType == preferredKeyType || !m_Encryptor || keyType > m_EncryptionType) &&
430 (!dest || dest->SupportsEncryptionType (keyType)))
431 {
432 auto encryptor = i2p::data::IdentityEx::CreateEncryptor (keyType, buf + offset);
433 if (encryptor)
434 {
435 m_Encryptor = encryptor; // TODO: atomic
436 m_EncryptionType = keyType;
437 if (keyType == preferredKeyType) preferredKeyFound = true;
438 }
439 }
440 }
441 }
442 offset += encryptionKeyLen;
443 }
444 // leases
445 if (offset + 1 > len) return 0;
446 int numLeases = buf[offset]; offset++;
447 auto ts = i2p::util::GetMillisecondsSinceEpoch ();
448 if (GetExpirationTime () > ts + LEASESET_EXPIRATION_TIME_THRESHOLD)
449 {
450 LogPrint (eLogWarning, "LeaseSet2: Expiration time is from future ", GetExpirationTime ()/1000LL);
451 return 0;
452 }
453 if (ts > m_PublishedTimestamp*1000LL + LEASESET_EXPIRATION_TIME_THRESHOLD)
454 {
455 LogPrint (eLogWarning, "LeaseSet2: Published time is too old ", m_PublishedTimestamp);
456 return 0;

Callers

nothing calls this directly

Calls 7

bufbe16tohFunction · 0.85
LogPrintFunction · 0.85
bufbe32tohFunction · 0.85
CleanUpMethod · 0.45
FromBufferMethod · 0.45

Tested by

no test coverage detected