hsdns-cache-1.0.4: Caching asynchronous DNS resolver.

Safe HaskellNone

ADNS.Cache

Contents

Description

Caching asynchronous DNS resolver built on top of GNU ADNS http://www.chiark.greenend.org.uk/~ian/adns/.

  • Resolves several IP addresses for one host (if available) in round-robin fashion.
  • Throttles number of parallel requests (so DNS resolving continues to work even under heavy load).
  • Errors are cached too (for one minute).
  • Handles CNAMEs (hsdns returns error for them).

You should link your program with the threaded runtime-system when using this module. In GHC, this is accomplished by specifying -threaded on the command-line.

This cache is tested in a long running web-crawler (used in https://bazqux.com) so it should be safe to use it in real world applications.

Synopsis

Cache

data DnsCache Source

Asynchronous DNS cache.

withDnsCache :: (DnsCache -> IO a) -> IO aSource

Create cache and run action passed.

withDnsCacheSettings :: DnsCacheSettings -> (DnsCache -> IO a) -> IO aSource

Create cache with specified settings and run action passed.

stopDnsCache :: DnsCache -> IO ()Source

Wait till all running resolvers are finished and block further resolvers.

Settings

data DnsCacheSettings Source

DNS cache settings.

Constructors

DnsCacheSettings 

Fields

dcsMaxParallelRequests :: Int

Throttling of parallel requests. Default: 30

dcsRequestDelay :: Maybe Int

Experimental! Delay in microseconds between subsequent requests to smooth load. Delay only inserted between real requests to DNS server. Cached results are returned immediately. Default: Nothing

Lookup

resolveA :: DnsCache -> HostName -> IO (Either String HostAddress)Source

Resolve A DNS record.

resolveCachedA :: DnsCache -> HostName -> IO (Maybe (Either String HostAddress))Source

Resolve cached A DNS record. Returns Nothing if host name is not yet cached.

Utils

showHostAddress :: HostAddress -> StringSource

Show HostAddress in standard 123.45.67.89 format.

Unlike inet_ntoa this function is pure and thread-safe.