dns

package
v0.22.8-patch-4-ledger... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: AGPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultTimeToLive is the default duration a dns result is cached.
	DefaultTimeToLive = 5 * time.Minute
)

DefaultTimeToLive is the default duration a dns result is cached.

Variables

This section is empty.

Functions

func WithBasicResolver

func WithBasicResolver(basic madns.BasicResolver) optFunc

WithBasicResolver is an option function for setting the basic resolver of this Resolver.

func WithTTL

func WithTTL(ttl time.Duration) optFunc

WithTTL is an option function for setting the time to live for cache entries.

Types

type Resolver

type Resolver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Resolver is a cache-based dns resolver for libp2p. - DNS cache implementation notes:

  • Generic / possibly expected functionality NOT implemented:
  • Caches domains for TTL seconds as given by upstream DNS resolver, e.g. [1].
  • Possibly pre-expire cached domains so no connection time resolve delay.
  • Actual / pragmatic functionality implemented below:
  • Caches domains for global (not individual domain record TTL) TTL seconds.
  • Cached IP is returned even if cached entry expired; so no connection time resolve delay.
  • Detecting expired cached domain triggers async DNS lookup to refresh cached entry.

[1] https://en.wikipedia.org/wiki/Name_server#Caching_name_server

func NewResolver

func NewResolver(collector module.ResolverMetrics, opts ...optFunc) *Resolver

NewResolver is the factory function for creating an instance of this resolver.

func (*Resolver) Done added in v0.22.4

func (r *Resolver) Done() <-chan struct{}

Done terminates the resolver and returns a channel that is closed when the termination is done

func (*Resolver) LookupIPAddr

func (r *Resolver) LookupIPAddr(ctx context.Context, domain string) ([]net.IPAddr, error)

LookupIPAddr implements BasicResolver interface for libp2p for looking up ip addresses through resolver.

func (*Resolver) LookupTXT

func (r *Resolver) LookupTXT(ctx context.Context, txt string) ([]string, error)

LookupTXT implements BasicResolver interface for libp2p. If txt exists on cache it is resolved through the cache. An expired txt on cache is still addressed through the cache, however, a request is fired up asynchronously through the underlying basic resolver to resolve it from the network.

func (*Resolver) Ready added in v0.22.4

func (r *Resolver) Ready() <-chan struct{}

Ready initializes the resolver and returns a channel that is closed when the initialization is done.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL