| 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 |
nothing calls this directly
no test coverage detected