Documentation ¶
Index ¶
- type DialContextFunc
- type DnsCacheItem
- type DnsCacheManager
- func (m *DnsCacheManager) CacheStorage() IDnsCacheStorage
- func (m *DnsCacheManager) DisposeCache()
- func (m *DnsCacheManager) InitDNSCaching(ttl, checkInterval time.Duration)
- func (m *DnsCacheManager) IsCacheEnabled() bool
- func (m *DnsCacheManager) SetCacheStorage(cache IDnsCacheStorage)
- func (m *DnsCacheManager) WrapDialer(dialer *net.Dialer) DialContextFunc
- type DnsCacheStorage
- func (dc *DnsCacheStorage) Clear()
- func (dc *DnsCacheStorage) Delete(key string)
- func (dc *DnsCacheStorage) FetchItem(hostName string) ([]string, error)
- func (dc *DnsCacheStorage) Get(key string) (DnsCacheItem, bool)
- func (dc *DnsCacheStorage) Items(includeExpired bool) map[string]DnsCacheItem
- func (dc *DnsCacheStorage) Set(key string, addrs []string)
- type IDnsCacheManager
- type IDnsCacheStorage
- type MockStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialContextFunc ¶
type DnsCacheItem ¶
type DnsCacheItem struct {
Addrs []string
}
DnsCacheItem represents single record in cache
type DnsCacheManager ¶
type DnsCacheManager struct {
// contains filtered or unexported fields
}
DnsCacheManager is responsible for in-memory dns query records cache. It allows to init dns caching and to hook into net/http dns resolution chain in order to cache query response ip records.
func NewDnsCacheManager ¶
func NewDnsCacheManager(multipleIPsHandleStrategy config.IPsHandleStrategy) *DnsCacheManager
NewDnsCacheManager returns new empty/non-initialized DnsCacheManager
func (*DnsCacheManager) CacheStorage ¶
func (m *DnsCacheManager) CacheStorage() IDnsCacheStorage
func (*DnsCacheManager) DisposeCache ¶
func (m *DnsCacheManager) DisposeCache()
DisposeCache clear all entries from cache and disposes/disables caching of dns queries
func (*DnsCacheManager) InitDNSCaching ¶
func (m *DnsCacheManager) InitDNSCaching(ttl, checkInterval time.Duration)
InitDNSCaching initializes manager's cache storage if it wasn't initialized before with provided ttl, checkinterval values Initialized cache storage enables caching of previously hoooked net.Dialer DialContext calls
Otherwise leave storage as is.
func (*DnsCacheManager) IsCacheEnabled ¶
func (m *DnsCacheManager) IsCacheEnabled() bool
func (*DnsCacheManager) SetCacheStorage ¶
func (m *DnsCacheManager) SetCacheStorage(cache IDnsCacheStorage)
func (*DnsCacheManager) WrapDialer ¶
func (m *DnsCacheManager) WrapDialer(dialer *net.Dialer) DialContextFunc
WrapDialer returns wrapped version of net.Dialer#DialContext func with hooked up caching of dns queries.
Actual dns server call occures in net.Resolver#LookupIPAddr method, linked to net.Dialer instance by net.Dialer#Resolver field
type DnsCacheStorage ¶
type DnsCacheStorage struct {
// contains filtered or unexported fields
}
DnsCacheStorage is an in-memory cache of auto-purged dns query ip responses
func NewDnsCacheStorage ¶
func NewDnsCacheStorage(expiration, checkInterval time.Duration) *DnsCacheStorage
func (*DnsCacheStorage) Clear ¶
func (dc *DnsCacheStorage) Clear()
Clear deletes all records from cache
func (*DnsCacheStorage) Delete ¶
func (dc *DnsCacheStorage) Delete(key string)
func (*DnsCacheStorage) FetchItem ¶
func (dc *DnsCacheStorage) FetchItem(hostName string) ([]string, error)
FetchItem returns list of ips from cache or resolves them and add to cache
func (*DnsCacheStorage) Get ¶
func (dc *DnsCacheStorage) Get(key string) (DnsCacheItem, bool)
Get returns non expired item from cache
func (*DnsCacheStorage) Items ¶
func (dc *DnsCacheStorage) Items(includeExpired bool) map[string]DnsCacheItem
Items returns map of non expired dns cache items
func (*DnsCacheStorage) Set ¶
func (dc *DnsCacheStorage) Set(key string, addrs []string)
type IDnsCacheManager ¶
type IDnsCacheManager interface { InitDNSCaching(ttl, checkInterval time.Duration) WrapDialer(dialer *net.Dialer) DialContextFunc SetCacheStorage(cache IDnsCacheStorage) CacheStorage() IDnsCacheStorage IsCacheEnabled() bool DisposeCache() }
IDnsCacheManager is an interface for abstracting interaction with dns cache. Implemented by DnsCacheManager
type IDnsCacheStorage ¶
type IDnsCacheStorage interface { FetchItem(key string) ([]string, error) Get(key string) (DnsCacheItem, bool) Set(key string, addrs []string) Delete(key string) Clear() }
IDnsCacheStorage is an interface for working with cached storage of dns record. Wrapped by IDnsCacheManager/DnsCacheManager. Implemented by DnsCacheStorage
type MockStorage ¶
type MockStorage struct { MockFetchItem func(key string) ([]string, error) MockGet func(key string) (DnsCacheItem, bool) MockSet func(key string, addrs []string) MockDelete func(key string) MockClear func() }
func (*MockStorage) Clear ¶
func (ms *MockStorage) Clear()
func (*MockStorage) Delete ¶
func (ms *MockStorage) Delete(key string)
func (*MockStorage) Get ¶
func (ms *MockStorage) Get(key string) (DnsCacheItem, bool)
func (*MockStorage) Set ¶
func (ms *MockStorage) Set(key string, addrs []string)