bootstrap

package
v0.71.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 10 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 ConsequentResolver added in v0.62.0

type ConsequentResolver []Resolver

ConsequentResolver is a slice of resolvers that are queried in order until the first successful non-empty response, as opposed to just successful response requirement in ParallelResolver.

func (ConsequentResolver) LookupNetIP added in v0.62.0

func (resolvers ConsequentResolver) LookupNetIP(
	ctx context.Context,
	network Network,
	host string,
) (addrs []netip.Addr, err error)

LookupNetIP implements the Resolver interface for ConsequentResolver.

type DialHandler

type DialHandler func(ctx context.Context, network 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. network must be one of NetworkTCP or NetworkUDP.

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.

func ResolveDialContext

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

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

type Network added in v0.62.0

type Network = string

Network is a network type for use in Resolver's methods.

const (
	// NetworkIP is a network type for both address families.
	NetworkIP Network = "ip"

	// NetworkIP4 is a network type for IPv4 address family.
	NetworkIP4 Network = "ip4"

	// NetworkIP6 is a network type for IPv6 address family.
	NetworkIP6 Network = "ip6"

	// NetworkTCP is a network type for TCP connections.
	NetworkTCP Network = "tcp"

	// NetworkUDP is a network type for UDP connections.
	NetworkUDP Network = "udp"
)

type ParallelResolver added in v0.58.0

type ParallelResolver []Resolver

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

func (ParallelResolver) LookupNetIP added in v0.58.0

func (r ParallelResolver) LookupNetIP(
	ctx context.Context,
	network Network,
	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 should
	// be one of [NetworkIP], [NetworkIP4] or [NetworkIP6].  The response may be
	// empty even if err is nil.  All the addrs must be valid.
	LookupNetIP(ctx context.Context, network Network, host string) (addrs []netip.Addr, err error)
}

Resolver resolves the hostnames to IP addresses. Note, that net.Resolver from standard library also implements this interface.

type StaticResolver added in v0.62.0

type StaticResolver []netip.Addr

StaticResolver is a resolver which always responds with an underlying slice of IP addresses regardless of host and network.

func (StaticResolver) LookupNetIP added in v0.62.0

func (r StaticResolver) LookupNetIP(
	_ context.Context,
	_ Network,
	_ string,
) (addrs []netip.Addr, err error)

LookupNetIP implements the Resolver interface for StaticResolver.

Jump to

Keyboard shortcuts

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