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

Method HostLookupMessageHandler

libi2pd_client/I2CP.cpp:959–1015  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

957 }
958
959 void I2CPSession::HostLookupMessageHandler (const uint8_t * buf, size_t len)
960 {
961 uint16_t sessionID = bufbe16toh (buf);
962 if (sessionID == m_SessionID || sessionID == 0xFFFF) // -1 means without session
963 {
964 uint32_t requestID = bufbe32toh (buf + 2);
965 //uint32_t timeout = bufbe32toh (buf + 6);
966 i2p::data::IdentHash ident;
967 switch (buf[10])
968 {
969 case 0: // hash
970 ident = i2p::data::IdentHash (buf + 11);
971 break;
972 case 1: // address
973 {
974 auto name = i2p::util::Mapping::ExtractString (buf + 11, len - 11);
975 auto addr = i2p::client::context.GetAddressBook ().GetAddress (name);
976 if (!addr || !addr->IsIdentHash ())
977 {
978 // TODO: handle blinded addresses
979 LogPrint (eLogError, "I2CP: Address ", name, " not found");
980 SendHostReplyMessage (requestID, nullptr);
981 return;
982 }
983 else
984 ident = addr->identHash;
985 break;
986 }
987 default:
988 LogPrint (eLogError, "I2CP: Request type ", (int)buf[10], " is not supported");
989 SendHostReplyMessage (requestID, nullptr);
990 return;
991 }
992
993 std::shared_ptr<LeaseSetDestination> destination = m_Destination;
994 if(!destination) destination = i2p::client::context.GetSharedLocalDestination ();
995 if (destination)
996 {
997 auto ls = destination->FindLeaseSet (ident);
998 if (ls)
999 SendHostReplyMessage (requestID, ls->GetIdentity ());
1000 else
1001 {
1002 auto s = shared_from_this ();
1003 destination->RequestDestination (ident,
1004 [s, requestID](std::shared_ptr<i2p::data::LeaseSet> leaseSet)
1005 {
1006 s->SendHostReplyMessage (requestID, leaseSet ? leaseSet->GetIdentity () : nullptr);
1007 });
1008 }
1009 }
1010 else
1011 SendHostReplyMessage (requestID, nullptr);
1012 }
1013 else
1014 LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID);
1015 }
1016

Callers

nothing calls this directly

Calls 10

bufbe16tohFunction · 0.85
bufbe32tohFunction · 0.85
LogPrintFunction · 0.85
IsIdentHashMethod · 0.80
SendHostReplyMessageMethod · 0.80
GetAddressMethod · 0.45
FindLeaseSetMethod · 0.45
GetIdentityMethod · 0.45
RequestDestinationMethod · 0.45

Tested by

no test coverage detected