ech

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ech provides a DoH-based fetcher and cache for ECHConfigList (Encrypted Client Hello configuration) bytes.

Index

Constants

View Source
const DisableTTL = 5 * time.Minute

DisableTTL is how long ECH stays disabled for a name after a rejection without retry configs when fallback is enabled.

Variables

View Source
var ErrDisabled = errors.New("ech: disabled")

ErrDisabled is returned when the requested name has been disabled.

View Source
var ErrNoECHConfig = errors.New("ech: no ECH config")

ErrNoECHConfig is returned when a DoH lookup succeeds but contains no ECH config for the requested name.

Functions

This section is empty.

Types

type Client

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

Client fetches and caches ECHConfigList bytes from a DoH endpoint.

func NewClient

func NewClient(doh string, opts ...Option) (*Client, error)

NewClient creates a Client querying the given DoH URL.

func (*Client) ConfigList

func (c *Client) ConfigList(ctx context.Context, name string) ([]byte, error)

ConfigList returns the cached (or freshly fetched) ECHConfigList for name.

func (*Client) Disable

func (c *Client) Disable(name string, d time.Duration)

Disable marks name as disabled until now+d.

func (*Client) Refresh

func (c *Client) Refresh(name string)

Refresh drops the cached entry for name so the next ConfigList performs a fresh lookup. A disabled name stays disabled.

func (*Client) SetConfigList

func (c *Client) SetConfigList(name string, list []byte)

SetConfigList stores list in the cache, overriding the TTL.

type Config

type Config struct {
	Enabled     bool
	DoH         string
	Timeout     time.Duration
	TTL         time.Duration
	Fallback    bool
	DoHInsecure bool
	// contains filtered or unexported fields
}

Config holds the ECH settings of a dialer. It is parsed from the ech* metadata keys and owns the DoH client used to fetch ECHConfigList bytes.

func FromMetadata

func FromMetadata(md mdata.Metadata) Config

FromMetadata parses the ECH metadata keys.

Supported keys: ech, ech.doh, ech.timeout, ech.ttl, ech.fallback and ech.dohInsecure.

func (*Config) Active

func (c *Config) Active() bool

Active reports whether ECH is enabled and the DoH client is ready.

func (*Config) Apply

func (c *Config) Apply(ctx context.Context, base *tls.Config, serverName string) (*tls.Config, error)

Apply returns a clone of base with the ECHConfigList for serverName injected. When the lookup fails and Fallback is enabled it returns the plain clone so the caller proceeds with a regular handshake. When ECH is disabled base is returned unchanged.

func (*Config) Init

func (c *Config) Init(log logger.Logger, base *tls.Config) error

Init validates the configuration and creates the DoH client. base is the TLS config the dialer will handshake with; it is only inspected, never modified. Init is a no-op when ECH is disabled.

func (*Config) OnDialError

func (c *Config) OnDialError(ctx context.Context, err error, serverName string) error

OnDialError is the counterpart of OnRejection for dialers that complete the TLS handshake inside Dial. Such transports usually do not preserve the *tls.ECHRejectionError, so any dial failure with ECH active invalidates the cached config list and asks for a single retry with a fresh lookup.

func (*Config) OnRejection

func (c *Config) OnRejection(err error, serverName string) error

OnRejection inspects err for a TLS ECH rejection. It returns a RetryableError when the handshake should be retried: either the server supplied new retry configs, or fallback is enabled and ECH has been disabled for serverName. It returns nil when err is not an ECH rejection, in which case the caller should propagate err unchanged.

type Option

type Option func(*Options)

Option allows setting Client options.

func LoggerOption

func LoggerOption(l logger.Logger) Option

LoggerOption sets the logger.

func TLSConfigOption

func TLSConfigOption(cfg *tls.Config) Option

TLSConfigOption sets the TLS config used for DoH.

func TTLOption

func TTLOption(ttl time.Duration) Option

TTLOption sets the cache TTL override.

func TimeoutOption

func TimeoutOption(timeout time.Duration) Option

TimeoutOption sets the DoH request timeout.

type Options

type Options struct {
	TTL       time.Duration
	Timeout   time.Duration
	Logger    logger.Logger
	TLSConfig *tls.Config
}

Options holds configuration for a Client.

type RetryableError

type RetryableError struct {
	Err error
}

RetryableError wraps an error to signal that the enclosing chain hop may retry the connection once.

func (RetryableError) Error

func (e RetryableError) Error() string

func (RetryableError) RetryableHandshake

func (e RetryableError) RetryableHandshake() bool

RetryableHandshake implements the interface used by x/chain to retry a failed connection once on the same node.

func (RetryableError) Unwrap

func (e RetryableError) Unwrap() error

Directories

Path Synopsis
Package echtest provides helpers for exercising ECH support in tests.
Package echtest provides helpers for exercising ECH support in tests.

Jump to

Keyboard shortcuts

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