1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 21:27:34 +00:00

LookupServer: Track the receive timestamp for DNS answers

This commit is contained in:
Gunnar Beutner 2021-05-09 16:47:51 +02:00 committed by Andreas Kling
parent 3304d675e1
commit edb21e02ea
2 changed files with 4 additions and 6 deletions

View file

@ -18,15 +18,12 @@ DNSAnswer::DNSAnswer(const DNSName& name, DNSRecordType type, DNSRecordClass cla
, m_record_data(record_data) , m_record_data(record_data)
, m_mdns_cache_flush(mdns_cache_flush) , m_mdns_cache_flush(mdns_cache_flush)
{ {
auto now = time(nullptr); time(&m_received_time);
m_expiration_time = now + m_ttl;
if (m_expiration_time < now)
m_expiration_time = 0;
} }
bool DNSAnswer::has_expired() const bool DNSAnswer::has_expired() const
{ {
return time(nullptr) >= m_expiration_time; return time(nullptr) >= m_received_time + m_ttl;
} }
} }

View file

@ -40,6 +40,7 @@ public:
DNSRecordClass class_code() const { return m_class_code; } DNSRecordClass class_code() const { return m_class_code; }
u16 raw_class_code() const { return (u16)m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); } u16 raw_class_code() const { return (u16)m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); }
u32 ttl() const { return m_ttl; } u32 ttl() const { return m_ttl; }
time_t received_time() const { return m_received_time; }
const String& record_data() const { return m_record_data; } const String& record_data() const { return m_record_data; }
bool mdns_cache_flush() const { return m_mdns_cache_flush; } bool mdns_cache_flush() const { return m_mdns_cache_flush; }
@ -50,7 +51,7 @@ private:
DNSRecordType m_type { 0 }; DNSRecordType m_type { 0 };
DNSRecordClass m_class_code { 0 }; DNSRecordClass m_class_code { 0 };
u32 m_ttl { 0 }; u32 m_ttl { 0 };
time_t m_expiration_time { 0 }; time_t m_received_time { 0 };
String m_record_data; String m_record_data;
bool m_mdns_cache_flush { false }; bool m_mdns_cache_flush { false };
}; };