netutil

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDNSCache = &SimpleDNSCache{}

Functions

func LookupReachable

func LookupReachable(addr string) (string, error)

LookupReachable tries to resolve addr via connecting to it. This method has much more overhead, but get guaranteed reachable resolved addr. Example: host is resolved to IPv4 and IPv6, but IPv4 is not working on machine. LookupAccessible will return IPv6 in that case.

func WarmDNSCache

func WarmDNSCache(c DNSCache, addr string) error

WarmDNSCache tries connect to addr, and adds conn remote ip + addr port to cache.

Types

type DNSCache

type DNSCache interface {
	Get(addr string) (string, bool)
	Add(addr, resolved string)
}

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, net, addr string) (net.Conn, error)
}

type DialerFunc

type DialerFunc func(ctx context.Context, network, address string) (net.Conn, error)

func NewDNSCachingDialer

func NewDNSCachingDialer(dialer Dialer, cache DNSCache) DialerFunc

NewDNSCachingDialer returns dialer with primitive DNS caching logic that remembers remote address on first try, and use it in future.

func (DialerFunc) DialContext

func (f DialerFunc) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type SimpleDNSCache

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

func (*SimpleDNSCache) Add

func (c *SimpleDNSCache) Add(addr, resolved string)

func (*SimpleDNSCache) Get

func (c *SimpleDNSCache) Get(addr string) (resolved string, ok bool)

Directories

Path Synopsis
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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