38 typedef int namedserverid_t;
43 const namedserverid_t NS_DEFAULT = 0;
50 friend QueryProcessor;
53 QueryProcessorThread(QueryProcessor &qp);
55 Void incActiveQueries() { m_activequeries.Increment(); }
56 Void decActiveQueries() { m_activequeries.Decrement(); }
57 int getActiveQueries() {
return m_activequeries.currCount(); }
59 virtual Dword threadProc(Void *arg);
64 static Void ares_callback( Void *arg,
int status,
int timeouts,
unsigned char *abuf,
int alen );
67 QueryProcessorThread();
68 Void wait_for_completion();
92 friend QueryProcessorThread;
95 QueryProcessor(
Cache &cache );
98 Cache &getCache() {
return m_cache; }
102 QueryProcessorThread *getQueryProcessorThread() {
return &m_qpt; }
104 Void setLocalIpAddress(
const char *address) { m_localip = address; }
105 const EIpAddress &getLocalIp() {
return m_localip; }
107 Void addNamedServer(
const char *address,
int udp_port,
int tcp_port);
108 Void removeNamedServer(
const char *address);
109 Void applyNamedServers();
114 ares_channel getChannel() {
return m_channel; }
124 QueryProcessorThread m_qpt;
125 ares_channel m_channel;
127 std::map<const char *,NamedServer> m_servers;
134 #define SAVED_QUERY_TYPE "type" 135 #define SAVED_QUERY_DOMAIN "domain" 137 const uint16_t CR_SAVEQUERIES =
EM_USER + 1;
138 const uint16_t CR_FORCEREFRESH =
EM_USER + 2;
145 CacheRefresher(
Cache &cache,
unsigned int maxconcur,
int percent,
long interval);
147 virtual Void onInit()
override;
148 virtual Void onQuit()
override;
153 const EString &queryFileName() {
return m_qfn; }
154 long querySaveFrequency() {
return m_qsf; }
156 Void loadQueries(
const char *qfn);
157 Void loadQueries(
const std::string &qfn) { loadQueries(qfn.c_str()); }
158 Void initSaveQueries(
const char *qfn,
long qsf);
159 Void saveQueries() { sendMessage(CR_SAVEQUERIES); }
160 Void forceRefresh() { sendMessage(CR_FORCEREFRESH); }
166 static Void callback(
QueryPtr q, Bool cacheHit,
const Void *data );
167 Void _submitQueries( std::list<QueryCacheKey> &keys );
168 Void _refreshQueries();
170 Void _forceRefresh();
191 friend QueryProcessor;
192 friend QueryProcessorThread;
194 friend CacheRefresher;
205 static Cache& getInstance(namedserverid_t nsid);
255 Void addNamedServer(
const char *address,
int udp_port=53,
int tcp_port=53);
258 Void removeNamedServer(
const char *address);
260 Void applyNamedServers();
263 Void setLocalIpAddress(
const char *address);
271 QueryPtr query( ns_type rtype,
const std::string &domain, Bool &cacheHit, Bool ignorecache=
false );
278 Void query( ns_type rtype,
const std::string &domain, CachedDNSQueryCallback cb,
const Void *data=NULL, Bool ignorecache=
false );
282 Void loadQueries(
const char *qfn);
289 Void initSaveQueries(
const char *qfn,
long qsf);
306 QueryPtr lookupQuery( ns_type rtype,
const std::string &domain );
307 QueryPtr lookupQuery( QueryCacheKey &qck );
309 Void identifyExpired( std::list<QueryCacheKey> &keys,
int percent );
310 Void getCacheKeys( std::list<QueryCacheKey> &keys );
316 static unsigned int m_concur;
317 static int m_percent;
318 static long m_interval;
319 static int m_querytimeout;
320 static int m_querytries;
323 CacheRefresher m_refresher;
325 namedserverid_t m_nsid;
331 #endif // #ifndef __DNSCACHE_H static Cache & getInstance()
Retrieves/creates the default Cache instance.
Definition: dnscache.h:208
base class for EThreadPrivate and EThreadPublic
Definition: etevent.h:1062
static int setRefreshPercent(int percent)
Assigns the refresh percentage value.
Definition: dnscache.h:225
static int getQueryTries()
Retrives the query "tries" (attempts) value.
Definition: dnscache.h:245
static long setRefreshInterval(long interval)
Assigns the refresh interval.
Definition: dnscache.h:233
long resetNewQueryCount()
Resets the number of new queries (not saved) to zero.
Definition: dnscache.h:301
Macros for performing CPU atomic/interlaced operations.
namedserverid_t getNamedServerId()
Retrieves the named server ID associated with this DNS cache.
Definition: dnscache.h:297
#define atomic_swap(a, b)
atomic swap - replaces a with b
Definition: eatomic.h:39
static unsigned int getRefreshConcurrent()
Retrieves the current setting of the maximum number of conncurrent DNS queries that can be performed ...
Definition: dnscache.h:212
Void loadQueries(const std::string &qfn)
Executes the DNS queries at startup from the suppoied file.
Definition: dnscache.h:285
#define EM_USER
beginning of user events
Definition: etevent.h:810
Defines the EIpAddress and EIpFilterRule classes.
Thread timer class.
Definition: etevent.h:828
Contains the definition of the DNS query related classes.
static unsigned int setRefreshConcurrent(unsigned int concur)
Sets the maximum number of conncurrent DNS queries that can be performed while refreshing the DNS cac...
Definition: dnscache.h:217
An event message that is to be sent to a thread.
Definition: etevent.h:264
static int setQueryTries(int tries)
Assigns the query "tries" (attempts) value.
Definition: dnscache.h:249
An abstract class that represents contains the threadProc() that will be run in a separate thread...
Definition: etbasic.h:53
Represents an IP address with mask.
Definition: eip.h:40
static int getRefreshPercent()
Retrieves the current refresh percentage value.
Definition: dnscache.h:221
#define DECLARE_MESSAGE_MAP()
Inserts message map declarations into the thread class.
Definition: etevent.h:1015
Defines the functionality associated with a DNS cache.
Definition: dnscache.h:189
static long getRefeshInterval()
Retrieves the refresh interval.
Definition: dnscache.h:229
Definition: dnscache.h:34
Represents a private semaphore, the semaphore data is allocated from either the stack or heap...
Definition: esynch.h:382
A private mutex (the mutex data is allocated from either the heap or stack).
Definition: esynch.h:175
static int setQueryTimeoutMS(int timeout)
Assigns the query timeout value.
Definition: dnscache.h:241
std::shared_ptr< Query > QueryPtr
A typedef to std::shared_ptr<Query>.
Definition: dnsquery.h:40
String class.
Definition: estring.h:31
Contains definitions for synchronization objects.
Encapsulates a read-write lock object.
Definition: esynch.h:507
static int getQueryTimeoutMS()
Retrieves the query timeout setting.
Definition: dnscache.h:237