2004-09-01 23:55:58 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cin: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
#ifndef nsHostResolver_h__
|
|
|
|
#define nsHostResolver_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "prclist.h"
|
|
|
|
#include "prnetdb.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
#include "mozilla/CondVar.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2003-10-07 09:11:41 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2012-01-21 03:14:46 +04:00
|
|
|
#include "nsIDNSListener.h"
|
2015-09-14 16:46:47 +03:00
|
|
|
#include "nsIDNSService.h"
|
2011-07-21 17:18:01 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2014-09-21 02:10:18 +04:00
|
|
|
#include "GetAddrInfo.h"
|
2012-12-24 01:08:43 +04:00
|
|
|
#include "mozilla/net/DNS.h"
|
2012-12-10 18:13:55 +04:00
|
|
|
#include "mozilla/net/DashboardTypes.h"
|
2013-02-14 19:03:51 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
class nsHostResolver;
|
|
|
|
class nsHostRecord;
|
2003-10-07 09:11:41 +04:00
|
|
|
class nsResolveHostCallback;
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2008-11-08 02:00:26 +03:00
|
|
|
#define MAX_RESOLVER_THREADS_FOR_ANY_PRIORITY 3
|
|
|
|
#define MAX_RESOLVER_THREADS_FOR_HIGH_PRIORITY 5
|
2011-10-13 02:01:24 +04:00
|
|
|
#define MAX_NON_PRIORITY_REQUESTS 150
|
|
|
|
|
2008-11-08 02:00:26 +03:00
|
|
|
#define MAX_RESOLVER_THREADS (MAX_RESOLVER_THREADS_FOR_ANY_PRIORITY + \
|
|
|
|
MAX_RESOLVER_THREADS_FOR_HIGH_PRIORITY)
|
|
|
|
|
2004-09-01 23:55:58 +04:00
|
|
|
struct nsHostKey
|
|
|
|
{
|
|
|
|
const char *host;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags;
|
|
|
|
uint16_t af;
|
2015-02-19 08:14:00 +03:00
|
|
|
const char *netInterface;
|
2017-02-14 07:25:35 +03:00
|
|
|
const char *originSuffix;
|
2004-09-01 23:55:58 +04:00
|
|
|
};
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
/**
|
2003-10-07 09:11:41 +04:00
|
|
|
* nsHostRecord - ref counted object type stored in host resolver cache.
|
2003-09-12 00:32:33 +04:00
|
|
|
*/
|
2004-09-01 23:55:58 +04:00
|
|
|
class nsHostRecord : public PRCList, public nsHostKey
|
2003-09-12 00:32:33 +04:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
public:
|
2012-07-10 18:14:01 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHostRecord)
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2003-10-07 09:11:41 +04:00
|
|
|
/* instantiates a new host record */
|
2004-09-01 23:55:58 +04:00
|
|
|
static nsresult Create(const nsHostKey *key, nsHostRecord **record);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2004-04-17 04:57:26 +04:00
|
|
|
/* a fully resolved host record has either a non-null |addr_info| or |addr|
|
|
|
|
* field. if |addr_info| is null, it implies that the |host| is an IP
|
2003-10-07 09:11:41 +04:00
|
|
|
* address literal. in which case, |addr| contains the parsed address.
|
2004-04-17 04:57:26 +04:00
|
|
|
* otherwise, if |addr_info| is non-null, then it contains one or many
|
|
|
|
* IP addresses corresponding to the given host name. if both |addr_info|
|
2003-10-07 09:11:41 +04:00
|
|
|
* and |addr| are null, then the given host has not yet been fully resolved.
|
2004-03-09 23:31:54 +03:00
|
|
|
* |af| is the address family of the record we are querying for.
|
2003-10-07 09:11:41 +04:00
|
|
|
*/
|
2004-09-01 23:55:58 +04:00
|
|
|
|
2007-12-12 00:45:42 +03:00
|
|
|
/* the lock protects |addr_info| and |addr_info_gencnt| because they
|
|
|
|
* are mutable and accessed by the resolver worker thread and the
|
|
|
|
* nsDNSService2 class. |addr| doesn't change after it has been
|
|
|
|
* assigned a value. only the resolver worker thread modifies
|
|
|
|
* nsHostRecord (and only in nsHostResolver::OnLookupComplete);
|
|
|
|
* the other threads just read it. therefore the resolver worker
|
|
|
|
* thread doesn't need to lock when reading |addr_info|.
|
|
|
|
*/
|
2011-07-21 17:18:01 +04:00
|
|
|
Mutex addr_info_lock;
|
2014-08-21 18:53:11 +04:00
|
|
|
int addr_info_gencnt; /* generation count of |addr_info| */
|
2016-09-08 01:04:07 +03:00
|
|
|
mozilla::net::AddrInfo *addr_info;
|
|
|
|
mozilla::net::NetAddr *addr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool negative; /* True if this record is a cache of a failed lookup.
|
2008-10-14 01:04:09 +04:00
|
|
|
Negative cache entries are valid just like any other
|
|
|
|
(though never for more than 60 seconds), but a use
|
|
|
|
of that negative entry forces an asynchronous refresh. */
|
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
enum ExpirationStatus {
|
|
|
|
EXP_VALID,
|
|
|
|
EXP_GRACE,
|
|
|
|
EXP_EXPIRED,
|
|
|
|
};
|
|
|
|
|
|
|
|
ExpirationStatus CheckExpiration(const mozilla::TimeStamp& now) const;
|
|
|
|
|
|
|
|
// When the record began being valid. Used mainly for bookkeeping.
|
|
|
|
mozilla::TimeStamp mValidStart;
|
|
|
|
|
|
|
|
// When the record is no longer valid (it's time of expiration)
|
|
|
|
mozilla::TimeStamp mValidEnd;
|
|
|
|
|
|
|
|
// When the record enters its grace period. This must be before mValidEnd.
|
|
|
|
// If a record is in its grace period (and not expired), it will be used
|
|
|
|
// but a request to refresh it will be made.
|
|
|
|
mozilla::TimeStamp mGraceStart;
|
|
|
|
|
|
|
|
// Convenience function for setting the timestamps above (mValidStart,
|
|
|
|
// mValidEnd, and mGraceStart). valid and grace are durations in seconds.
|
|
|
|
void SetExpiration(const mozilla::TimeStamp& now, unsigned int valid,
|
|
|
|
unsigned int grace);
|
2015-02-10 16:45:00 +03:00
|
|
|
void CopyExpirationTimesAndFlagsFrom(const nsHostRecord *aFromHostRecord);
|
2003-10-07 09:11:41 +04:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
// Checks if the record is usable (not expired and has a value)
|
|
|
|
bool HasUsableResult(const mozilla::TimeStamp& now, uint16_t queryFlags = 0) const;
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2011-07-21 17:18:01 +04:00
|
|
|
// hold addr_info_lock when calling the blacklist functions
|
2012-12-24 01:08:43 +04:00
|
|
|
bool Blacklisted(mozilla::net::NetAddr *query);
|
2011-07-21 17:18:01 +04:00
|
|
|
void ResetBlacklist();
|
2012-12-24 01:08:43 +04:00
|
|
|
void ReportUnusable(mozilla::net::NetAddr *addr);
|
2011-07-21 17:18:01 +04:00
|
|
|
|
2013-11-25 03:24:12 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
enum DnsPriority {
|
|
|
|
DNS_PRIORITY_LOW,
|
|
|
|
DNS_PRIORITY_MEDIUM,
|
|
|
|
DNS_PRIORITY_HIGH,
|
|
|
|
};
|
|
|
|
static DnsPriority GetPriority(uint16_t aFlags);
|
|
|
|
|
2014-10-14 01:07:00 +04:00
|
|
|
bool RemoveOrRefresh(); // Mark records currently being resolved as needed
|
|
|
|
// to resolve again.
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
private:
|
2003-10-07 09:11:41 +04:00
|
|
|
friend class nsHostResolver;
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
|
2003-10-26 02:48:33 +03:00
|
|
|
PRCList callbacks; /* list of callbacks */
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool resolving; /* true if this record is being resolved, which means
|
2003-10-26 02:48:33 +03:00
|
|
|
* that it is either on the pending queue or owned by
|
2013-11-25 03:24:12 +04:00
|
|
|
* one of the worker threads. */
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool onQueue; /* true if pending and on the queue (not yet given to getaddrinfo())*/
|
|
|
|
bool usingAnyThread; /* true if off queue and contributing to mActiveAnyThreadCount */
|
2013-07-20 02:40:00 +04:00
|
|
|
bool mDoomed; /* explicitly expired */
|
2003-10-07 09:11:41 +04:00
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
#if TTL_AVAILABLE
|
|
|
|
bool mGetTtl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The number of times ReportUnusable() has been called in the record's
|
|
|
|
// lifetime.
|
|
|
|
uint32_t mBlacklistedCount;
|
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
// when the results from this resolve is returned, it is not to be
|
|
|
|
// trusted, but instead a new resolve must be made!
|
|
|
|
bool mResolveAgain;
|
|
|
|
|
2011-07-21 17:18:01 +04:00
|
|
|
// a list of addresses associated with this record that have been reported
|
|
|
|
// as unusable. the list is kept as a set of strings to make it independent
|
|
|
|
// of gencnt.
|
|
|
|
nsTArray<nsCString> mBlacklistedItems;
|
|
|
|
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit nsHostRecord(const nsHostKey *key); /* use Create() instead */
|
2003-10-07 09:11:41 +04:00
|
|
|
~nsHostRecord();
|
2003-09-12 00:32:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ResolveHost callback object. It's PRCList members are used by
|
|
|
|
* the nsHostResolver and should not be used by anything else.
|
|
|
|
*/
|
2003-10-07 09:11:41 +04:00
|
|
|
class NS_NO_VTABLE nsResolveHostCallback : public PRCList
|
2003-09-12 00:32:33 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2003-10-07 09:11:41 +04:00
|
|
|
* OnLookupComplete
|
|
|
|
*
|
|
|
|
* this function is called to complete a host lookup initiated by
|
|
|
|
* nsHostResolver::ResolveHost. it may be invoked recursively from
|
|
|
|
* ResolveHost or on an unspecified background thread.
|
2003-09-12 00:32:33 +04:00
|
|
|
*
|
2003-10-07 09:11:41 +04:00
|
|
|
* NOTE: it is the responsibility of the implementor of this method
|
|
|
|
* to handle the callback in a thread safe manner.
|
2003-09-12 00:32:33 +04:00
|
|
|
*
|
|
|
|
* @param resolver
|
|
|
|
* nsHostResolver object associated with this result
|
2003-10-07 09:11:41 +04:00
|
|
|
* @param record
|
|
|
|
* the host record containing the results of the lookup
|
2003-09-12 00:32:33 +04:00
|
|
|
* @param status
|
2003-10-07 09:11:41 +04:00
|
|
|
* if successful, |record| contains non-null results
|
2003-09-12 00:32:33 +04:00
|
|
|
*/
|
|
|
|
virtual void OnLookupComplete(nsHostResolver *resolver,
|
2003-10-07 09:11:41 +04:00
|
|
|
nsHostRecord *record,
|
|
|
|
nsresult status) = 0;
|
2012-01-21 03:14:46 +04:00
|
|
|
/**
|
|
|
|
* EqualsAsyncListener
|
|
|
|
*
|
|
|
|
* Determines if the listener argument matches the listener member var.
|
|
|
|
* For subclasses not implementing a member listener, should return false.
|
|
|
|
* For subclasses having a member listener, the function should check if
|
|
|
|
* they are the same. Used for cases where a pointer to an object
|
|
|
|
* implementing nsResolveHostCallback is unknown, but a pointer to
|
|
|
|
* the original listener is known.
|
|
|
|
*
|
|
|
|
* @param aListener
|
|
|
|
* nsIDNSListener object associated with the original request
|
|
|
|
*/
|
|
|
|
virtual bool EqualsAsyncListener(nsIDNSListener *aListener) = 0;
|
2013-11-25 03:24:12 +04:00
|
|
|
|
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf) const = 0;
|
2003-09-12 00:32:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2003-10-07 09:11:41 +04:00
|
|
|
* nsHostResolver - an asynchronous host name resolver.
|
2003-09-12 00:32:33 +04:00
|
|
|
*/
|
|
|
|
class nsHostResolver
|
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
typedef mozilla::CondVar CondVar;
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
public:
|
2003-10-07 09:11:41 +04:00
|
|
|
/**
|
|
|
|
* host resolver instances are reference counted.
|
|
|
|
*/
|
2012-07-10 18:14:01 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHostResolver)
|
2003-10-07 09:11:41 +04:00
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
/**
|
|
|
|
* creates an addref'd instance of a nsHostResolver object.
|
|
|
|
*/
|
2014-09-21 02:10:18 +04:00
|
|
|
static nsresult Create(uint32_t maxCacheEntries, // zero disables cache
|
|
|
|
uint32_t defaultCacheEntryLifetime, // seconds
|
|
|
|
uint32_t defaultGracePeriod, // seconds
|
2003-09-12 00:32:33 +04:00
|
|
|
nsHostResolver **resolver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* puts the resolver in the shutdown state, which will cause any pending
|
|
|
|
* callbacks to be detached. any future calls to ResolveHost will fail.
|
|
|
|
*/
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
/**
|
2017-02-14 07:25:35 +03:00
|
|
|
* resolve the given hostname and originAttributes asynchronously. the caller
|
|
|
|
* can synthesize a synchronous host lookup using a lock and a cvar. as noted
|
|
|
|
* above the callback will occur re-entrantly from an unspecified thread. the
|
|
|
|
* host lookup cannot be canceled (cancelation can be layered above this by
|
|
|
|
* having the callback implementation return without doing anything).
|
2003-09-12 00:32:33 +04:00
|
|
|
*/
|
2017-02-14 07:25:35 +03:00
|
|
|
nsresult ResolveHost(const char *hostname,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
|
|
|
uint16_t flags,
|
|
|
|
uint16_t af,
|
|
|
|
const char *netInterface,
|
|
|
|
nsResolveHostCallback *callback);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* removes the specified callback from the nsHostRecord for the given
|
2017-02-14 07:25:35 +03:00
|
|
|
* hostname, originAttributes, flags, and address family. these parameters
|
|
|
|
* should correspond to the parameters passed to ResolveHost. this function
|
|
|
|
* executes the callback if the callback is still pending with the given status.
|
2003-09-12 00:32:33 +04:00
|
|
|
*/
|
2017-02-14 07:25:35 +03:00
|
|
|
void DetachCallback(const char *hostname,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
|
|
|
uint16_t flags,
|
|
|
|
uint16_t af,
|
|
|
|
const char *netInterface,
|
|
|
|
nsResolveHostCallback *callback,
|
|
|
|
nsresult status);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2012-01-21 03:14:46 +04:00
|
|
|
/**
|
2017-02-14 07:25:35 +03:00
|
|
|
* Cancels an async request associated with the hostname, originAttributes, flags,
|
2012-01-21 03:14:46 +04:00
|
|
|
* address family and listener. Cancels first callback found which matches
|
|
|
|
* these criteria. These parameters should correspond to the parameters
|
|
|
|
* passed to ResolveHost. If this is the last callback associated with the
|
|
|
|
* host record, it is removed from any request queues it might be on.
|
|
|
|
*/
|
2017-02-14 07:25:35 +03:00
|
|
|
void CancelAsyncRequest(const char *host,
|
|
|
|
const mozilla::OriginAttributes &aOriginAttributes,
|
|
|
|
uint16_t flags,
|
|
|
|
uint16_t af,
|
|
|
|
const char *netInterface,
|
|
|
|
nsIDNSListener *aListener,
|
|
|
|
nsresult status);
|
2004-09-01 23:55:58 +04:00
|
|
|
/**
|
|
|
|
* values for the flags parameter passed to ResolveHost and DetachCallback
|
|
|
|
* that may be bitwise OR'd together.
|
|
|
|
*
|
|
|
|
* NOTE: in this implementation, these flags correspond exactly in value
|
|
|
|
* to the flags defined on nsIDNSService.
|
|
|
|
*/
|
|
|
|
enum {
|
2015-09-14 16:46:47 +03:00
|
|
|
RES_BYPASS_CACHE = nsIDNSService::RESOLVE_BYPASS_CACHE,
|
|
|
|
RES_CANON_NAME = nsIDNSService::RESOLVE_CANONICAL_NAME,
|
|
|
|
RES_PRIORITY_MEDIUM = nsIDNSService::RESOLVE_PRIORITY_MEDIUM,
|
|
|
|
RES_PRIORITY_LOW = nsIDNSService::RESOLVE_PRIORITY_LOW,
|
|
|
|
RES_SPECULATE = nsIDNSService::RESOLVE_SPECULATE,
|
|
|
|
//RES_DISABLE_IPV6 = nsIDNSService::RESOLVE_DISABLE_IPV6, // Not used
|
|
|
|
RES_OFFLINE = nsIDNSService::RESOLVE_OFFLINE,
|
|
|
|
//RES_DISABLE_IPv4 = nsIDNSService::RESOLVE_DISABLE_IPV4, // Not Used
|
|
|
|
RES_ALLOW_NAME_COLLISION = nsIDNSService::RESOLVE_ALLOW_NAME_COLLISION
|
2004-09-01 23:55:58 +04:00
|
|
|
};
|
|
|
|
|
2013-11-25 03:24:12 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
/**
|
|
|
|
* Flush the DNS cache.
|
|
|
|
*/
|
|
|
|
void FlushCache();
|
|
|
|
|
2003-09-12 00:32:33 +04:00
|
|
|
private:
|
2014-09-21 02:10:18 +04:00
|
|
|
explicit nsHostResolver(uint32_t maxCacheEntries,
|
|
|
|
uint32_t defaultCacheEntryLifetime,
|
|
|
|
uint32_t defaultGracePeriod);
|
2003-09-12 00:32:33 +04:00
|
|
|
~nsHostResolver();
|
|
|
|
|
|
|
|
nsresult Init();
|
2014-08-21 18:53:11 +04:00
|
|
|
nsresult IssueLookup(nsHostRecord *);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetHostToLookup(nsHostRecord **m);
|
2014-09-25 07:14:00 +04:00
|
|
|
|
|
|
|
enum LookupStatus {
|
|
|
|
LOOKUP_OK,
|
|
|
|
LOOKUP_RESOLVEAGAIN,
|
|
|
|
};
|
|
|
|
|
|
|
|
LookupStatus OnLookupComplete(nsHostRecord *, nsresult, mozilla::net::AddrInfo *);
|
2008-11-08 02:00:26 +03:00
|
|
|
void DeQueue(PRCList &aQ, nsHostRecord **aResult);
|
|
|
|
void ClearPendingQueue(PRCList *aPendingQueue);
|
|
|
|
nsresult ConditionallyCreateThread(nsHostRecord *rec);
|
2013-08-16 22:49:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts a new lookup in the background for entries that are in the grace
|
|
|
|
* period with a failed connect or all cached entries are negative.
|
|
|
|
*/
|
|
|
|
nsresult ConditionallyRefreshRecord(nsHostRecord *rec, const char *host);
|
2014-09-24 20:56:13 +04:00
|
|
|
|
2008-11-08 02:00:26 +03:00
|
|
|
static void MoveQueue(nsHostRecord *aRec, PRCList &aDestQ);
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void ThreadFunc(void *);
|
2003-09-12 00:32:33 +04:00
|
|
|
|
2011-12-17 06:24:17 +04:00
|
|
|
enum {
|
|
|
|
METHOD_HIT = 1,
|
|
|
|
METHOD_RENEWAL = 2,
|
|
|
|
METHOD_NEGATIVE_HIT = 3,
|
|
|
|
METHOD_LITERAL = 4,
|
|
|
|
METHOD_OVERFLOW = 5,
|
|
|
|
METHOD_NETWORK_FIRST = 6,
|
|
|
|
METHOD_NETWORK_SHARED = 7
|
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mMaxCacheEntries;
|
2014-09-21 02:10:18 +04:00
|
|
|
uint32_t mDefaultCacheLifetime; // granularity seconds
|
|
|
|
uint32_t mDefaultGracePeriod; // granularity seconds
|
2013-11-25 03:24:12 +04:00
|
|
|
mutable Mutex mLock; // mutable so SizeOfIncludingThis can be const
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
CondVar mIdleThreadCV;
|
2015-05-20 02:46:17 +03:00
|
|
|
PLDHashTable mDB;
|
2008-11-08 02:00:26 +03:00
|
|
|
PRCList mHighQ;
|
|
|
|
PRCList mMediumQ;
|
|
|
|
PRCList mLowQ;
|
2003-09-12 00:32:33 +04:00
|
|
|
PRCList mEvictionQ;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mEvictionQSize;
|
2003-09-12 00:32:33 +04:00
|
|
|
PRTime mCreationTime;
|
2008-11-08 02:00:26 +03:00
|
|
|
PRIntervalTime mLongIdleTimeout;
|
|
|
|
PRIntervalTime mShortIdleTimeout;
|
2012-12-10 18:13:55 +04:00
|
|
|
|
2015-08-20 19:14:40 +03:00
|
|
|
mozilla::Atomic<bool> mShutdown;
|
|
|
|
mozilla::Atomic<uint32_t> mNumIdleThreads;
|
|
|
|
mozilla::Atomic<uint32_t> mThreadCount;
|
|
|
|
mozilla::Atomic<uint32_t> mActiveAnyThreadCount;
|
|
|
|
mozilla::Atomic<uint32_t> mPendingCount;
|
|
|
|
|
2014-09-21 02:10:18 +04:00
|
|
|
// Set the expiration time stamps appropriately.
|
|
|
|
void PrepareRecordExpiration(nsHostRecord* rec) const;
|
|
|
|
|
2012-12-10 18:13:55 +04:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* Called by the networking dashboard via the DnsService2
|
|
|
|
*/
|
|
|
|
void GetDNSCacheEntries(nsTArray<mozilla::net::DNSCacheEntries> *);
|
2003-09-12 00:32:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHostResolver_h__
|