diff --git a/src/Dns.cpp b/src/Dns.cpp index 2b8a4a6..c3a7aff 100644 --- a/src/Dns.cpp +++ b/src/Dns.cpp @@ -17,19 +17,7 @@ Dns::Dns() { ipv4_regex_ = std::regex("^(((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4})(:\\d+)*$"); - ipv6_regex_ = std::regex( - "^%5B(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:" - "|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[" - "0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" - "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1," - "2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" - ":((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]" - "{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-" - "9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:" - ")" - "{1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-" - "4]" - "|1{0,1}[0-9]){0,1}[0-9]))%5D(:\\d+)*$"); + ipv6_regex_ = std::regex("\\[([a-f0-9:]+:+)+[a-f0-9]+\\](:\\d+)*"); LoadHostFile(); } @@ -66,7 +54,9 @@ void Dns::AddFetchAAAARequest(struct Request *request, bool isHttps) { std::string host((char *)request->iov[2].iov_base); host = host.substr(1); std::size_t pos = host.find("/"); - host = host.substr(0, pos); + if (pos != std::string::npos) { + host = host.substr(0, pos); + } int port = 80; if (isHttps) { port = 443; @@ -122,9 +112,9 @@ void Dns::AddFetchAAAARequest(struct Request *request, bool isHttps) { } if (std::regex_match(host, ipv6_regex_)) { - pos = host.find("%5D"); + pos = host.find("]"); std::string tmp = host.substr(pos); - host = host.substr(3, pos - 3); + host = host.substr(1, pos - 1); pos = tmp.find(":"); if (pos != std::string::npos) { port = std::stoi(tmp.substr(pos + 1)); diff --git a/src/DnsSeeker.cpp b/src/DnsSeeker.cpp index caade6f..5c5914d 100644 --- a/src/DnsSeeker.cpp +++ b/src/DnsSeeker.cpp @@ -597,19 +597,18 @@ bool DnsSeeker::read8Bits(uint8_t &var, const char *const data, const int &size, return true; } -//bool DnsSeeker::read16Bits(uint16_t &var, const char *const data, - //const int &size, int &pos) { - //uint16_t t = 0; - //read16BitsRaw(t, data, size, pos); - //var = be16toh(t); - //return var; +// bool DnsSeeker::read16Bits(uint16_t &var, const char *const data, +// const int &size, int &pos) { +// uint16_t t = 0; +// read16BitsRaw(t, data, size, pos); +// var = be16toh(t); +// return var; //} bool DnsSeeker::read16Bits(uint16_t &var, const char *const data, const int &size, int &pos) { uint16_t t = 0; - if(!read16BitsRaw(t, data, size, pos)) - return false; + if (!read16BitsRaw(t, data, size, pos)) return false; var = be16toh(t); return true; } @@ -824,24 +823,25 @@ void DnsSeeker::removeQuery(const uint16_t &id, const bool &withNextDueTime) { const Query &query = queryList.at(id); if (withNextDueTime) { if (queryByNextDueTime.find(query.nextRetry) == - queryByNextDueTime.cend()) { + queryByNextDueTime.cend()) std::cerr << __FILE__ << ":" << __LINE__ << " query " << id << " not found into queryByNextDueTime: " << query.nextRetry << std::endl; - } queryByNextDueTime.erase(query.nextRetry); } - if (queryByNextDueTime.find(query.nextRetry) == queryByNextDueTime.cend()) { - Log(__FILE__, __LINE__, Log::kError) - << "query " << id - << " not found into queryListByHost: " << query.host; - } + + if (queryListByHost.find(query.host) == queryListByHost.cend()) + std::cerr << __FILE__ << ":" << __LINE__ << " query " << id + << " not found into queryListByHost: " << query.host + << " into Dns::removeQuery()" << std::endl; queryListByHost.erase(query.host); - if (queryByNextDueTime.find(query.nextRetry) == queryByNextDueTime.cend()) { - Log(__FILE__, __LINE__, Log::kError) - << "query " << id << " not found into queryList"; - } + + if (queryList.find(id) == queryList.cend()) + std::cerr << __FILE__ << ":" << __LINE__ << " query " << id + << " not found into queryList: " << id + << " into Dns::removeQuery()" << std::endl; queryList.erase(id); + if (httpInProgress > 0) httpInProgress--; } diff --git a/src/HttpClient.cpp b/src/HttpClient.cpp index e62ae91..6cdd6b2 100644 --- a/src/HttpClient.cpp +++ b/src/HttpClient.cpp @@ -18,10 +18,19 @@ bool HttpClient::HandleFetchRequest(struct Request *inner, bool ipv4) { std::string url((char *)inner->iov[2].iov_base); url = url.substr(1); std::size_t pos = url.find("/"); - std::string host = url.substr(0, pos); - std::string query = url.substr(pos); + std::string host; + std::string query; - Log(__FILE__, __LINE__, Log::kDebug) << "Requesting: " << query; + if (pos != std::string::npos) { + host = url.substr(0, pos); + query = url.substr(pos); + } else { + host = url; + query = "/"; + } + + Log(__FILE__, __LINE__, Log::kDebug) + << "Requesting: " << host << " " << query; int sock = -1; int is_connected = -1; @@ -56,7 +65,8 @@ bool HttpClient::HandleFetchRequest(struct Request *inner, bool ipv4) { Retry(inner, ipv4); return false; } else { - Log(__FILE__, __LINE__, Log::kError) << "Could not connect " << strerror(errno); + Log(__FILE__, __LINE__, Log::kError) + << "Could not connect " << strerror(errno); stream_->ReleaseErrorAllWaitingRequest(inner->resource_id, 502); } return true; @@ -87,13 +97,11 @@ bool HttpClient::HandleFetchRequest(struct Request *inner, bool ipv4) { http->iov[1].iov_len = inner->iov[2].iov_len; http->iov[1].iov_base = malloc(http->iov[1].iov_len); - memcpy(http->iov[1].iov_base, inner->iov[2].iov_base, - http->iov[1].iov_len); + memcpy(http->iov[1].iov_base, inner->iov[2].iov_base, http->iov[1].iov_len); http->iov[2].iov_len = inner->iov[4].iov_len; http->iov[2].iov_base = malloc(http->iov[2].iov_len); - memcpy(http->iov[2].iov_base, inner->iov[4].iov_base, - http->iov[2].iov_len); + memcpy(http->iov[2].iov_base, inner->iov[4].iov_base, http->iov[2].iov_len); // io_uring_prep_readv(sqe, sock, &http->iov[0], 1, 0); io_uring_prep_read(sqe, http->client_socket, http->iov[0].iov_base, @@ -108,9 +116,7 @@ void HttpClient::ReleaseSocket(struct Request *http) { Utils::ReleaseRequest(http); } -int HttpClient::PreRequest(struct Request *http, int readed) { - return readed; -} +int HttpClient::PreRequest(struct Request *http, int readed) { return readed; } int HttpClient::PostRequest(struct Request *http) { struct io_uring_sqe *sqe = io_uring_get_sqe(ring_); diff --git a/src/Utils.cpp b/src/Utils.cpp index 2680eec..a86d3c1 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -137,7 +137,6 @@ void Utils::ReleaseRequest(struct Request *request) { free(request->iov[i].iov_base); } } - std::cout<< "LAN_[" << __FILE__ << ":" << __LINE__ << "] "<< request->event_type << std::endl; free(request); }