dial

package
v0.0.0-...-9019093 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package dial contains an implementation of TCP/HTTP dialing.

Index

Constants

View Source
const (
	DefaultConnectTimeout   = time.Second * 30
	DefaultEstablishTimeout = time.Second * 15
)

Variables

This section is empty.

Functions

func HTTP

func HTTP[T any](ctx context.Context, opts Opts, url, protocol string, makeClient func(parentCtx context.Context, mc types.MetaConn, brw *bufio.ReadWriter, opts Opts) (*T, error)) (*T, error)

func HTTPHandler

func HTTPHandler(s ProtocolServer, proto string) http.Handler

func TCP

func TCP(ctx context.Context, opts Opts) (net.Conn, error)

func TLS

func TLS(conn net.Conn, opts Opts) *tls.Conn

func WithTLS

func WithTLS(ctx context.Context, opts Opts) (net.Conn, error)

WithTLS does a "full" dial, including TLS wrapping and CN checking

Types

type Opts

type Opts struct {
	Domain string

	// If non-empty, overrides DNS lookup from Domain
	Addrs []netip.Addr

	// If not set, will use 80 for not TLS, and 443 for TLS
	Port uint16

	// Establish the connection with TLS, turns HTTP into HTTPS.
	TLS bool

	// If non-empty, sends this string in SNI, and checks the certificate common name against it.
	//
	// Only works if TLS is true.
	ExpectCertCN string

	// If nil, uses default of 30 seconds
	ConnectTimeout time.Duration

	// If nil, uses default of 15 seconds
	EstablishTimeout time.Duration
}

func (*Opts) SetDefaults

func (opts *Opts) SetDefaults()

type ProtocolServer

type ProtocolServer interface {
	Logger() *slog.Logger
	Accept(ctx context.Context, mc types.MetaConn, brw *bufio.ReadWriter, remoteAddrPort netip.AddrPort) error
}

Jump to

Keyboard shortcuts

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