mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
LookupServer: Replace unused 'did_timeout' with 'did_get_response'
did_timeout is a bool& parameter of lookup() that used to be set when
the UDP connection timed out, but this behaviour was broken in e335d73
.
I replaced it with a more useful 'did_get_response' parameter that is
being set after the UDP socket connected, sent its request and got a
response - it might still be bogus data but we know the communication
was successful.
This commit is contained in:
parent
75864b5a85
commit
2440112d53
2 changed files with 11 additions and 10 deletions
|
@ -120,19 +120,18 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
|
||||||
if (auto known_host = m_etc_hosts.get(hostname); known_host.has_value()) {
|
if (auto known_host = m_etc_hosts.get(hostname); known_host.has_value()) {
|
||||||
responses.append(known_host.value());
|
responses.append(known_host.value());
|
||||||
} else if (!hostname.is_empty()) {
|
} else if (!hostname.is_empty()) {
|
||||||
bool did_timeout;
|
bool did_get_response = false;
|
||||||
int retries = 3;
|
int retries = 3;
|
||||||
do {
|
do {
|
||||||
did_timeout = false;
|
|
||||||
if (lookup_type == 'L')
|
if (lookup_type == 'L')
|
||||||
responses = lookup(hostname, did_timeout, T_A);
|
responses = lookup(hostname, did_get_response, T_A);
|
||||||
else if (lookup_type == 'R')
|
else if (lookup_type == 'R')
|
||||||
responses = lookup(hostname, did_timeout, T_PTR);
|
responses = lookup(hostname, did_get_response, T_PTR);
|
||||||
if (!did_timeout)
|
if (did_get_response)
|
||||||
break;
|
break;
|
||||||
} while (--retries);
|
} while (--retries);
|
||||||
if (did_timeout) {
|
if (!did_get_response) {
|
||||||
fprintf(stderr, "LookupServer: Out of retries :(\n");
|
fprintf(stderr, "LookupServer: Never got a response but out of retries :(\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +152,7 @@ void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, unsigned short record_type, ShouldRandomizeCase should_randomize_case)
|
Vector<String> LookupServer::lookup(const String& hostname, bool& did_get_response, unsigned short record_type, ShouldRandomizeCase should_randomize_case)
|
||||||
{
|
{
|
||||||
if (auto it = m_lookup_cache.find(hostname); it != m_lookup_cache.end()) {
|
if (auto it = m_lookup_cache.find(hostname); it != m_lookup_cache.end()) {
|
||||||
auto& cached_lookup = it->value;
|
auto& cached_lookup = it->value;
|
||||||
|
@ -199,6 +198,8 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
|
||||||
if (nrecv == 0)
|
if (nrecv == 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
did_get_response = true;
|
||||||
|
|
||||||
auto o_response = DNSResponse::from_raw_response(response_buffer, nrecv);
|
auto o_response = DNSResponse::from_raw_response(response_buffer, nrecv);
|
||||||
if (!o_response.has_value())
|
if (!o_response.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
@ -213,7 +214,7 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
|
||||||
if (response.code() == DNSResponse::Code::REFUSED) {
|
if (response.code() == DNSResponse::Code::REFUSED) {
|
||||||
if (should_randomize_case == ShouldRandomizeCase::Yes) {
|
if (should_randomize_case == ShouldRandomizeCase::Yes) {
|
||||||
// Retry with 0x20 case randomization turned off.
|
// Retry with 0x20 case randomization turned off.
|
||||||
return lookup(hostname, did_timeout, record_type, ShouldRandomizeCase::No);
|
return lookup(hostname, did_get_response, record_type, ShouldRandomizeCase::No);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void load_etc_hosts();
|
void load_etc_hosts();
|
||||||
void service_client(RefPtr<Core::LocalSocket>);
|
void service_client(RefPtr<Core::LocalSocket>);
|
||||||
Vector<String> lookup(const String& hostname, bool& did_timeout, unsigned short record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
|
Vector<String> lookup(const String& hostname, bool& did_get_response, unsigned short record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
|
||||||
|
|
||||||
struct CachedLookup {
|
struct CachedLookup {
|
||||||
DNSQuestion question;
|
DNSQuestion question;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue