| 755 | } |
| 756 | |
| 757 | std::shared_ptr<GarlicRoutingSession> GarlicDestination::GetRoutingSession ( |
| 758 | std::shared_ptr<const i2p::data::RoutingDestination> destination, bool attachLeaseSet, |
| 759 | bool requestNewIfNotFound) |
| 760 | { |
| 761 | if (destination->GetEncryptionType () >= i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD) |
| 762 | { |
| 763 | if (SupportsEncryptionType (destination->GetEncryptionType ())) |
| 764 | { |
| 765 | ECIESX25519AEADRatchetSessionPtr session; |
| 766 | uint8_t staticKey[32]; |
| 767 | destination->Encrypt (nullptr, staticKey); // we are supposed to get static key |
| 768 | auto it = m_ECIESx25519Sessions.find (staticKey); |
| 769 | if (it != m_ECIESx25519Sessions.end ()) |
| 770 | { |
| 771 | session = it->second; |
| 772 | if (session->IsInactive (i2p::util::GetSecondsSinceEpoch ())) |
| 773 | { |
| 774 | LogPrint (eLogDebug, "Garlic: Session restarted"); |
| 775 | requestNewIfNotFound = true; // it's not a new session |
| 776 | session = nullptr; |
| 777 | } |
| 778 | } |
| 779 | if (!session && requestNewIfNotFound) |
| 780 | { |
| 781 | session = std::make_shared<ECIESX25519AEADRatchetSession> (this, true); |
| 782 | session->SetRemoteStaticKey (destination->GetEncryptionType (), staticKey); |
| 783 | } |
| 784 | if (session && destination->IsDestination ()) |
| 785 | session->SetDestination (destination->GetIdentHash ()); // NS or NSR |
| 786 | return session; |
| 787 | } |
| 788 | else |
| 789 | LogPrint (eLogError, "Garlic: Non-supported encryption type ", destination->GetEncryptionType ()); |
| 790 | } |
| 791 | else |
| 792 | { |
| 793 | ElGamalAESSessionPtr session; |
| 794 | { |
| 795 | std::unique_lock<std::mutex> l(m_SessionsMutex); |
| 796 | auto it = m_Sessions.find (destination->GetIdentHash ()); |
| 797 | if (it != m_Sessions.end ()) |
| 798 | session = it->second; |
| 799 | } |
| 800 | if (!session) |
| 801 | { |
| 802 | session = std::make_shared<ElGamalAESSession> (this, destination, |
| 803 | attachLeaseSet ? m_NumTags : 4, attachLeaseSet); // specified num tags for connections and 4 for LS requests |
| 804 | std::unique_lock<std::mutex> l(m_SessionsMutex); |
| 805 | m_Sessions[destination->GetIdentHash ()] = session; |
| 806 | } |
| 807 | return session; |
| 808 | } |
| 809 | return nullptr; |
| 810 | } |
| 811 | |
| 812 | void GarlicDestination::CleanupExpiredTags () |
| 813 | { |
no test coverage detected