|
|
@ -650,56 +650,57 @@ namespace client |
|
|
|
LogPrint (eLogError, "Addressbook: Can't resolve ", url.host); |
|
|
|
LogPrint (eLogError, "Addressbook: Can't resolve ", url.host); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* this code block still needs some love */ |
|
|
|
/* all code below till end of function is subject of refacroring */ |
|
|
|
std::condition_variable newDataReceived; |
|
|
|
bool success = false; |
|
|
|
std::mutex newDataReceivedMutex; |
|
|
|
if (!m_Etag.length ()) |
|
|
|
auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident); |
|
|
|
{ |
|
|
|
if (!leaseSet) |
|
|
|
// load ETag
|
|
|
|
{ |
|
|
|
m_Book.GetEtag (ident, m_Etag, m_LastModified); |
|
|
|
std::unique_lock<std::mutex> l(newDataReceivedMutex); |
|
|
|
LogPrint (eLogInfo, "Addressbook: set ", m_Link, " ETag: ", m_Etag, " Last-Modified: ", m_LastModified); |
|
|
|
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (ident, |
|
|
|
} |
|
|
|
[&newDataReceived, &leaseSet](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
std::condition_variable newDataReceived; |
|
|
|
{ |
|
|
|
std::mutex newDataReceivedMutex; |
|
|
|
leaseSet = ls; |
|
|
|
auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (ident); |
|
|
|
newDataReceived.notify_all (); |
|
|
|
if (!leaseSet) |
|
|
|
}); |
|
|
|
|
|
|
|
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(newDataReceivedMutex); |
|
|
|
LogPrint (eLogError, "Addressbook: Subscription LeaseSet request timeout expired"); |
|
|
|
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (ident, |
|
|
|
i2p::client::context.GetSharedLocalDestination ()->CancelDestinationRequest (ident); |
|
|
|
[&newDataReceived, &leaseSet](std::shared_ptr<i2p::data::LeaseSet> ls) |
|
|
|
return; |
|
|
|
{ |
|
|
|
|
|
|
|
leaseSet = ls; |
|
|
|
|
|
|
|
newDataReceived.notify_all (); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "Addressbook: Subscription LeaseSet request timeout expired"); |
|
|
|
|
|
|
|
i2p::client::context.GetSharedLocalDestination ()->CancelDestinationRequest (ident); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (leaseSet) |
|
|
|
} |
|
|
|
{ |
|
|
|
if (!leaseSet) { |
|
|
|
std::stringstream request, response; |
|
|
|
/* still no leaseset found */ |
|
|
|
std::string host = url.host; |
|
|
|
LogPrint (eLogError, "Addressbook: LeaseSet for address ", url.host, " not found"); |
|
|
|
int port = url.port ? url.port : 80; |
|
|
|
return; |
|
|
|
/* make relative url */ |
|
|
|
} |
|
|
|
url.schema = ""; |
|
|
|
if (m_Etag.empty() && m_LastModified.empty()) { |
|
|
|
url.host = ""; |
|
|
|
m_Book.GetEtag (ident, m_Etag, m_LastModified); |
|
|
|
// standard header
|
|
|
|
LogPrint (eLogDebug, "Addressbook: loaded for ", url.host, ": ETag: ", m_Etag, ", Last-Modified: ", m_LastModified); |
|
|
|
request << "GET " << url.to_string() << " HTTP/1.1\r\n" |
|
|
|
} |
|
|
|
<< "Host: " << url.host << "\r\n" |
|
|
|
/* save url parts for later use */ |
|
|
|
<< "Accept: */*\r\n" |
|
|
|
std::string dest_host = url.host; |
|
|
|
<< "User-Agent: Wget/1.11.4\r\n" |
|
|
|
int dest_port = url.port ? url.port : 80; |
|
|
|
//<< "Accept-Encoding: gzip\r\n"
|
|
|
|
/* create http request & send it */ |
|
|
|
<< "X-Accept-Encoding: x-i2p-gzip;q=1.0, identity;q=0.5, deflate;q=0, gzip;q=0, *;q=0\r\n" |
|
|
|
i2p::http::HTTPReq req; |
|
|
|
<< "Connection: close\r\n"; |
|
|
|
req.add_header("Host", dest_host); |
|
|
|
if (m_Etag.length () > 0) // etag
|
|
|
|
req.add_header("User-Agent", "Wget/1.11.4"); |
|
|
|
request << i2p::util::http::IF_NONE_MATCH << ": " << m_Etag << "\r\n"; |
|
|
|
req.add_header("Connection", "close"); |
|
|
|
if (m_LastModified.length () > 0) // if-modfief-since
|
|
|
|
if (!m_Etag.empty()) |
|
|
|
request << i2p::util::http::IF_MODIFIED_SINCE << ": " << m_LastModified << "\r\n"; |
|
|
|
req.add_header("If-None-Match", m_Etag); |
|
|
|
request << "\r\n"; // end of header
|
|
|
|
if (!m_LastModified.empty()) |
|
|
|
auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (leaseSet, port); |
|
|
|
req.add_header("If-Modified-Since", m_LastModified); |
|
|
|
stream->Send ((uint8_t *)request.str ().c_str (), request.str ().length ()); |
|
|
|
/* convert url to relative */ |
|
|
|
|
|
|
|
url.schema = ""; |
|
|
|
|
|
|
|
url.host = ""; |
|
|
|
|
|
|
|
req.uri = url.to_string(); |
|
|
|
|
|
|
|
auto stream = i2p::client::context.GetSharedLocalDestination ()->CreateStream (leaseSet, dest_port); |
|
|
|
|
|
|
|
std::string request = req.to_string(); |
|
|
|
|
|
|
|
stream->Send ((const uint8_t *) request.data(), request.length()); |
|
|
|
|
|
|
|
/* all code below till end of function is subject of refacroring */ |
|
|
|
|
|
|
|
bool success = false; |
|
|
|
|
|
|
|
std::stringstream response; |
|
|
|
|
|
|
|
|
|
|
|
uint8_t buf[4096]; |
|
|
|
uint8_t buf[4096]; |
|
|
|
bool end = false; |
|
|
|
bool end = false; |
|
|
@ -778,9 +779,6 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogWarning, "Adressbook: HTTP response ", status); |
|
|
|
LogPrint (eLogWarning, "Adressbook: HTTP response ", status); |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "Addressbook: address ", url.host, " not found"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!success) |
|
|
|
if (!success) |
|
|
|
LogPrint (eLogError, "Addressbook: download hosts.txt from ", m_Link, " failed"); |
|
|
|
LogPrint (eLogError, "Addressbook: download hosts.txt from ", m_Link, " failed"); |
|
|
|