| 829 | } |
| 830 | |
| 831 | void SAMSocket::ProcessNamingLookup (std::string_view buf) |
| 832 | { |
| 833 | LogPrint (eLogDebug, "SAM: Naming lookup: ", buf); |
| 834 | auto params = ExtractParams (buf); |
| 835 | std::string name (params[SAM_PARAM_NAME]); |
| 836 | std::shared_ptr<const i2p::data::IdentityEx> identity; |
| 837 | std::shared_ptr<const Address> addr; |
| 838 | auto session = m_Owner.FindSession(m_ID); |
| 839 | auto dest = session == nullptr ? context.GetSharedLocalDestination() : session->GetLocalDestination (); |
| 840 | if (name == "ME") |
| 841 | SendNamingLookupReply (name, dest->GetIdentity ()); |
| 842 | else if ((identity = context.GetAddressBook ().GetFullAddress (name)) != nullptr) |
| 843 | SendNamingLookupReply (name, identity); |
| 844 | else if ((addr = context.GetAddressBook ().GetAddress (name))) |
| 845 | { |
| 846 | if (addr->IsIdentHash ()) |
| 847 | { |
| 848 | auto leaseSet = dest->FindLeaseSet (addr->identHash); |
| 849 | if (leaseSet) |
| 850 | SendNamingLookupReply (name, leaseSet->GetIdentity ()); |
| 851 | else |
| 852 | dest->RequestDestination (addr->identHash, |
| 853 | std::bind (&SAMSocket::HandleNamingLookupLeaseSetRequestComplete, |
| 854 | shared_from_this (), std::placeholders::_1, name)); |
| 855 | } |
| 856 | else |
| 857 | dest->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, |
| 858 | std::bind (&SAMSocket::HandleNamingLookupLeaseSetRequestComplete, |
| 859 | shared_from_this (), std::placeholders::_1, name)); |
| 860 | } |
| 861 | else |
| 862 | { |
| 863 | LogPrint (eLogError, "SAM: Naming failed, unknown address ", name); |
| 864 | #ifdef _MSC_VER |
| 865 | size_t len = sprintf_s (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str()); |
| 866 | #else |
| 867 | size_t len = snprintf (m_Buffer, SAM_SOCKET_BUFFER_SIZE, SAM_NAMING_REPLY_INVALID_KEY, name.c_str()); |
| 868 | #endif |
| 869 | SendMessageReply ({m_Buffer, len}, false); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | void SAMSocket::ProcessSessionAdd (std::string_view buf) |
| 874 | { |
nothing calls this directly
no test coverage detected