Fixed TSDNS

This commit is contained in:
WolverinDEV 2021-02-15 19:52:14 +01:00
parent 4365b7a205
commit 2c37861acd
4 changed files with 17 additions and 14 deletions

View File

@ -234,9 +234,6 @@ void Resolver::resolve_tsdns(const char *query, const sockaddr_storage& server_a
#endif
}
event_add(request->event_write, nullptr);
event_add(request->event_read, nullptr);
{
auto seconds = chrono::floor<chrono::seconds>(timeout);
auto microseconds = chrono::ceil<chrono::microseconds>(timeout - seconds);
@ -252,6 +249,9 @@ void Resolver::resolve_tsdns(const char *query, const sockaddr_storage& server_a
this->tsdns_requests.push_back(request);
}
event_add(request->event_write, nullptr);
event_add(request->event_read, nullptr);
/* Activate the event loop */
this->event.condition.notify_one();
}
@ -269,12 +269,14 @@ void Resolver::event_tsdns_read(Resolver::tsdns_request *request) {
if(buffer_length < 0) {
#ifdef WIN32
auto error = WSAGetLastError();
if(error != WSAEWOULDBLOCK)
if(error == WSAEWOULDBLOCK) {
return;
}
request->callback(ResultState::TSDNS_CONNECTION_FAIL, -2, "read failed: " + to_string(error));
#else
if(errno == EAGAIN)
if(errno == EAGAIN) {
return;
}
request->callback(ResultState::TSDNS_CONNECTION_FAIL, -2, "read failed: " + to_string(errno) + "/" + strerror(errno));
#endif
this->destroy_tsdns_request(request);

View File

@ -72,7 +72,7 @@ namespace tc::dns {
std::string bogus;
uint8_t secure_state{0};
#else
DNSResponse(std::shared_ptr<DNSResponseData>);
explicit DNSResponse(std::shared_ptr<DNSResponseData>);
#endif
std::shared_ptr<DNSResponseData> data{nullptr};

View File

@ -43,8 +43,8 @@ int main() {
auto begin = chrono::system_clock::now();
for(int i = 0; i < 1; i++) {
cr(resolver, {
"alex.ts3clan.pp.ua",
9922
"ttesting.ts3index.com", //alex.ts3clan.pp.ua
9987
}, [begin](bool success, auto data) {
auto end = chrono::system_clock::now();
cout << "Success: " << success << " Time: " << chrono::ceil<chrono::milliseconds>(end - begin).count() << "ms" << endl;

View File

@ -268,9 +268,9 @@ void tc::dns::cr_tsdns(tc::dns::Resolver &resolver, const tc::dns::ServerAddress
std::transform(query.begin(), query.end(), query.begin(), tolower);
resolver.resolve_tsdns(query.c_str(), tsdns_address, std::chrono::seconds{5}, [callback, query, address](Resolver::ResultState::value error, int detail, const std::string& response) {
if(error == Resolver::ResultState::SUCCESS) {
if(response == "404")
if(response == "404") {
callback(false, "no record found for " + query);
else {
} else {
std::string host{response};
std::string port{"$PORT"};
@ -329,7 +329,7 @@ struct CrStatus {
this->finished |= this->try_answer(_this); //May invokes next DNS query
assert(this->pending > 0);
if(--pending == 0 && !this->finished) { //Order matters we have to decrease pensing!
if(--this->pending == 0 && !this->finished) { //Order matters we have to decrease pensing!
this->print_status();
this->callback(false, "no results");
this->finished = true;
@ -508,17 +508,18 @@ void tc::dns::cr(Resolver& resolver, const tc::dns::ServerAddress& address, cons
status->execute_root_tsdns = {
false,
[&resolver, root_domain](const std::shared_ptr<CrStatus>& status) {
//std::cout << "Execute tsdns" << std::endl;
std::cout << "Execute tsdns (root)" << std::endl;
status->pending++;
tc::dns::cr_tsdns(resolver, {
root_domain,
status->address.port
}, [status](bool success, auto data) {
std::cout << "Done tsdns (root)" << std::endl;
if(success) {
status->tsdns = {CrStatus::SUCCESS, "", std::get<ServerAddress>(data)};
status->root_tsdns = {CrStatus::SUCCESS, "", std::get<ServerAddress>(data)};
} else {
status->tsdns = {CrStatus::FAILED, std::get<std::string>(data), {}};
status->root_tsdns = {CrStatus::FAILED, std::get<std::string>(data), {}};
}
status->do_done(status);
});