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

View File

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

View File

@ -43,8 +43,8 @@ int main() {
auto begin = chrono::system_clock::now(); auto begin = chrono::system_clock::now();
for(int i = 0; i < 1; i++) { for(int i = 0; i < 1; i++) {
cr(resolver, { cr(resolver, {
"alex.ts3clan.pp.ua", "ttesting.ts3index.com", //alex.ts3clan.pp.ua
9922 9987
}, [begin](bool success, auto data) { }, [begin](bool success, auto data) {
auto end = chrono::system_clock::now(); auto end = chrono::system_clock::now();
cout << "Success: " << success << " Time: " << chrono::ceil<chrono::milliseconds>(end - begin).count() << "ms" << endl; 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); 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) { 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(error == Resolver::ResultState::SUCCESS) {
if(response == "404") if(response == "404") {
callback(false, "no record found for " + query); callback(false, "no record found for " + query);
else { } else {
std::string host{response}; std::string host{response};
std::string port{"$PORT"}; std::string port{"$PORT"};
@ -329,7 +329,7 @@ struct CrStatus {
this->finished |= this->try_answer(_this); //May invokes next DNS query this->finished |= this->try_answer(_this); //May invokes next DNS query
assert(this->pending > 0); 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->print_status();
this->callback(false, "no results"); this->callback(false, "no results");
this->finished = true; this->finished = true;
@ -508,17 +508,18 @@ void tc::dns::cr(Resolver& resolver, const tc::dns::ServerAddress& address, cons
status->execute_root_tsdns = { status->execute_root_tsdns = {
false, false,
[&resolver, root_domain](const std::shared_ptr<CrStatus>& status) { [&resolver, root_domain](const std::shared_ptr<CrStatus>& status) {
//std::cout << "Execute tsdns" << std::endl; std::cout << "Execute tsdns (root)" << std::endl;
status->pending++; status->pending++;
tc::dns::cr_tsdns(resolver, { tc::dns::cr_tsdns(resolver, {
root_domain, root_domain,
status->address.port status->address.port
}, [status](bool success, auto data) { }, [status](bool success, auto data) {
std::cout << "Done tsdns (root)" << std::endl;
if(success) { if(success) {
status->tsdns = {CrStatus::SUCCESS, "", std::get<ServerAddress>(data)}; status->root_tsdns = {CrStatus::SUCCESS, "", std::get<ServerAddress>(data)};
} else { } else {
status->tsdns = {CrStatus::FAILED, std::get<std::string>(data), {}}; status->root_tsdns = {CrStatus::FAILED, std::get<std::string>(data), {}};
} }
status->do_done(status); status->do_done(status);
}); });