resolver

package
v0.0.0-...-3cdde17 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

type EvictCallback = func(key any, value any)

EvictCallback is used to get a callback when a cache entry is evicted

type LruCache

type LruCache struct {
	// contains filtered or unexported fields
}

LruCache is a thread-safe, in-memory lru-cache that evicts the least recently used entries from memory when (if set) the entries are older than maxAge (in seconds). Use the New constructor to create one.

func (*LruCache) CloneTo

func (c *LruCache) CloneTo(n *LruCache)

CloneTo clone and overwrite elements to another LruCache

func (*LruCache) Delete

func (c *LruCache) Delete(key any)

Delete removes the value associated with a key.

func (*LruCache) Exist

func (c *LruCache) Exist(key any) bool

Exist returns if key exist in cache but not put item to the head of linked list

func (*LruCache) Get

func (c *LruCache) Get(key any) (any, bool)

Get returns the any representation of a cached response and a bool set to true if the key was found.

func (*LruCache) GetWithExpire

func (c *LruCache) GetWithExpire(key any) (any, time.Time, bool)

GetWithExpire returns the any representation of a cached response, a time.Time Give expected expires, and a bool set to true if the key was found. This method will NOT check the maxAge of element and will NOT update the expires.

func (*LruCache) Set

func (c *LruCache) Set(key any, value any)

Set stores the any representation of a response for a given key.

func (*LruCache) SetWithExpire

func (c *LruCache) SetWithExpire(key any, value any, expires time.Time)

SetWithExpire stores the any representation of a response for a given key and given expires. The expires time will round to second.

type Option

type Option func(*LruCache)

Option is part of Functional Options Pattern

func WithAge

func WithAge(maxAge int64) Option

WithAge defined element max age (second)

func WithEvict

func WithEvict(cb EvictCallback) Option

WithEvict set the evict callback

func WithSize

func WithSize(maxSize int) Option

WithSize defined max length of LruCache

func WithStale

func WithStale(stale bool) Option

WithStale decide whether Stale return is enabled. If this feature is enabled, element will not get Evicted according to `WithAge`.

func WithUpdateAgeOnGet

func WithUpdateAgeOnGet() Option

WithUpdateAgeOnGet update expires when Get element

type Record

type Record struct {
	Domain string
	RealIP netip.Addr
	FakeIP netip.Addr
	Query  *dns.Msg
	Reply  *dns.Msg
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}
var DefaultResolver *Resolver

func NewDnsResolver

func NewDnsResolver(nameservers []string) *Resolver

func (*Resolver) EnableEnhancerMode

func (r *Resolver) EnableEnhancerMode(tunCIDR string)

func (Resolver) Find

func (r Resolver) Find(host string) *Record

func (Resolver) FindByIP

func (r Resolver) FindByIP(ip netip.Addr) *Record

func (*Resolver) IsEnhancerMode

func (r *Resolver) IsEnhancerMode() bool

func (*Resolver) LookupIP

func (r *Resolver) LookupIP(ctx context.Context, host string) ([]netip.Addr, error)

func (*Resolver) Query

func (r *Resolver) Query(req *dns.Msg) (reply *dns.Msg, err error)

func (*Resolver) ResolveHost

func (r *Resolver) ResolveHost(host string) netip.Addr

func (*Resolver) ResolveQuery

func (r *Resolver) ResolveQuery(req *dns.Msg) netip.Addr

Jump to

Keyboard shortcuts

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