changed how dns deals with cnames and recursion: remember cnames and implement recurs...
[pingcheck] / src / dns / dnscache.h
CommitLineData
96779587
CH
1/*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
13
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
16
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
19
20 Christian Herdtweck, Intra2net AG 2015
21 */
22
23#ifndef DNS_CACHE_H
24#define DNS_CACHE_H
25
26#include <map>
27
28#include <boost/shared_ptr.hpp>
29#include <boost/asio/deadline_timer.hpp>
30#include <boost/system/error_code.hpp>
31
32#include "host/pinger.h" // for IoserviceItem
33#include "dns/hostaddress.h"
34
4e7b6ff9 35typedef std::vector<HostAddress> HostAddressVec;
ad83004d
CH
36typedef std::map<std::string, HostAddressVec> ip_map_type;
37typedef std::map<std::string, std::string> cname_map_type;
96779587
CH
38
39class DnsCache
40{
41public:
42 DnsCache( const IoServiceItem &io_serv,
43 const std::string &cache_file );
44 ~DnsCache();
45
46 // accessed from ResolverBase subclasses
ad83004d
CH
47 void update(const std::string &hostname, const HostAddressVec &new_data);
48 void update(const std::string &hostname, const std::string &cname);
49 void update_ttl(const std::string &hostname, const uint32_t ttl);
50 HostAddressVec& get_ips(const std::string &hostname);
51 std::string& get_cname(const std::string &hostname);
96779587
CH
52
53// variables
54private:
ad83004d
CH
55 ip_map_type IpCache;
56 cname_map_type CnameCache;
96779587
CH
57 boost::asio::deadline_timer SaveTimer;
58 std::string CacheFile;
59 bool HasChanged;
60
61// functions
62private:
63 void schedule_save(const boost::system::error_code &error);
64 void save_to_cachefile();
65 void load_from_cachefile();
66
67};
68
69typedef boost::shared_ptr<DnsCache> DnsCacheItem;
70
71#endif
72
73// (created using vim -- the world's best text editor)
74