| 832 | } |
| 833 | |
| 834 | void AddressBook::LookupAddress (std::string_view address) |
| 835 | { |
| 836 | std::shared_ptr<const Address> addr; |
| 837 | auto dot = address.find ('.'); |
| 838 | if (dot != std::string::npos) |
| 839 | addr = FindAddress (address.substr (dot + 1)); |
| 840 | if (!addr || !addr->IsIdentHash ()) // TODO: |
| 841 | { |
| 842 | LogPrint (eLogError, "Addressbook: Can't find domain for ", address); |
| 843 | return; |
| 844 | } |
| 845 | |
| 846 | auto dest = i2p::client::context.GetSharedLocalDestination (); |
| 847 | if (dest) |
| 848 | { |
| 849 | auto datagram = dest->GetDatagramDestination (); |
| 850 | if (datagram) |
| 851 | { |
| 852 | uint32_t nonce; |
| 853 | RAND_bytes ((uint8_t *)&nonce, 4); |
| 854 | { |
| 855 | std::unique_lock<std::mutex> l(m_LookupsMutex); |
| 856 | m_Lookups[nonce] = address; |
| 857 | } |
| 858 | LogPrint (eLogDebug, "Addressbook: Lookup of ", address, " to ", addr->identHash.ToBase32 (), " nonce=", nonce); |
| 859 | size_t len = address.length () + 9; |
| 860 | uint8_t * buf = new uint8_t[len]; |
| 861 | memset (buf, 0, 4); |
| 862 | htobe32buf (buf + 4, nonce); |
| 863 | buf[8] = address.length (); |
| 864 | memcpy (buf + 9, address.data (), address.length ()); |
| 865 | datagram->SendDatagramTo (buf, len, addr->identHash, ADDRESS_RESPONSE_DATAGRAM_PORT, ADDRESS_RESOLVER_DATAGRAM_PORT); |
| 866 | delete[] buf; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | void AddressBook::HandleLookupResponse (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) |
| 872 | { |
nothing calls this directly
no test coverage detected