| 935 | } |
| 936 | |
| 937 | bool AddressBookSubscription::MakeRequest () |
| 938 | { |
| 939 | i2p::http::URL url; |
| 940 | // must be run in separate thread |
| 941 | LogPrint (eLogInfo, "Addressbook: Downloading hosts database from ", m_Link); |
| 942 | if (!url.parse(m_Link)) |
| 943 | { |
| 944 | LogPrint(eLogError, "Addressbook: Failed to parse url: ", m_Link); |
| 945 | return false; |
| 946 | } |
| 947 | auto addr = m_Book.GetAddress (url.host); |
| 948 | if (!addr || !addr->IsIdentHash ()) |
| 949 | { |
| 950 | LogPrint (eLogError, "Addressbook: Can't resolve ", url.host); |
| 951 | return false; |
| 952 | } |
| 953 | else |
| 954 | m_Ident = addr->identHash; |
| 955 | // save url parts for later use |
| 956 | std::string dest_host = url.host; |
| 957 | int dest_port = url.port ? url.port : 80; |
| 958 | // try to create stream to addressbook site |
| 959 | auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (m_Ident, dest_port); |
| 960 | if (!stream) |
| 961 | { |
| 962 | LogPrint (eLogError, "Addressbook: LeaseSet for address ", url.host, " not found"); |
| 963 | return false; |
| 964 | } |
| 965 | if (m_Etag.empty() && m_LastModified.empty()) |
| 966 | { |
| 967 | m_Book.GetEtag (m_Ident, m_Etag, m_LastModified); |
| 968 | LogPrint (eLogDebug, "Addressbook: Loaded for ", url.host, ": ETag: ", m_Etag, ", Last-Modified: ", m_LastModified); |
| 969 | } |
| 970 | // create http request & send it |
| 971 | i2p::http::HTTPReq req; |
| 972 | req.AddHeader("Host", dest_host); |
| 973 | req.AddHeader("User-Agent", "Wget/1.11.4"); |
| 974 | req.AddHeader("Accept-Encoding", "gzip"); |
| 975 | req.AddHeader("X-Accept-Encoding", "x-i2p-gzip;q=1.0, identity;q=0.5, deflate;q=0, gzip;q=0, *;q=0"); |
| 976 | req.AddHeader("Connection", "close"); |
| 977 | if (!m_Etag.empty()) |
| 978 | req.AddHeader("If-None-Match", m_Etag); |
| 979 | if (!m_LastModified.empty()) |
| 980 | req.AddHeader("If-Modified-Since", m_LastModified); |
| 981 | // convert url to relative |
| 982 | url.schema = ""; |
| 983 | url.host = ""; |
| 984 | req.uri = url.to_string(); |
| 985 | req.version = "HTTP/1.1"; |
| 986 | std::string request = req.to_string(); |
| 987 | stream->Send ((const uint8_t *) request.data(), request.length()); |
| 988 | // read response |
| 989 | std::string response; |
| 990 | uint8_t recv_buf[4096]; |
| 991 | bool end = false; |
| 992 | int numAttempts = 0; |
| 993 | while (!end) |
| 994 | { |
nothing calls this directly
no test coverage detected