bootstrap

package
v0.0.0-...-9e8a4c4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package bootstrap provides types and functions to resolve upstream hostnames and to dial retrieved addresses.

Index

Constants

View Source
const ErrNoResolvers errors.Error = "no resolvers specified"

ErrNoResolvers is returned when zero resolvers specified.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialHandler

type DialHandler func(ctx context.Context, network, addr string) (conn net.Conn, err error)

DialHandler is a dial function for creating unencrypted network connections to the upstream server. It establishes the connection to the server specified at initialization and ignores the addr.

func NewDialContext

func NewDialContext(timeout time.Duration, addrs ...string) (h DialHandler)

NewDialContext returns a DialHandler that dials addrs and returns the first successful connection. At least a single addr should be specified.

TODO(e.burkov): Consider using Resolver instead of [upstream.Options.Bootstrap] and [upstream.Options.ServerIPAddrs].

func ResolveDialContext

func ResolveDialContext(
	u *url.URL,
	timeout time.Duration,
	resolver Resolver,
	preferIPv6 bool,
) (h DialHandler, err error)

ResolveDialContext returns a DialHandler that uses addresses resolved from u using resolver. u must not be nil.

type HostsResolver

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

HostsResolver is a Resolver that uses [netutil.Hosts] as a source of IP.

func NewDefaultHostsResolver

func NewDefaultHostsResolver(rootFSys fs.FS) (hr *HostsResolver, err error)

NewDefaultHostsResolver returns a resolver based on system hosts files provided by the hostsfile.DefaultHostsPaths and read from rootFSys.

TODO(e.burkov): Use.

func NewHostsResolver

func NewHostsResolver(hosts *netutil.Hosts) (hr *HostsResolver)

NewHostsResolver is the resolver based on system hosts files.

func (*HostsResolver) LookupNetIP

func (hr *HostsResolver) LookupNetIP(
	context context.Context,
	network string,
	host string,
) (addrs []netip.Addr, err error)

LookupNetIP implements the Resolver interface for *hostsResolver.

type ParallelResolver

type ParallelResolver []Resolver

ParallelResolver is a slice of resolvers that are queried concurrently. The first successful response is returned.

func (ParallelResolver) LookupNetIP

func (r ParallelResolver) LookupNetIP(
	ctx context.Context,
	network string,
	host string,
) (addrs []netip.Addr, err error)

LookupNetIP implements the Resolver interface for ParallelResolver.

type Resolver

type Resolver interface {
	// LookupNetIP looks up the IP addresses for the given host.  network must
	// be one of "ip", "ip4" or "ip6".  The response may be empty even if err is
	// nil.
	LookupNetIP(ctx context.Context, network, host string) (addrs []netip.Addr, err error)
}

Resolver resolves the hostnames to IP addresses.

Jump to

Keyboard shortcuts

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