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

Method ProcessNamingLookup

libi2pd_client/SAM.cpp:831–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 11

LogPrintFunction · 0.85
GetFullAddressMethod · 0.80
IsIdentHashMethod · 0.80
FindSessionMethod · 0.45
GetLocalDestinationMethod · 0.45
GetIdentityMethod · 0.45
GetAddressMethod · 0.45
FindLeaseSetMethod · 0.45
RequestDestinationMethod · 0.45

Tested by

no test coverage detected