summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer/LookupServer.h
blob: 2e42d5e290e3eaaa6ec854c60cc9f3871bd6e59e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "DNSName.h"
#include "DNSPacket.h"
#include "DNSServer.h"
#include "MulticastDNS.h"
#include <LibCore/FileWatcher.h>
#include <LibCore/Object.h>

namespace LookupServer {

class DNSAnswer;

class LookupServer final : public Core::Object {
    C_OBJECT(LookupServer);

public:
    static LookupServer& the();
    Vector<DNSAnswer> lookup(const DNSName& name, DNSRecordType record_type);

private:
    LookupServer();

    void load_etc_hosts();
    void put_in_cache(const DNSAnswer&);

    Vector<DNSAnswer> lookup(const DNSName& hostname, const String& nameserver, bool& did_get_response, DNSRecordType record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);

    RefPtr<Core::LocalServer> m_local_server;
    RefPtr<DNSServer> m_dns_server;
    RefPtr<MulticastDNS> m_mdns;
    Vector<String> m_nameservers;
    RefPtr<Core::FileWatcher> m_file_watcher;
    HashMap<DNSName, Vector<DNSAnswer>, DNSName::Traits> m_etc_hosts;
    HashMap<DNSName, Vector<DNSAnswer>, DNSName::Traits> m_lookup_cache;
};

}